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

How do I redirect printf in ble_template_app?

So I'm trying to start off development of my project using the PCA10040 development board. I have downloaded the SDK16 and built a couple of examples no problem using SES. Now I have started using the ble_app_template  - which builds fine and seems just right to base development on.

Until I try to use the UART. I've searched & tried dozens of things, none of which work and often break the project. Often the Googled answer to a question is just "please look at the UART example" which doesn't help with modifying another example. After two days of trying to get this one simple thing working I've finally decided to ask here..

It looks like the printf redirect is the simplest option, but there isn't any option in the sdconfig.h which is incomplete.

So what do I need to do to turn off the debug logging and to output to the UART?

Thanks!

Parents
  • Hi,

    To enable retargeting of the STDIO functions, you need to include the source file into the project:

    nRF5_SDK_16.0.0_684aa2c\components\libraries\uart\retarget.c

    And enable it in your sdk_config.h file (add the lines yourself if they are not there):

    // <q> RETARGET_ENABLED  - retarget - Retargeting stdio functions
    
    #ifndef RETARGET_ENABLED
    #define RETARGET_ENABLED 1
    #endif

    This uses the app_uart library, so you need to include and initialize this as well, similar to how it is done in the UART peripheral example.

    Also, make sure that the UART backend is disabled for NRF_LOG module, otherwise, you may get errors when initializing logger (if you want to keep logging over RTT, etc.):

    // <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 0
    #endif

    Best regards,
    Jørgen

  • Thanks for a quick answer Jorgen

    I've done all the above - although this is the bit I think I'm having trouble with:

    This uses the app_uart library, so you need to include and initialize this as well, similar to how it is done in the UART peripheral example.

    So I added retarget.c and changed sdk_config.h as above. Then I added \components\libraries\uart\app_uart.c and rebuild the project and it builds OK.

    Now if I put a simple printf in main() and rebuild it fails with this error

    retarget.c:105: undefined reference to `app_uart_put'
    Build failed

    What exactly do you mean by "initialize this" (app_uart)

Reply
  • Thanks for a quick answer Jorgen

    I've done all the above - although this is the bit I think I'm having trouble with:

    This uses the app_uart library, so you need to include and initialize this as well, similar to how it is done in the UART peripheral example.

    So I added retarget.c and changed sdk_config.h as above. Then I added \components\libraries\uart\app_uart.c and rebuild the project and it builds OK.

    Now if I put a simple printf in main() and rebuild it fails with this error

    retarget.c:105: undefined reference to `app_uart_put'
    Build failed

    What exactly do you mean by "initialize this" (app_uart)

Children
No Data
Related