Forum : ST7/STM8
Original Post
| Post Information | Post |
|---|---|
|
December 15, 2009 - 11:53am
|
Hi, Is it STM8S-Discovery (http://st.com/stm8s-discovery) _officially_ supported by RCSTM8 compiler? I have ported, using above-mentioned compiler, a working little test program from STM8128-EVAL/A (STM8S208MB) to STM8S-Discovery (STM8S105C6) where unfortunately this stop to work. In particularly printf() function don't work anymore. In first occurrence of this function micro "freeze" completely. Under Cosmic compiler it works out-of-box but I just bought RCSTM8 and obviously I'm particularly interested to working with second one :-) Could anyone give me some suggestions? Thanks in advance! Ciao, |
All the compiler knows & cares about is the chip - the details of the external hardware connected to the chip are irrelevant to the compiler.
In other words, if the compiler supports your chip, then it makes no difference to the compiler whether that chip is on a Discover board or some other board.
It is up to you, the programmer, to ensure that your software is correct for use on your particular hardware.
If printf is "freezing", I suggest that you check your UART code carefully.
Also check whether Raisonance's implementation of the printf library function - and any other low-level support fucntions - is correctly configured for the target...
Hi Alessio and Andy,
Actually there IS a problem with the STM8S105 putchar function: It currently uses the STM8 UART1, whereas the UART2 should be used instead (as it is the only available UART on STM8S105).
We only got some sample boards one week ago, and discovered the problem only then.
We ported the putchar to the STM8S103, but it will not be available until next release of RKit-STM8.
As a workaround, you can add an "stm8s105_putchar.asm file to your project with the following contents:
;============================================================================= ; 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 ENDThis will ensure that your putchar works fine, hence printf will be ok.
Let us know if this fixes your problem,
Bruno
Indeed - although that's to do with the chip - not the board on which it's mounted.
And it's not really a compiler problem - the compiler generates good code for the chip - it's a configuration problem in the support library.
Whenever one ports code from one chip to another, one should should expect to have to pay close attention to such details as these:
- are the correct ports/peripherals used?
- are they correctly configured?