How to enable logging in Ble secure DFU example pca10056

Dear nordic team,

                            i want to take log from dfu example i tried using rtt veiwer but it doesnt work.im using sdk version 17.0.2 and soft device 7.2.0 and nrf52840 DK

in nrf drivers/ folder there is no uart related files do we need this for taking logs.pls help

Parents
  • ble_secure_dfu_debug has the dfu working..how can i enable it in ble_secure_dfu  

  • Hi,

    You have to increase the size of the bootloader and then add the logger module and its RTT dependencies like in the ble_secure_dfu_debug project. But it would probably be quicker to just add enable the SPIS code in the ble_secure_dfu_debug project.

  • Hi,

    Please make the following changes to main.c and your Segger project to get a more verbose crash log:

    ff --git a/secure_bootloader/main.c b/secure_bootloader/main.c
    index 788970e..3585d9c 100644
    --- a/secure_bootloader/main.c
    +++ b/secure_bootloader/main.c
    
    +#ifndef DEBUG
     void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
     {
         NRF_LOG_ERROR("%s:%d", p_file_name, line_num);
     }
    
     void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
     {
         NRF_LOG_ERROR("Received a fault! id: 0x%08x, pc: 0x%08x, info: 0x%08x", id, pc, info);
         on_error();
     }
    
     void app_error_handler_bare(uint32_t error_code)
     {
         NRF_LOG_ERROR("Received an error: 0x%08x!", error_code);
         on_error();
     }
    +#endif
    
    diff --git a/secure_bootloader/pca10056_s140_ble_debug/ses/secure_bootloader_ble_s140_pca10056_debug.emProject b/secure_bootloader/pca10056_s140_ble_debug/ses/secure_bootloader_ble_s140_pca10056_debug.emProject
    index 220d382..f8b9bd1 100644
    --- a/secure_bootloader/pca10056_s140_ble_debug/ses/secure_bootloader_ble_s140_pca10056_debug.emProject
    +++ b/secure_bootloader/pca10056_s140_ble_debug/ses/secure_bootloader_ble_s140_pca10056_debug.emProject
    @@ -15,27 +18,27 @@
           arm_simulator_memory_simulation_parameter="RWX 00000000,00100000,FFFFFFFF;RWX 20000000,00010000,CDCDCDCD"
           arm_target_device_name="nRF52840_xxAA"
           arm_target_interface_type="SWD"
    +      c_preprocessor_definitions="DEBUG;BLE_STACK_SUPPORT_REQD;BOARD_PCA10056;CONFIG_GPIO_AS_PINRESET;DEBUG_NRF;FLOAT_ABI_HARD;INITIALIZE_USER_SECTIONS;NO_VTOR_CONFIG;NRF52840_XXAA;NRF_DFU_DEBUG_VERSION;NRF_DFU_SETTINGS_VERSION=2;NRF_DFU_SVCI_ENABLED;NRF_SD_BLE_API_VERSION=7;S140;SOFTDEVICE_PRESENT;SVC_INTERFACE_CALL_AS_NORMAL_FUNCTION"
    -      c_preprocessor_definitions="BLE_STACK_SUPPORT_REQD;BOARD_PCA10056;CONFIG_GPIO_AS_PINRESET;DEBUG_NRF;FLOAT_ABI_HARD;INITIALIZE_USER_SECTIONS;NO_VTOR_CONFIG;NRF52840_XXAA;NRF_DFU_DEBUG_VERSION;NRF_DFU_SETTINGS_VERSION=2;NRF_DFU_SVCI_ENABLED;NRF_SD_BLE_API_VERSION=7;S140;SOFTDEVICE_PRESENT;SVC_INTERFACE_CALL_AS_NORMAL_FUNCTION;"
    @@ -63,6 +66,8 @@
           <file file_name="../../../../../components/libraries/ringbuf/nrf_ringbuf.c" />
           <file file_name="../../../../../components/libraries/experimental_section_vars/nrf_section_iter.c" />
           <file file_name="../../../../../components/libraries/strerror/nrf_strerror.c" />
    +      <file file_name="../../../../../components/libraries/util/app_error.c" />
    +      <file file_name="../../../../../components/libraries/util/app_error_handler_gcc.c" />

    Summary of changes:

    1. Exclude app_error_handler(), app_error_fault_handler, and app_error_handler_bare() in main.c if DEBUG flag is set.

    2. Add the app_error_handler_gcc.c and app_error.c source file to the project

    3. Define "DEBUG" in the list of pre-processor symbols:

  • i also having error when  calling

    nrf_power_gpregret_set(nrf_power_gpregret_get() & ~BOOTLOADER_DFU_START);

    <error> app: Received a fault! id: 0x00001001, pc: 0x0000F4D2C, info: 0x00000001

  • after adding this it is giving me

    00> <debug> app: DFU mode requested via GPREGRET.
    00>
    00> <info> nrf_bootloader_wdt: WDT is not enabled
    00>
    00> <info> app: Entered gpio init
    00>
    00> <debug> app: in weak nrf_dfu_init_user
    00>
    00> <debug> app: timer_stop (0x20005994)
    00>
    00> <debug> app: timer_activate (0x20005994)
    00>
    00> <info> app: Entering DFU mode.
    00>
    00> <debug> app: Initializing transports (found: 1)
    00>
    00> <debug> nrf_dfu_ble: Initializing BLE DFU transport
    00>
    00> <debug> nrf_dfu_ble: Setting up vector table: 0x000F1000
    00>
    00> <debug> nrf_dfu_ble: Enabling SoftDevice.
    00>
    00> <debug> nrf_dfu_ble: Configuring BLE stack.
    00>
    00> <debug> nrf_dfu_ble: Enabling the BLE stack.
    00>
    00> <debug> nrf_dfu_ble: No advertising name found
    00>
    00> <debug> nrf_dfu_ble: Using default advertising name
    00>
    00> <debug> nrf_dfu_ble: Advertising...
    00>
    00> <debug> nrf_dfu_ble: BLE DFU transport initialized.
    00>
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_sd backend.
    00>
    00> <debug> app: Enter main loop
    00>
    00> <info> app: Transfer completed. Received:
    00>
    00> <info> app: 0xEE00,
    00>
    00> <info> app: 0xEF00,
    00>
    00> <info> app: 0x100,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: mac id transfer
    00>
    00> <info> app: Transfer completed. Received:
    00>
    00> <info> app: 0xEE00,
    00>
    00> <info> app: 0xEF00,
    00>
    00> <info> app: 0x2000,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: exit to app
    00>
    00> <error> app: Fatal error

    fatal error

  • You can't write directly to the POWER->GPREGRET register when the BLE transport is enabled. Instead you have to use sd_power_gpregret_set()

  • Looks like you haven't added the DEBUG flag as shown in my screenshot.

Reply Children
  • OK  thanks now i added everything and get error code as

    SOFTDEVICE: INVALID MEMORY ACCESS

    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: 0x0,
    00>
    00> <info> app: exit to app
    00>
    00> <error> app: SOFTDEVICE: INVALID MEMORY ACCESS

  • This assert indicates that the program has tried to access on of the peripherals reserved to the Softdevice (Hardware peripherals). While debugging, please read the 'info' value as the picture below shows. This will tell us which peripheral it was.

  • But dfu code without debug is working fine.that was my doubt and by adding these lines

    sd_power_gpregret_clr(0, 0xffffffff);
    sd_power_gpregret_set(0, ~BOOTLOADER_DFU_START);

    NVIC_SystemReset();

    it is working fine instead of this

    nrf_power_gpregret_set(nrf_power_gpregret_get() & ~BOOTLOADER_DFU_START);

    NVIC_SystemReset();

    i think when enabling debug is making the issue

  • The difference between the original debug and release project is that the debug variant includes logging and more relaxed security requirements (with regards to version validation), and that doesn't explain the INVALID MEMORY ACCESS assertion.

  • thanks for your response vidar.i have one more doubt that when enable the debug in bootloader i cant get logging from application code.with out enabling debug im getting log from application code

    ie.

    00> <info> app: Inside main
    00>
    00> <debug> app: In nrf_bootloader_init
    00>
    00> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    00>
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    00>
    00> <debug> nrf_dfu_settings: Using settings page.
    00>
    00> <debug> nrf_dfu_settings: Copying forbidden parts from backup page.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <debug> app: Enter nrf_bootloader_fw_activate
    00>
    00> <info> app: No firmware to activate.
    00>
    00> <debug> app: App is valid
    00>
    00> <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <debug> app: Running nrf_bootloader_app_start with address: 0x00001000
    00>
    00> <debug> app: Disabling interrupts. NVIC->ICER[0]: 0x10
    00>

    up to this im getting log but after this switching to app log is not coming from application

Related