Forum : ST7/STM8
Original Post
| Post Information | Post |
|---|---|
|
January 22, 2010 - 12:15pm
|
Hi, Nicola |
Forum : ST7/STM8
| Post Information | Post |
|---|---|
|
January 22, 2010 - 12:15pm
|
Hi, Nicola |
Hi Nicola,
What do you mean by "the modules don't work"?
Just try this:
#include float f; void main(void) { f = tan(2.0); while(1); }Compile, run, it just works!
I hope this helps,
Bruno
Hi Bruno,
thanks for your reply.
Your code compiles and works but mine do not run properly. I mean that it compiles and runs but it doesn't write on UART.
If I remove the float variable it works.
Can I send you a copy of my code?
Thanks
Nicola
Hi Nicola,
Sure you can send the faulty project (with application files and sources) in a zip to for investigation.
Concerning STM8S-Discovery printf/putchar issues:
The STM8S105 has a different UART than the other STM8S. It uses UART2 (address 0x5240), not UART1 (address 0x5230). The putchar offered by default in RKit-STM8 is based on UART1, so the putchar/puts/printf functions do not work correctly.
If this is the problem you are encountering, just add the following assembly file in your project. It will define a STM8S105-specific UART, hence putchar/printf will work fine with your STM8S-Discovery.
;============================================================================= ; Purpose: putchar function (for STM8S105 devices). ;----------------------------------------------------------------------------- ; Input: A character to print. ; Output: A the character written. ; Read only: A, X, Y, BH, BL, CH, CL ; Modified: - ;----------------------------------------------------------------------------- ; Notes: ; - In projects that do not use the (un)getchar functionality, some extra code ; can be removed from the present file. Just set the NO_UNGETCHAR macro to 1 ; and unnecessary conditional assembly blocks will be removed. ; - If you do not want the '\n' (Line Feed) character converted to CR/LF, set ; the NO_CRLF_CONV macro to 1 and unnecessary instructions will be removed. ; - If your project uses the large model, using the RCST7 directive STM8(LARGE), ; functions will be called using CALLF, and will return using RETF. ; For the following code to work properly, you must set the LARGE macro to 1 ; so that the proper CALL/RET scheme will be used. ;----------------------------------------------------------------------------- ; (c) Copyright Raisonance S.A.S. 1989-2009, All rights reserved. ;============================================================================= $MODESTM8 ;$SET(LARGE = 1) ; Uncomment if you are in LARGE mode ;$SET(NO_UNGETCHAR = 1) ; Uncomment if you do not use the ungetchar function ;$SET(NO_CRLF_CONV = 1) ; Uncomment if you do not want LF to CR/LF conversion $IF(LARGE==1) BIBCALL MACRO address CALLF address ENDM BIBRET MACRO RETF ENDM $ELSE BIBCALL MACRO address CALL address ENDM BIBRET MACRO RET ENDM $ENDIF ; Exports public symbols PUBLIC putchar PUBLIC ?putchar ; These publics are required for getchar PUBLIC USART_SR PUBLIC USART_DR ; Symbols for SCI registers depend on the target architecture USART_SR DATA 05240h ; USART status register USART_DR DATA 05241h ; USART data register USART_BRR1 DATA 05242h ; USART baud rate register USART_BRR2 DATA 05243h ; USART DIV mantissa[11:8] SCIDIV fraction USART_CR1 DATA 05244h ; USART control register 1 USART_CR2 DATA 05245h ; USART control register 2 USART_CR3 DATA 05246h ; USART control register 3 USART_CR4 DATA 05247h ; USART control register 4 USART_CR6 DATA 05249h ; USART control register 6 USART_GT DATA 0524Ah ; USART guard time register USART_PSCR DATA 0524Bh ; USART prescaler register ; Baud rate divisor settings (For 9600 bps) ; When using the 16MHz internal R/C clock, and HSIDIV divides by 8 (default) BDRATDIV1 EQU 00Dh ; Baud rate divisor (depends on the CPU frequency) BDRATDIV2 EQU 000h ; Baud rate divisor 2 (depends on the CPU frequency) ; Use the following settings when using w/ a 16MHz R/C clock undivided ; BDRATDIV1 EQU 068h ; Baud rate divisor (depends on the CPU frequency) ; BDRATDIV2 EQU 003h ; Baud rate divisor 2 (depends on the CPU frequency) ; USART_SR bit definitions TDRE EQU 7 ; Transmit data register empty TC EQU 6 ; Transmission complete RDRF EQU 5 ; Received data ready flag IDLE EQU 4 ; Idle line detect OERR EQU 3 ; Overrun error NF EQU 2 ; Noise flag FE EQU 1 ; Framing error PE EQU 0 ; Parity error ; USART Control Register 1 bit definitions R8 EQU 7 ; Receive data bit 8 T8 EQU 6 ; Transmit data bit 8 SCID EQU 5 ; Disabled for low power consumption M EQU 4 ; Word length WAKE EQU 3 ; Wake-Up method PCE EQU 2 ; Parity control enable PS EQU 1 ; Parity selection PIE EQU 0 ; Parity interrupt enable ; USART Control Register 2 bit definitions TIE EQU 7 ; Transmitter interrupt enable. TCIE EQU 6 ; Transmission complete interrupt enable RIE EQU 5 ; Receiver interrupt enable. ILIE EQU 4 ; Idle line interrupt enable. TE EQU 3 ; Transmitter enable. RE EQU 2 ; Receiver enable. RWU EQU 1 ; Receiver wake-up. SBK EQU 0 ; Send break. ; Character Codes LF EQU 0Ah ; Line Feed CR EQU 0Dh ; Carriage Return $IF(NO_UNGETCHAR <> 1) ; This can be skipped if getchar/ungetchar are not necessary ;--------------------------------------------------------------------------- ; Flag for getchar/ungetchar SCI buffer full bit ;--------------------------------------------------------------------------- PUBLIC FULLB_SCI RSG_BTM1_GETFLAG SEGMENT BIT RSEG RSG_BTM1_GETFLAG FULLB_SCI: DBIT 1 ; Read bit indicates whether the buffer has been read $ENDIF ;--------------------------------------------------------------------------- ; Actual putchar function. ; Note that the SCI initialization is performed by this function upon its ; first call, hence it is not necessary to initialize the SCI elsewhere. ; For this reason, it is necessary to call putchar at least once before ; calling the getchar function, otherwise the SCI will not be initialized. ;--------------------------------------------------------------------------- CSTDLIB SEGMENT CODE INSECTION0 RSEG CSTDLIB ?putchar: putchar: ;----------------------------------------------------------------------------- ; Initialize the SCI if not yet done ;----------------------------------------------------------------------------- BTJT USART_CR2, #TE, _convert ; Jump to _convert if USART already initialized ; Load Default value into control registers CLR USART_CR1 CLR USART_CR3 ; Set baudrate to 9600 bauds @ 16 MHz $IF(BDRATDIV2 <> 0) MOV USART_BRR2, #BDRATDIV2 $ELSE CLR USART_BRR2 $ENDIF MOV USART_BRR1, #BDRATDIV1 ; Enable Transmission and Reception BSET USART_CR2, #TE BSET USART_CR2, #RE $IF(NO_UNGETCHAR <> 1) ; This can be skipped if getchar/ungetchar are not necessary ; Specifies that no char is in the getchar/ungetchar buffer yet BRES FULLB_SCI $ENDIF ;----------------------------------------------------------------------------- ; Convert LF to CR/LF (to keep Hyperterminal happy) ;----------------------------------------------------------------------------- _convert: $IF(NO_CRLF_CONV <> 1) ; This can be skipped if CR/LF conversion is not necessary CP A, #LF JRNE _emit ; Reentrant call to putchar PUSH A LD A, #CR BIBCALL _emit POP A $ENDIF _emit: BTJF USART_SR, #TC, $ ; Wait end of (previous) transmission LD USART_DR, A ; Send the character to the SCI ; BTJF USART_SR, #TC, $ ; Wait end of transmission BIBRET ENDNote: This will be corrected in the next RKit-STM8 version (it will automatically link this putchar version with STM8S105), but the release should not be before March. Using this file in your project is the best workaround in the meantime.
I hope this helps. Please come back to us if needed.
Bruno
Hi Nicola,
We received your project, but have not been able to use it.
Can you describe precisely the problem you are encountering?
If you use the assembler-written putchar, disable the clock settings in your project, does your printf work?
If it does, do you have a difference when enabling the float initialization routine?
I would be surprised if that made any difference, but you never know.
Keep us informed about what happens to your project.
Regards,
Bruno