This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Segger_RTT_Printf seems doesn't work with printf

I have a project using printf to send AT commands to a cellular modem. It works well. Yesterday I added Segger_RTT into the project.

With NRF_LOG_USES_RTT=0 defined. SEGGER_RTT_WriteString() has no problem. SEGGER_RTT_printf() won't work because it requires NRF_LOG_USES_RTT = 1.

So I define NRF_LOG_USES_RTT = 1 to get SEGGER_RTT_printf() working. And as I expected, SEGGER_RTT_printf() works like a charm.

But one thing got affected in my software. I had retarget.c included in my project to use "printf()" to send AT commands to my cellular modem. Now it doesn't work anymore.

Did I miss anything when I use SEGGER_RTT_printf() and printf() at the same time?

As a workaround I am using app_uart_put to replace printf().

Thanks

PS. I am using SDK11.0.0, nrf51422

Parents
  • If you take a look in retarget.c you'll see that it defines the fputc,fgetc, _write, _read and __write functions using app_uart_put(), which in turn are used by printf() . These functions are only defined if NRF_LOG_USES_RTT !=1.

    When NRF_LOG_USES_RTT =1, the functions are retargeted to the SEGGER_RTT implementations.

    Thus, the workaround you have implemented is the correct approach.

    Best regards

    Bjørn

Reply
  • If you take a look in retarget.c you'll see that it defines the fputc,fgetc, _write, _read and __write functions using app_uart_put(), which in turn are used by printf() . These functions are only defined if NRF_LOG_USES_RTT !=1.

    When NRF_LOG_USES_RTT =1, the functions are retargeted to the SEGGER_RTT implementations.

    Thus, the workaround you have implemented is the correct approach.

    Best regards

    Bjørn

Children
No Data
Related