cancel
Showing results for 
Search instead for 
Did you mean: 

USART_printf not working on STM323221G_eval via GNU_ARM_GCC

vneff
Associate II
Posted on November 27, 2013 at 20:39

Hello,

I haven't been able to get the example: STM32F2xx_StdPeriph_Lib_V1.1.0\Project\STM32F2xx_StdPeriph_Examples\USART\USART_Printf to work. It seems as if the the wrong put_char routine is being overridden. I have verified that USART3 is working correctly. By default, __io_putchar is being overriden (__GNUC__ is defined) and I have verified that I can print a character by calling __io_putchar. If I undefine __GNUC__, then fputc is overridden and I have verified that I can call fputc successfully. Basically, when I call printf, it does not return and does not send anything to usart3. I could rewrite printf, but I don't think I should have to. I am out of ideas! My environment particulars: included c and asm files: STM32F2xx Standard Peripheral Library V1.1.2 - including all src\*.c files and STM32_EVAL\STM322xG_EVAL\stm322xg_eval.c, stm322xg_eval_fsmc_sram.c, stm322xg_eval_ioe.c, stm322xg_eval_lcd.c, and stm322xg_eval_sdio_sd.c CMSIS\CM3\DeviceSupport\system_stm32f2xx.c and startup_stm32f2xx.s and typical syscalls.c and stm32f2xx_it.c and what I believe is a type .ld file: stm32f217vg_flash.ld main.c is listed below. Toolchain: gcc-arm-none-eabi - GNU Tools for ARM Embedded Processors 4.7 - Q3 2013 Compiler flags: -fno-common -mcpu=cortex-m3 -march=armv7-m -mfix-cortex-m3-ldrd -mfpu=vfp -std=gnu99 -mthumb and IDE Code::Blocks 11 Any ideas will be appreciated!!!! Vance Main.c:

#include ''stm32f2xx.h''
#include ''stm322xg_eval.h''
#include <
stdio.h
>
USART_InitTypeDef USART_InitStructure;
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
USART_SendData(EVAL_COM1, (uint8_t) ch);
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
{}
return ch;
}
int main(void)
{
#if (1)
STM_EVAL_LEDInit( LED1 );
STM_EVAL_LEDInit( LED2 );
STM_EVAL_LEDInit( LED3 );
STM_EVAL_LEDInit( LED4 );
STM_EVAL_LEDOn(LED1);
#endif
USART_InitStructure.USART_BaudRate = 38400;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
STM_EVAL_COMInit(COM1, &USART_InitStructure);
STM_EVAL_LEDOn(LED2);
USART_SendData(EVAL_COM1, 0x49); // Send 'I'
#ifdef __GNUC__
__io_putchar( 0x4A);
#else
fputc( 0x4B, (FILE *)NULL);
#endif // __GNUC__
STM_EVAL_LEDOn(LED3);
printf(''\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r'');
STM_EVAL_LEDOn(LED4);
while (1)
{
}
}

#stm32-standard-peripheral-librar #stm32f2-eval-board
6 REPLIES 6
Posted on November 28, 2013 at 02:43

Guess I'd be looking at what libraries you are linking against, and looking at a disassembly listing or debugging to understand where printf()/putchar() is going. If it is calling the NEWLIB/SYSCALL implementation, generating SWI/BKPT or whatever.

May be there are some odd Code::Blocks or C++ things going on there. I've used Yagarto GNU/GCC (4.7.2) with my own syscalls.c and hosting code, and had USART and SWV output streams.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vneff
Associate II
Posted on December 10, 2013 at 19:05

Thanks for replying!

I've since installed the Yagarto toolchain with Gcc 4.7.2 (this is the fourth toolchain I've tried).  I've generated a make file so that Code::Blocks is no longer a possible issue.  I have the yagarto\bin directory as the first item in my PATH.

Still having the same issue.  It is still not displaying anything when the printf is called and does not return from that call.

I'm using gcc to compile the C & asm code and ld to link.

using the flags: -mthumb -fno-common -mcpu=cortex-m3 -march=armv7-m -mfix-cortex-m3-ldrd -mfpu=vfp -std=gnu99 -gdwarf-2

and for the linker, specified -nostartfiles as I'm using (as stated previously) the standard startup supplied with the ST32F2 library.

I'm linking to the libraries in lib\gcc\arm-none-eabi\4.7.2\thumb\v7m

Recall that this is for the STM323221G eval board with the 32F217 processor.

Everything compiles with no warnings or errors.

Unfortunately, I haven't been able to get GDB/openOCD debugging working yet (I think it has something to do with Windows 7/64 and STLink).

Does this all look OK?  It seems its got to be something simple.

Vance

Posted on December 11, 2013 at 00:19

You mean an

http://www.st.com/web/en/catalog/tools/PF251702

?

Try this

https://drive.google.com/file/d/0B7OY5pub_GfIcnFFUGJRT3ZTV00/edit?usp=sharing

assumes 25 MHz HSE crystal X4

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vneff
Associate II
Posted on December 11, 2013 at 18:05

Mr Clive1,

Thank you so much!  That was what I needed to figure what was wrong with my stuff.

It turned out that the flags -mcpu=cortex-m3  -mthumb

was not being passed to the linker, only the compiler.

I knew it was a simple error.

Having a known working example using open source tools was exactly what I needed.

Unfortunately, all the examples from ST are via commercial toolchains.

 

Thanks again,

Vance

Posted on December 11, 2013 at 19:14

Glad it worked, bit of a blind gamble on my part.

The code itself wasn't ''known working'' as I don't have the board in question, but the framework has been used successfully on other F2 and F4 projects, and was ported to your board using a ''best effort'' process designed to have a high chance of success. It's easier for me to tunnel from the other end than try to recreate the issues, compiler/linker settings et al.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
karthiksun
Associate
Posted on October 01, 2014 at 17:53

arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -Tstm32f217ig.ld -g -Wl,-Map=out/demo.map,--cref,--no-warn-mismatch -Wl,--gc-sections -nostartfiles  out/startup_stm32f2xx.o out/stm322xg_eval.o out/stm32f2xx_gpio.o out/stm32f2xx_usart.o out/main.o out/misc.o out/system_stm32f2xx.o out/stm32f2xx_rcc.o out/newlib_stubs.o out/stm32f2xx_it.o   -o out/demo.elf

c:/program files (x86)/gnu tools arm embedded/4.8 2014q2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: section .ARM.exidx loaded at [08005ddc,08005de3] overlaps section .data loaded at [08005ddc,08006697]

collect2.exe: error: ld returned 1 exit status

I get the above error while compiling. What is missing?

I did try to program with the binary provided in the zip file and that works great.

I need to port this to the STM3220G_EVAL board, what do I change if any in the linker script to support stm32f207.

Thank you.