Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to de-init the NRF_LOG module

Hi Nordic,

I am writing a simple boot-loader, which is working fine without NRF_LOG module enabled. But if I enable the NRF_LOG module, the main app stops working when it is initializing the NRF_LOG again.

I cannot seem to find a way to de-initialize the NRF_LOG module after enabling it. Can you please help me to find a way to do that?

This is what I do to initialize the LOG module (besides enabling it in sdk_config):

int rc = NRF_LOG_INIT(NULL);

APP_ERROR_CHECK(rc);

NRF_LOG_DEFAULT_BACKENDS_INIT();

  • Hi

    A typical reason for missing or corrupt RTT logs is that both the bootloader and application use RTT logging. If you edit either one of them so that one uses the UART instead this should resolve this issue for you. 

    I'm afraid it's not possible to turn off the logging module during run time in our SDK. If it is turned on it stays on, so if you'd like to only log certain parts of your application before turning it on I suggest that you look into using the UART directly without the logging module instead.

    Best regards,

    Simon

  • Hi Simon,

    Thanks for your reply.

    Both bootloader and main application currently use UART as backend for logging. The issue is that if I turn on NRF_LOG in the bootloader application, the bootloader prints out LOG entries just fine, but then when it jumps to the main application, the main app works fine until it does runs NRF_LOG_INIT() or NRF_LOG_DEFAULT_BACKENDS_INIT(). The main app stops working and never prints out any LOG entries and also does not continue to run the application (without logging)

    If I disable the uart logging in the bootloader, then the main application works just fine and prints out LOG entries just fine.

    So I am not using RTT logging. I am using UART logging for both bootloader and main app.

  • Hi

    Thank you for the update. NRF_LOG_FLUSH should return when the queued log data has been emptied. Are you calling NRF_LOG_FLUSH or NRF_LOG_PROCESS from any other places in your code except in main()? You can try commenting out NRF_LOG_FLUSH call in nrf_bootloader_app_start allow you to jump to the application?

    You can also try using RTT logging for one instance and UART logging for the other if that's possible.

    Best regards,

    Simon

  • Hi Simon,

    But I am not using the NRF bootloader - I am writing my own bootloader! And my bootloader works perfectly.

    The last thing I do in the bootloader is this:

    NRF_LOG_INFO("Booting image in SLOT 0 at address 0x%x", SLOT_0_ADDR);NRF_LOG_FLUSH();

    Then I set MSP (stackpointer) and update the SCB->VTOR vector table.

    Everything up to this point is fine, also if NRF_LOG is enabled in the sdk_config.

    Now the bootloader jumps to the main app.

    The main app starts executing at SLOT_0_ADDR - which is also working fine. Until the main app executes this:

    NRF_LOG_INIT(NULL);
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    NRF_LOG_INFO("Starting Main App ver %d.%d.%d...", FW_MAJOR, FW_MINOR, FW_PATCH);

    The main app basically tries to initialize the NRF_LOG again and it fails and stops working. I suspect that if de-initialize the NRF_LOG in the bootloader, then the main app will succeed in re-initializing it. However, I need your help with this, as there are no way to de-initialize the NRF_LOG.

    So the question is this: Why do the main app stop working when (re)initializing NRF_LOG_INIT() ?

    Or more precisely: I want to be able to use NRF_LOG in both my own bootloader and my own main-app. How do I do that?

    Thanks for your replies Slight smile

  • Well, the NRF_LOG module is not dynamic, so if it's on it's on. I assume resetting the device whenever go from the bootloader to your application is not viable for you? Because if you do that you can init the log for the application after the reset, as there is no way to deinit the NRF_LOG module during run time.

    So I would suggest that you use the UART directly, without the logging module so that you can uninitialize once you're done. You'll have to call the prints with another call than NRF_LOG_INFO(), but other than that it should be rather similar to the NRF_LOG_MODULE in terms of performance and current consumption.

    Using the NRF_LOG_MODULE in both bootloader and app won't be possible I'm afraid.

    Best regards,

    Simon

Related