get printf to send characters to SCI UART

Using the EK_RA4M3 with the latest AzureRTOS/threadx  I want to have printf redirect to SCI UART.  

I am confused as to how I get the access to the printf write/putch/puts using the Renesas FSP?

int _write(int file, char *buffer, int count)


    R_SCI_UART_Write (&g_uart_sci9_ctrl, (uint8_t const *)buffer, count);

    return 0;


I assume I have to set a flag or something to overwrite the default call?

  • I would suggest you set --specs=nosys.specs as a linker flag, so the version of the Newlib C runtime library is using stubs for the syscalls :-

    The default linker setting of --specs=rdimon.specs is a semihosted version of the C runtime library.

    Then all you need to do is define your version of the required syscall in your code, and it will override the stub version in the C runtime library

    The return value from the function _write() should be the number of bytes written, not 0. You should also make sure that the previous write to the UART has finished before calling R_SCI_UART_Write() again.

    You will also need to set some heap in the BSP tab of the configurator, as some of the C runtime library functions will malloc from the heap.

    If you are using newlib-nano (the default setting) then if you want printf() to support floating point format, you would need to check the box to add support :-

  • Thanks Jeremy that was very helpful and I now have printf sending characters out uart sci.

  • Hi photonthunder-

    If you are able to share your code with us, please do. It will help others with a similar requirement.

  • int _write(int file, char *buffer, int count)


        if ((file != STDOUT_FILENO) && (file != STDERR_FILENO))


           return -1;


        R_SCI_UART_Write (&g_uart_sci9_ctrl, (uint8_t const *)buffer, count);

        return count;


Reply Children
No Data