How to retarget printf to UART in SES(v5.50) with SEEGER Compiler and Runtime Library

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • How to retarget printf to UART in SES(v5.50) with SEEGER Compiler and Runtime Library

      ^^ Hello guys, i'm a student and i'm learning STM32. I used to programming in Keil5(MDK), but i met the SES few days ago and fell in love with it soon. :P
      I met some troubles, i want to retarget printf to UART, if i import project from Keil and use the ARMCC, that will be very easy, the only thing i should do is "use the MircoLib and retarget printf to UART via some codes".
      But if i Set Build Configurations to "Internal"(using the SEEGER Compiler/ Linker, Include Standard Libraries with SEGGER Runtime Library), i can't make it work X/ .i know that if i retarget printf to UART, the "Library I/O" shouldn't be setted to SEMIHOST(or RTT/SWO), so i set it to the "STD".
      After that i followed the wiki,and found that:

      SEGGER Wiki wrote:

      When STD is selected as Library I/O, the user has to supply an implementation of int __SEGGER_RTL_stdout_putc(int c); which can be used to route character output to any resource, such as a UART or other terminal.
      so i guess, i should set the "Library I/O = STD" and define the int __SEGGER_RTL_stdout_putc(int c) to retarget the printf().
      And I did it,but i get a strange error: undefined symbol: __SEGGER_RTL_X_file_write
      After many attempts, i couldn't find the reason, but to my surprise, if i set the options "Code > Compiler > Use Compiler Driver = NO-->YES", the error will gone, but printf() still not working ?( .
      that's my code,trying to retarget printf to UART1, like what i done in keil, emm, and i'm using the STM32 HAL library yet.

      C Source Code: retarget printf to UART

      1. #if 1
      2. //#pragma import(__use_no_semihosting)
      3. int __SEGGER_RTL_stdout_putc(int ch)
      4. {
      5. HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
      6. return ch;
      7. }
      8. #endif
      if you can help me, i would appreciate it very much! :thumbsup: Forgive my poor English ;( ~~