how to flash default app data while programming?

I am working on SDK17.1 with SES. I am developing an BLE application that has bootloader (buttonless dfu), softdevice(s340 7.0.1) and fds. My application requires some data that are stored in flash (fds) to run. I want to flash default values of these data while I am programming the NRF52840 for the first time or after full chip erase. How can I do that while using SES?

Parents
  • Hello ,

    I am not sure if there is a builtin SES way to do that, however, here are some steps you could look at:

    Using j-link commander you can do the following https://wiki.segger.com/J-Link_Commander#LoadFile 

    connect
    loadfile <absolute bin file> 0x40000

    This will write the corresponding bytes contained in the file at the specific address 0x40000.

    To get the default data, in the application, directly write the necessary files as default.

    void default_write(void)
    {
        fds_record_t record = {0};
        fds_record_desc_t record_desc;
    
        fds_init();
    
        record.file_id           = FDS_DEFAULT_RECORD_ID;
        record.key               = FDS_DEFAULT_RECORD_KEY;
        record.data.p_data       = &default_data;
        record.data.length_words = ARRAY_SIZE(default_data_t);
        fds_record_write(&record_desc, &record);
    
        // Wait for FDS operation to complete
        while (!fds_check_result(&record_desc));
    }

    Then, once you programmed the binary to the target nrf52, read back the flash content at the location of the FDS partition's address to store it in a .bin file.
    You can use nrfjprog --memrd or, by using jlink commander (https://wiki.segger.com/J-Link_Commander#SaveBin):

    SaveBin <filename> <addr> <NumBytes>

    Now that you have the default partition content data, you can update the linker script to put this data to the proper location in the final binary so that it will have the default values at the proper address.

    const uint8_t FDS_DATA[] __attribute__((section("dataFds"))) = {0x12, 0x34, 0x56, 0x78};

    You can look at https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/sdk_config.html to update the config and add where the dataFds array should go:

    { .dataFds: { *(.dataFds) } > 0x040000 }

Reply
  • Hello ,

    I am not sure if there is a builtin SES way to do that, however, here are some steps you could look at:

    Using j-link commander you can do the following https://wiki.segger.com/J-Link_Commander#LoadFile 

    connect
    loadfile <absolute bin file> 0x40000

    This will write the corresponding bytes contained in the file at the specific address 0x40000.

    To get the default data, in the application, directly write the necessary files as default.

    void default_write(void)
    {
        fds_record_t record = {0};
        fds_record_desc_t record_desc;
    
        fds_init();
    
        record.file_id           = FDS_DEFAULT_RECORD_ID;
        record.key               = FDS_DEFAULT_RECORD_KEY;
        record.data.p_data       = &default_data;
        record.data.length_words = ARRAY_SIZE(default_data_t);
        fds_record_write(&record_desc, &record);
    
        // Wait for FDS operation to complete
        while (!fds_check_result(&record_desc));
    }

    Then, once you programmed the binary to the target nrf52, read back the flash content at the location of the FDS partition's address to store it in a .bin file.
    You can use nrfjprog --memrd or, by using jlink commander (https://wiki.segger.com/J-Link_Commander#SaveBin):

    SaveBin <filename> <addr> <NumBytes>

    Now that you have the default partition content data, you can update the linker script to put this data to the proper location in the final binary so that it will have the default values at the proper address.

    const uint8_t FDS_DATA[] __attribute__((section("dataFds"))) = {0x12, 0x34, 0x56, 0x78};

    You can look at https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/sdk_config.html to update the config and add where the dataFds array should go:

    { .dataFds: { *(.dataFds) } > 0x040000 }

Children
No Data
Related