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 ;( ~~
    • New

      Hi,

      Sorry for the delay in response.
      There have indeed been changes to the RTL implementation here for the STD I/O.
      As the error message suggests you need to supply an implementation of __SEGGER_RTL_X_file_write now.
      This has been addressed in the documentation here:
      wiki.segger.com/Embedded_Studio_Library_IO#STD


      Best regards,

      Nino
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • New

      Hello to all,
      I found yesterday the declacation to the __SEGGER_RTL_X_file_write() in corresponding __SEGGER_RTL.h.
      So I included the following function in my project and it works.

      C Source Code

      1. int __SEGGER_RTL_X_file_write (__SEGGER_RTL_FILE *__stream, const char *__s, unsigned __len)
      2. {
      3. HAL_UART_Transmit(&huart1, __s, __len, 10);
      4. return 0;
      5. }

      But i can't replay this yesterday, because my registration for this forum was approved today.
      So I saw the new description for this issue form Nino today.

      But I have further question:

      What ist the definitin for the return value of __SEGGER_RTL_X_file_write(..)?


      Kind regards

      AxKe
    • New

      Hi AxKe,

      Indeed the return values were not described.
      We updated the Wiki accordingly.
      wiki.segger.com/Embedded_Studio_Library_IO#STD

      Keep in mind that if you retarget to e.g. a filesystem and if the disk returns that it is full, the return value for the write function would still be considered "OK".

      Best regards,
      Nino
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.