AnsweredAssumed Answered

USART_printf not working on STM323221G_eval via GNU_ARM_GCC

Question asked by neff.vance on Nov 27, 2013
Latest reply on Oct 1, 2014 by skuul32

I haven't been able to get the example:
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 12.11

Any ideas will be appreciated!!!!

#include "stm32f2xx.h"
#include "stm322xg_eval.h"
#include <stdio.h>
USART_InitTypeDef USART_InitStructure;
#ifdef __GNUC__
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
  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 );
  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);
    USART_SendData(EVAL_COM1, 0x49); // Send 'I'
#ifdef __GNUC__
    __io_putchar( 0x4A);
    fputc( 0x4B, (FILE *)NULL);
#endif // __GNUC__
  printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
  while (1)