Retarget Printf and Friends to UART

A project log for Notes on Using SystemWorkbench with STM32 BluePill

I finally succumb to IDE madness... for awhile.

Al WilliamsAl Williams 04/03/2017 at 12:352 Comments
  1. Make sure you have enough stack! If you didn't set it at project generation time, fix it in your .ld file (and be sure to fix it in the CubeMX project too in case you regenerate.
  2. Also, create a dummy project with the IDE and NOT CubeMX. Steal the syscalls.c file from that project and put it in your project.
  3. Obviously, you need to set up the UART in CubeMX.
  4. Add this:
int __io_putchar(int ch)


uint8_t ch8=ch;

HAL_UART_Transmit(&huart1,(uint8_t *)&ch8,1,HAL_MAX_DELAY);

return ch;


int __io_getchar()


uint8_t ch8;


return 0;


Done! Mysterious crashes means your stack is too small or you have left the boot jumpers set funny and SP isn't set to what you think it is.


Yann Guidon / YGDES wrote 04/03/2017 at 20:20 point

I hate printf....

  Are you sure? yes | no

Al Williams wrote 04/03/2017 at 14:28 point

Oops. Obviously __io_getchar needs to return ch8 not 0. Sorry!

  Are you sure? yes | no