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

Flash write

Hello,

I'm trying to write value to a specified address with ble_flash_page_write .

I'm using ble_flash_page_write after ble disconnect event. I've tested different page address to be sure i'm not writing on application or s110 areas and page address are multiples of 4.

At execution, an Hard fault occur at the ble_flash_page_write line... Any idea about this error ? Is there others solutions to write values to a precise flash address ?

int32_t page = 200;
uint8_t word_count = 1;
uint32_t data_array[2]={0x81ABACAB};
data_array[1] = 0x81ABACAB;
		
err_code = ble_flash_page_write(page,(uint32_t *) &data_array,1);
APP_ERROR_CHECK(err_code);
  • Hi Thomas,

    Are you calling ble_flash_page_write() when you are in a connection (connected to a peer)? That could be a reason for hardfault. You can either call this API when not in a connection (if that suits your usecase). Or you can use the API ble_flash_word_write instead. (This assumes that the Flash location to be written has been erased previously)

    It is recommended that you use the 'Persistent Storage Interface' (pstorage.h) instead of the 'Flash Manager' (ble_flash.h) to perform flash related operations. It has been added to the nRF51 SDK sicne version 5.0.0. It helps in handling asynchronous flash memory access without the application needing to know whether the radio is active (connected to the peer).

    Cheers, Balaji

  • i'm calling ble_flash_page_write() just after the ble disconnect event and before to start advertisment.

    I tried to use pstorage manager, but don't understand how to specify exactly were i want to write (i need to read this value from the bootloader or an external flasher..). Raw mode seems to be appropriate but i don't find documentation about this, just last lines of the pstorage lib documentation. https://devzone.nordicsemi.com/documentation/nrf51/5.1.0/html/a00131.html

  • Hi Thomas,

    You should know that ble_flash module cannot be used when SoftDevice is enabled. This was done post SoftDevice 6.0.0 release, when flash access was offered as a part of SoftDevice functionality.

    Also, in case you need the address, in pstorage block_id of pstorage_handle_t contains actual flash access. Accessing the flash access yourself is not recommended for typical use cases.

    In case you do want to access all flash yourself, raw mode is appropriate. In this case, you need follow the following steps: a. Initilaize pstorage using pstorage_init(); b. Register the application in raw mode using the pstorage_raw_register() with appropriate parameters. You will provided a handle here. The module id in this handle identifies your application. Block id of the handle can be manipulated to any flash access to desire to access subsequently. c. Assign block_id field of the handle to an appropriate word aligned flash address (not page number). And call pstorage_raw_store. Do ensure that your source data lies in resident memory as flash access is no longer blocking.

    For an example usage of raw mode, you can look at the boot-loader included in the SDK. This is the only application using raw mode.

    Hope this helps!

    Regards, Krishna

  • Thanks for response ,

    And for you , what is the best solution to share values between the main app and the bootloader (like a flag) ? The Raw mode ?

    Regards,

    Thomas

  • Hi Thomas,

    To give you an example, lets say you want to share bond information from application to boot-loader. Then this is what can be done:

    a. Ensure that pstorage_platform file has been provided with same start address. Number of applications and end address could be adjusted if you need more persistent memory in boot-loader mode. b. Register bond related blocks in same order as in application mode once pstorage has been initialized.

    If this is done, and your bootloader is not overriding or clearing any of flash pages reserved for storing data persistently, you should be able to share information from application to bootloader.

    Regards, Krishna

Related