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

nrf52832 buttonless DFU with fstorage

I am using nrf52832 with buttonless DFU ,SDK 15.0,using fstorage.I want to store some device information in flash,such as serial number,hardware version,these data will not be erased duing DFU,and I want to save firmware version too,I tested that if I comment device read and write ,the DFU works well,if I uncomment device read and write,and rease 4to1 hex to device,it will not run to app and stuck in bootloader and broadcast.

this is my configuration:

Bootloader:start addr:0x78000,size:0x6000 ,end addr:0x7e000

APP:start addr:0x26000,size:0x5a000,end addr:0x80000

fstorage setting:

NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
/* Set a handler for fstorage events. */
.evt_handler = fstorage_evt_handler,
.start_addr = 0x73000,
.end_addr = 0x78000,
};

/*device information addr define*/

uint32_t Hardware_VerAddr           __attribute__ ((at(0x74400)));
uint32_t Serial_NumAddr               __attribute__ ((at(0x74300)));
uint32_t SN_HW_EXIST_Addr      __attribute__ ((at(0x74100)));
uint32_t Firmware_VerAddr           __attribute__ ((at(0x73FD0)));
uint32_t Firmware_EXIST_Addr    __attribute__ ((at(0x73FC0)));

I want to write hardware version and serial num in Reserved Application Data area,and write firmware version in the end of app.below 0x75000.

it covered Application Data area,I tried to change fstorage`s start_addr from 0x73000~0x75000, if I comment device read and write ,the DFU works well,if I uncomment device read and write,and rease 4to1 hex to device,it will not run to app and stuck in bootloader and broadcast.

Is there any configuration wrong?

 

Parents
  • This problem is solved. here is my solution:

    #define SN_HW_EXIST_MASK             (uint32_t)0x12345678u
    #define FIRMWARE_EXIST_MASK      (uint32_t)0x87654321u

    #define FSTORAGE_START_ADDR    (uint32_t)0x3EE00
    #define FSTORAGE_END_ADDR       (uint32_t)0x78000
    uint32_t Hardware_VerAddr                __attribute__ ((at(0x74400)));
    uint32_t Serial_NumAddr                    __attribute__ ((at(0x74300)));
    uint32_t SN_HW_EXIST_Addr           __attribute__ ((at(0x74100)));

    uint32_t Firmware_VerAddr               __attribute__ ((at(0x3EE10)));
    uint32_t Firmware_EXIST_Addr         __attribute__ ((at(0x3EE00)));

    I changed FW version addr and exist addr, fstorage start addr changed too,In my app,when dfu command comes, device prepare to enter bootloader,I reset the FW version exist addr`s value in ble_dfu_evt_handler, add  Reset_FIRMWARE_EXIST_MASK();

    void Reset_FIRMWARE_EXIST_MASK(void)
    {
    uint32_t data=0xFFFFFFFF;
    ret_code_t rc;
    rc = nrf_fstorage_write(&fstorage, (uint32_t )(&Firmware_EXIST_Addr),&data,sizeof(uint32_t), NULL);//写入标志
    APP_ERROR_CHECK(rc);
    }

    static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
    {
        switch (event)
        {
            case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
                NRF_LOG_INFO("Device is preparing to enter bootloader mode.");
                // YOUR_JOB: Disconnect all bonded devices that currently are connected.
                //           This is required to receive a service changed indication
                //           on bootup after a successful (or aborted) Device Firmware Update.
    			Reset_FIRMWARE_EXIST_MASK();
    		    nrf_gpio_pin_set(LED_RED);
                break;
    
            case BLE_DFU_EVT_BOOTLOADER_ENTER:
                // YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this
                //           by delaying reset by reporting false in app_shutdown_handler
    			Reset_FIRMWARE_EXIST_MASK();
    		    nrf_gpio_pin_set(LED_RED);
                NRF_LOG_INFO("Device will enter bootloader mode.");
                break;
    
            case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
                NRF_LOG_ERROR("Request to enter bootloader mode failed asynchroneously.");
                // YOUR_JOB: Take corrective measures to resolve the issue
                //           like calling APP_ERROR_CHECK to reset the device.
                break;
    
            case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
                NRF_LOG_ERROR("Request to send a response to client failed.");
                // YOUR_JOB: Take corrective measures to resolve the issue
                //           like calling APP_ERROR_CHECK to reset the device.
                APP_ERROR_CHECK(false);
                break;
    
            default:
                NRF_LOG_ERROR("Unknown event from ble_dfu_buttonless.");
                break;
        }
    }

    tell app that firmware  information does not exist,when dfu is finished,app reboot and rewrite firmware data and exist value .

    may this be helpful for others!

Reply
  • This problem is solved. here is my solution:

    #define SN_HW_EXIST_MASK             (uint32_t)0x12345678u
    #define FIRMWARE_EXIST_MASK      (uint32_t)0x87654321u

    #define FSTORAGE_START_ADDR    (uint32_t)0x3EE00
    #define FSTORAGE_END_ADDR       (uint32_t)0x78000
    uint32_t Hardware_VerAddr                __attribute__ ((at(0x74400)));
    uint32_t Serial_NumAddr                    __attribute__ ((at(0x74300)));
    uint32_t SN_HW_EXIST_Addr           __attribute__ ((at(0x74100)));

    uint32_t Firmware_VerAddr               __attribute__ ((at(0x3EE10)));
    uint32_t Firmware_EXIST_Addr         __attribute__ ((at(0x3EE00)));

    I changed FW version addr and exist addr, fstorage start addr changed too,In my app,when dfu command comes, device prepare to enter bootloader,I reset the FW version exist addr`s value in ble_dfu_evt_handler, add  Reset_FIRMWARE_EXIST_MASK();

    void Reset_FIRMWARE_EXIST_MASK(void)
    {
    uint32_t data=0xFFFFFFFF;
    ret_code_t rc;
    rc = nrf_fstorage_write(&fstorage, (uint32_t )(&Firmware_EXIST_Addr),&data,sizeof(uint32_t), NULL);//写入标志
    APP_ERROR_CHECK(rc);
    }

    static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
    {
        switch (event)
        {
            case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
                NRF_LOG_INFO("Device is preparing to enter bootloader mode.");
                // YOUR_JOB: Disconnect all bonded devices that currently are connected.
                //           This is required to receive a service changed indication
                //           on bootup after a successful (or aborted) Device Firmware Update.
    			Reset_FIRMWARE_EXIST_MASK();
    		    nrf_gpio_pin_set(LED_RED);
                break;
    
            case BLE_DFU_EVT_BOOTLOADER_ENTER:
                // YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this
                //           by delaying reset by reporting false in app_shutdown_handler
    			Reset_FIRMWARE_EXIST_MASK();
    		    nrf_gpio_pin_set(LED_RED);
                NRF_LOG_INFO("Device will enter bootloader mode.");
                break;
    
            case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
                NRF_LOG_ERROR("Request to enter bootloader mode failed asynchroneously.");
                // YOUR_JOB: Take corrective measures to resolve the issue
                //           like calling APP_ERROR_CHECK to reset the device.
                break;
    
            case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
                NRF_LOG_ERROR("Request to send a response to client failed.");
                // YOUR_JOB: Take corrective measures to resolve the issue
                //           like calling APP_ERROR_CHECK to reset the device.
                APP_ERROR_CHECK(false);
                break;
    
            default:
                NRF_LOG_ERROR("Unknown event from ble_dfu_buttonless.");
                break;
        }
    }

    tell app that firmware  information does not exist,when dfu is finished,app reboot and rewrite firmware data and exist value .

    may this be helpful for others!

Children
No Data
Related