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

Flash memory utilization

Dear Nordic Support Team,

I am trying to write some information in the flash memory without success. In the ble_flash.h file, it is specified that the pages 0-127 are reserved to the soft device. So, I can use the next page to store my data, am I right?

Can you tell me why the following code crash ?

uint32_t page = 128;

uint8_t word_count = 1;
uint32_t data_array[2]={0};

err_code = ble_flash_page_write(page,(uint32_t *) &data_array,1);
APP_ERROR_CHECK(err_code);
														
err_code = ble_flash_page_read(page, (uint32_t *) & data_array, &word_count);
APP_ERROR_CHECK(err_code);
Parents
  • This code most likely crashes because you are trying to overwrite the application code. There isn't a separate data flash in the nRF51822, so when you write to flash, you write to the same flash that the actual program runs from. You should therefore be careful not to erase or write to pages where there is program code, as the comment in ble_flash.h tells you.

    The softdevice occupies pages 0-79 (not 127 anymore, this is actually a bug in ble_flash.h) which translates to address 0 to 0x13FFF, while the application can use pages 79-255, address 0x14000 to 0x39FFF. However, this latter part will be shared between actual application code and data storage. It is a strict requirement that the code of the application starts at address 0x14000, and how far up it will go is simply a matter of how big it is.

    For data storage you should therefore make sure to use the upper pages. If you look at the bond manager, it uses pages 254 and 255, so I'd recommend you to use for example page 253 for other application storage needs.

    Also remember that any flash writing or erasing locks the CPU, so you need to be careful if you try to do this while in a BLE connection. Have a look at this question for details on this.

  • Dear Ole Morten,

    Thanks for helping me with this problem. I am just trying to test the read/write flash page feature without success.

    Please, have a look on my answer on this thread above to see my code. Teh code is executed at the end of the main function, just before the infinity loop containing the "sd_app_event_wait" softdevice function.

    At this point, the ble stack is started and I should be able to use ble_flash_page_write function, but I can't. The code crash when I execute the function ble_flash_page_write, therefore, I don't have any error message to give you...

    Go into the function does not help because the debugger stopped on function ble_flash_crc16_compute, but if I set a breakpoint right after, it execute successfully the ble_flash_crc16_compute function.

    I think that it crashes due to a bad memory address. The page I am tring to write is NRF_FICR->CODESIZE - 4;

    Do you have any idea or example which could inspired me?

    Best regards

Reply
  • Dear Ole Morten,

    Thanks for helping me with this problem. I am just trying to test the read/write flash page feature without success.

    Please, have a look on my answer on this thread above to see my code. Teh code is executed at the end of the main function, just before the infinity loop containing the "sd_app_event_wait" softdevice function.

    At this point, the ble stack is started and I should be able to use ble_flash_page_write function, but I can't. The code crash when I execute the function ble_flash_page_write, therefore, I don't have any error message to give you...

    Go into the function does not help because the debugger stopped on function ble_flash_crc16_compute, but if I set a breakpoint right after, it execute successfully the ble_flash_crc16_compute function.

    I think that it crashes due to a bad memory address. The page I am tring to write is NRF_FICR->CODESIZE - 4;

    Do you have any idea or example which could inspired me?

    Best regards

Children
No Data
Related