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

Migrating from Keil to SES - Error with DFU INIT service

Hello Guys,,

I am trying to migrate my project form keil to segger embedded studio. My product is based on sdk 12.2.0, using softdevice s130 on nrf51822.
I searched for all the posts that helped in migrating to SES and able to successfully build my application project. But when flashing the build to my board
it is getting stuck at nrf_dfu_flash_erase function in dfu_init

I tried debugging and it is giving the error FS_ERR_INVALID_CFG in check_config(p_config) function. searched for the solution in the forum posts but nothing helped so far.
please help us to resolve as we are nearing production.


I am attaching my flash placement file for your reference

<!DOCTYPE Linker_Placement_File>
<Root name="Flash Section Placement">
  <MemorySegment name="$(FLASH_NAME:FLASH)">
    <ProgramSection alignment="0x100" load="Yes" name=".vectors" start="$(FLASH_START:)" />
    <ProgramSection alignment="4" load="Yes" name=".fs_data" />
    <ProgramSection alignment="4" load="Yes" name=".init" />
    <ProgramSection alignment="4" load="Yes" name=".init_rodata" />
    <ProgramSection alignment="4" load="Yes" name=".text" />
    <ProgramSection alignment="4" load="Yes" name=".dtors" />
    <ProgramSection alignment="4" load="Yes" name=".ctors" />
    <ProgramSection alignment="4" load="Yes" name=".rodata" />
    <ProgramSection alignment="4" load="Yes" name=".ARM.exidx" address_symbol="__exidx_start" end_symbol="__exidx_end" />
    <ProgramSection alignment="4" load="Yes" runin=".fast_run" name=".fast" />
    <ProgramSection alignment="4" load="Yes" runin=".data_run" name=".data" />
    <ProgramSection alignment="4" load="Yes" name=".bootloaderSettings" />
    <ProgramSection alignment="4" load="Yes" runin=".tdata_run" name=".tdata" />
    <ProgramSection alignment="4" keep="Yes" load="Yes" runin=".fs_data_run" name=".fs_data" />
  </MemorySegment>
  <MemorySegment name="$(RAM_NAME:RAM);SRAM">
    <ProgramSection alignment="0x100" load="No" name=".vectors_ram" start="$(RAM_START:$(SRAM_START:))" />
    <ProgramSection alignment="4" load="No" name=".fast_run" />
    <ProgramSection alignment="4" load="No" name=".data_run" />
    <ProgramSection alignment="4" load="No" name=".bss" />
    <ProgramSection alignment="4" load="No" name=".tbss" />
    <ProgramSection alignment="4" load="No" name=".tdata_run" />
    <ProgramSection alignment="4" load="No" name=".non_init" />
    <ProgramSection alignment="4" size="__HEAPSIZE__" load="No" name=".heap" />
    <ProgramSection alignment="8" size="__STACKSIZE__" load="No" place_from_segment_end="Yes" name=".stack" />
    <ProgramSection alignment="8" size="__STACKSIZE_PROCESS__" load="No" name=".stack_process" />
    <ProgramSection alignment="4" size="__STACKSIZE__" load="No" name=".fs_data_run" address_symbol="__start_fs_data"  end_symbol="__stop_fs_data" />
    <ProgramSection alignment="4" keep="Yes" load="No" name=".fs_data_run" address_symbol="__start_fs_data"  end_symbol="__stop_fs_data" />
  </MemorySegment>
  <MemorySegment name="$(FLASH2_NAME:FLASH2)">
    <ProgramSection alignment="4" load="Yes" name=".text2" />
    <ProgramSection alignment="4" load="Yes" name=".rodata2" />
    <ProgramSection alignment="4" load="Yes" runin=".data2_run" name=".data2" />
  </MemorySegment>
  <MemorySegment name="$(RAM2_NAME:RAM2)">
    <ProgramSection alignment="4" load="No" name=".data2_run" />
    <ProgramSection alignment="4" load="No" name=".bss2" />
  </MemorySegment>
</Root>

  • Thanks! Ok, now I think that i understand more. If you are using the bootloader from SDK v12.2.0, then the FLASH Origion + the FLASH length == Bootloader start address

    In the default bootloader from SDK v12.2.0 starts at 0x7A000, so the length of the flash for the application should be set to 0x3AC00- 0x1B000 = 0x1FC00

    So the issue is that the ble_dfu_init function return a non-zero error code? If yes, which error code is it? 

    Are you still seeing the FDS_ERR_NO_PAGES being returned by fds_init when initializing the Peer Manager module?( call tree peer_manager_init() -> pm_init() ->pds_init()-fds_init()?

    In the SDK v12.2.0 buttonless dfu example peer_manager_init() is called before the services are initialized. So please make sure that you call your dfu_init() function after ble_stack_init() and peer_manager_init(). 

    Best regards

    Bjørn

  • Thanks for the reply Bjorn.

    I am trying to debug and find the return value of the function ble_dfu_init() function. But unfortunately, the function is not returning. it is returning FS_ERR_UNALIGNED_ADDR error for fs_erase function.

    No, fds_init() function is now returning success response.

    I have checked my code and dfu_init function is only called after ble_stack_init() and peer_manager_init() functions. So i dont see any issues with it.

    Best,
    Krish

  • HI Krish, 

    Ok, so then it has to be the nrf_dfu_settings_write() call at the end to nrf_dfu_settings_init(), which is called at the end of ble_dfu_init() that is the cause. As the error code implies, the address passed to nrf_dfu_flash_erase is not aligned to a page boundary.

    /**@brief Function for erasing data from flash (with or without the SoftDevice enabled).
     *
     * @param[in]  p_dest    The address of the first byte to be deleted.
     * @param[in]  num_pages The number of flash pages to be deleted.
     * @param[in]  callback  Pointer to the callback function.
     *
     * @retval  FS_SUCCESS              If the operation was successful.
     * @retval  FS_ERR_UNALIGNED_ADDR   If @p p_dest is not aligned to a page boundary.
     * @retval  FS_ERR_INVALID_ADDR     If @p p_dest does not point to the start of a flash page or the operation would
     *                                  go beyond the flash memory boundary.
     * @retval  FS_ERR_NOT_INITIALIZED  If the fstorage module is not initialized.
     * @retval  FS_ERR_INVALID_CFG      If the initialization of the fstorage module is invalid.
     * @retval  FS_ERR_NULL_ARG         If @p p_dest is NULL.
     * @retval  FS_ERR_INVALID_ARG      If @p num_pages is zero.
     * @retval  FS_ERR_QUEUE_FULL       If the internal operation queue of the fstorage module is full.
     */
    fs_ret_t nrf_dfu_flash_erase(uint32_t const * p_dest, uint32_t num_pages, dfu_flash_callback_t callback);

    Can you set a breakpoint at nrf_dfu_flash_erase in nrf_dfu_settings_write() in nrf_dfu_settings.c? What is the pointer to to the m_dfu_settings_buffer? It should be 0x0003FC00.

    Best regards

    Bjørn

  • Thanks for the quick reply .

    I don't think the pointer is at 0x0003FC00. Attaching the screenshot of the debug trace for your reference.

    Best,

    Krish

  • Yes, looking at the .map file you sent I see that the bootloader settings are place at 0x3ef84

    .bootloaderSettings
                    0x000000000003ef84      0x400
                    0x000000000003ef84                __bootloaderSettings_start__ = .
     *(.bootloaderSettings .bootloaderSettings.*)
     .bootloaderSettings
                    0x000000000003ef84      0x400 Output/SpineFit Strack Internal/Obj/nrf_dfu_settings.o
                    0x000000000003ef84                m_dfu_settings_buffer
                    0x000000000003f384                __bootloaderSettings_end__ = (__bootloaderSettings_start__ + SIZEOF (.bootloaderSettings))
                    0x0000000000000400                __bootloaderSettings_size__ = SIZEOF (.bootloaderSettings)
                    0x000000000003f384                __bootloaderSettings_load_end__ = __bootloaderSettings_end__
                    0x0000000000000001                . = ASSERT (((__bootloaderSettings_start__ == __bootloaderSettings_end__) || ((__bootloaderSettings_end__ - __FLASH_segment_start__) <= __FLASH_segment_size__)), error: .bootloaderSettings is too large to fit in FLASH memory segment)
                    0x000000000003f384                __data_load_start__ = ALIGN (__bootloaderSettings_end__, 0x4)

    The m_dfu_settings_buffer is placed in a section called .bootloaderSettings. 

    uint8_t m_dfu_settings_buffer[CODE_PAGE_SIZE] __attribute__ ((section(".bootloaderSettings")))
                                                  __attribute__((used));

    I cant see any bootloaderSettings in your flash_placement.xml file you attached to your question, so need to add this snippet to your projects flash_placement.xml file   

    <MemorySegment name="bootloaderSettings" start="0x0003FC00" size="0x400">
        <ProgramSection alignment="4" keep="Yes" load="No" name=".bootloaderSettings" address_symbol="__start_bootloader_settings" end_symbol="__stop_bootloader_settings" start = "0x0003FC00" size="0x400" />
    </MemorySegment>

Related