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

app_context_load/dm_application_context_get

SDK 9.0, examples/ble_peripheral/ble_app_hrs

Trying to use DFU with a bond device, I got aware, that after the update, some "static" data seems to get corrupted during startup.

I found in main.c, app_context_load:

static uint32_t          context_data;
dm_application_context_t context;

context.len    = sizeof(context_data);
context.p_data = (uint8_t *)&context_data;

err_code = dm_application_context_get(p_handle, &context);

and in dm_application_context_get:

err_code = pstorage_load(p_context->p_data,
                                 &block_handle,
                                 DEVICE_MANAGER_APP_CONTEXT_SIZE,
                                 (APP_CONTEXT_STORAGE_OFFSET + sizeof(uint32_t)));

Though DEVICE_MANAGER_APP_CONTEXT_SIZE is set to 16 in config/device_manager_cnfg.h

Fixing DEVICE_MANAGER_APP_CONTEXT_SIZE to 4 (or enlarging the context_data) makes the startup after update working.

So my question: must the context data match exactly the size defined in DEVICE_MANAGER_APP_CONTEXT_SIZE, or should dm_application_context_get obey the given size in context.len?

Parents
  • in main.c

        static void app_context_load(dm_handle_t const * p_handle)
        {
            uint32_t                 err_code;
            static uint32_t          context_data[DEVICE_MANAGER_APP_CONTEXT_SIZE /
                                                               sizeof(uint32_t)];
        dm_application_context_t context;
    
        context.len    = sizeof(context_data);
        context.p_data = (uint8_t *)&context_data;
    
        err_code = dm_application_context_get(p_handle, &context);
        if (err_code == NRF_SUCCESS)
       {
           // Send Service Changed Indication if ATT table has changed.
           if ((context_data[0] & (DFU_APP_ATT_TABLE_CHANGED << 
                 DFU_APP_ATT_TABLE_POS)) != 0)
           {
    

    I use a a size of 16 and enlarge context data. The bug is still in the SDK and the contained hrs_dfu demo. To say it clear: YOUR DEMO CORRUPST THE MEMORY! FIX IT!

Reply
  • in main.c

        static void app_context_load(dm_handle_t const * p_handle)
        {
            uint32_t                 err_code;
            static uint32_t          context_data[DEVICE_MANAGER_APP_CONTEXT_SIZE /
                                                               sizeof(uint32_t)];
        dm_application_context_t context;
    
        context.len    = sizeof(context_data);
        context.p_data = (uint8_t *)&context_data;
    
        err_code = dm_application_context_get(p_handle, &context);
        if (err_code == NRF_SUCCESS)
       {
           // Send Service Changed Indication if ATT table has changed.
           if ((context_data[0] & (DFU_APP_ATT_TABLE_CHANGED << 
                 DFU_APP_ATT_TABLE_POS)) != 0)
           {
    

    I use a a size of 16 and enlarge context data. The bug is still in the SDK and the contained hrs_dfu demo. To say it clear: YOUR DEMO CORRUPST THE MEMORY! FIX IT!

Children
No Data
Related