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

UART example goes to debug window

I have been developing some nrf52832 code (SDK 17.0.2) using the Segger RTT debug window for logging.  I added the code from the UART example but the printf goes to the debug window not the UART.

In my sdk_config file I have the following:

// NRF_LOG_BACKEND_SERIAL_USES_UART - If enabled data is printed over UART
//==========================================================
#ifndef NRF_LOG_BACKEND_SERIAL_USES_UART
#define NRF_LOG_BACKEND_SERIAL_USES_UART 1
#endif

// NRF_LOG_BACKEND_SERIAL_USES_RTT - If enabled data is printed using RTT
//==========================================================
#ifndef NRF_LOG_BACKEND_SERIAL_USES_RTT
#define NRF_LOG_BACKEND_SERIAL_USES_RTT 0
#endif

//==========================================================
// <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
//==========================================================
#ifndef NRF_LOG_BACKEND_RTT_ENABLED
#define NRF_LOG_BACKEND_RTT_ENABLED 0
#endif

// <e> NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart - Log UART backend
//==========================================================
#ifndef NRF_LOG_BACKEND_UART_ENABLED
#define NRF_LOG_BACKEND_UART_ENABLED 1
#endif

// <o> NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin
#ifndef NRF_LOG_BACKEND_UART_TX_PIN
#define NRF_LOG_BACKEND_UART_TX_PIN 6
#endif

What else needs to be done to get the UART example to output on the UART and not on RTT?

Thanks for your help,

Tim

Parents Reply Children
  • I switched on RETARGET_ENABLED and added retarget.c to the project.  Now it no longer directs the printf output to the debug window, but I don't see anything on the terminal.  When I run the uart example code on my hardware it prints to the terminal so I know the hardware is working and my pinout is correct.  Anything else I might be missing? Seems like it is still a config or library issue.

    One more issue.  It looks like I cannot mix sending things out the UART with the example code AND sending logging messages to the RTT is that true?  I know it is not a hardware limitation but is it a code limitation of the library used in the UART example?  If so can you refer me to an example of how to use the UART independent of the logging?  I am thinking of just writing the low level drivers myself if necessary.

    Thanks for your help.

    Tim

  • Hi Tim,

    ProtonTim said:
    When I run the uart example code on my hardware it prints to the terminal so I know the hardware is working and my pinout is correct.

     Do you see the printf data being sent when using the unmodified UART example? The uart example code from the SDK is already correctly configured with printf. If you don't see any logs being printed when flashing an unmodified example then there is something outside of the application that is the culprit. Have you configured the terminal correct? Do you have a logic analyzer? Could you probe TX and RX and see if the nRF actually sends any data when printf is called in the application. 

     

    ProtonTim said:

    One more issue.  It looks like I cannot mix sending things out the UART with the example code AND sending logging messages to the RTT is that true?  I know it is not a hardware limitation but is it a code limitation of the library used in the UART example?  If so can you refer me to an example of how to use the UART independent of the logging?  I am thinking of just writing the low level drivers myself if necessary.

     You can use the UART in the application and use the logger module with RTT as a backend. You can't however both use UART in the application AND use UART as a backend for the logger module. The nRF52832 has only 1 UART instance. 

    It's important to note that what we traditionally view as the logger is the logger module which uses either RTT or UART as a backend. Retargeting printf as in the UART example is traditionally not viewed as part of the logger library as it just uses the app_uart functions to print the logs through UART. See the retarget.c file in the SDK if this doesn't make any sense Slight smile

    best regards

    Jared

  • Jared,

    As I mentioned earlier, the "stock" example UART app works fine on my hardware, including the printf so I am confident in my hardware.  However, in the code where the UART is not working properly I am using a different sdk_config file from what is being used in the UART example.  So it looks like it is still an issue with the sdk_config not being set properly.  I have added all the changes you recommended to the config file and printf fails to print to the terminal or anywhere else (though as I mentioned it works fine in the UART example).  Any suggestions as to where else to look in the sdk_config file?

    Thanks,

    Tim

  • Hi,

    Could you share your entire config file?

    regards

    Jared 

  • Yes I will share it.  I enabled  UART0_CONFIG_USE_EASY_DMA and now I get the first character of the printf string coming out the port followed by a carriage return.  Is the best way to share it to paste it into a code window?  I don't see an easy way to attach it.

Related