nRF51 SDK - S120 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Flash Manager

Module for accessing flash memory. More...

Macros

#define BLE_FLASH_PAGE_SIZE   ((uint16_t)NRF_FICR->CODEPAGESIZE)
 
#define BLE_FLASH_MAGIC_NUMBER   0x45DE0000
 
#define BLE_FLASH_EMPTY_MASK   0xFFFFFFFF
 
#define BLE_FLASH_PAGE_END
 Macro for getting the end of the flash available for application. More...
 

Functions

uint32_t ble_flash_page_write (uint8_t page_num, uint32_t *p_in_array, uint8_t word_count)
 Function for erasing the specified flash page, and then writes the given data to this page. More...
 
uint32_t ble_flash_page_read (uint8_t page_num, uint32_t *p_out_array, uint8_t *p_word_count)
 Function for reading data from flash to RAM. More...
 
uint32_t ble_flash_page_erase (uint8_t page_num)
 Function for erasing a flash page. More...
 
uint32_t ble_flash_word_write (uint32_t *p_address, uint32_t value)
 Function for writing one word to flash. More...
 
uint32_t ble_flash_block_write (uint32_t *p_address, uint32_t *p_in_array, uint16_t word_count)
 Function for writing a data block to flash. More...
 
uint32_t ble_flash_page_addr (uint8_t page_num, uint32_t **pp_page_addr)
 Function for computing pointer to start of specified flash page. More...
 
uint16_t ble_flash_crc16_compute (uint8_t *p_data, uint16_t size, uint16_t *p_crc)
 Function for calculating a 16 bit CRC using the CRC-16-CCITT scheme. More...
 
void ble_flash_on_radio_active_evt (bool radio_active)
 Function for handling flashing module Radio Notification event. More...
 

Detailed Description

Module for accessing flash memory.

It contains functions for reading, writing and erasing one page in flash.

     The module uses the first 32 bits of the flash page to write a magic number in order to
     determine if the page has been written or not.
Note
Be careful not to use a page number in the SoftDevice area (which currently occupies the range 0 to 127), or in your application space! In both cases, this would end up with a hard fault.

Macro Definition Documentation

#define BLE_FLASH_EMPTY_MASK   0xFFFFFFFF

Bit mask that defines an empty address in flash.

#define BLE_FLASH_MAGIC_NUMBER   0x45DE0000

Magic value to identify if flash contains valid data.

#define BLE_FLASH_PAGE_END
Value:
((NRF_UICR->BOOTLOADERADDR != BLE_FLASH_EMPTY_MASK) \
? (NRF_UICR->BOOTLOADERADDR / BLE_FLASH_PAGE_SIZE) \
: NRF_FICR->CODESIZE)

Macro for getting the end of the flash available for application.

The result flash page number indicates the end boundary of the flash available to the application. If a bootloader is used, the end will be the start of the bootloader region. Otherwise, the end will be the size of the flash.

#define BLE_FLASH_PAGE_SIZE   ((uint16_t)NRF_FICR->CODEPAGESIZE)

Size of one flash page.

Function Documentation

uint32_t ble_flash_block_write ( uint32_t *  p_address,
uint32_t *  p_in_array,
uint16_t  word_count 
)

Function for writing a data block to flash.

Note
Flash locations to be written must have been erased previously.
Parameters
[in]p_addressPointer to start of flash location to be written.
[in]p_in_arrayPointer to start of flash block to be written.
[in]word_countNumber of words to be written.
Returns
NRF_SUCCESS.
uint16_t ble_flash_crc16_compute ( uint8_t *  p_data,
uint16_t  size,
uint16_t *  p_crc 
)

Function for calculating a 16 bit CRC using the CRC-16-CCITT scheme.

Parameters
[in]p_dataPointer to data on which the CRC is to be calulated.
[in]sizeNumber of bytes on which the CRC is to be calulated.
[in]p_crcInitial CRC value (if NULL, a preset value is used as the initial value).
Returns
Calculated CRC.
void ble_flash_on_radio_active_evt ( bool  radio_active)

Function for handling flashing module Radio Notification event.

Note
For flash writing to work safely while in a connection or while advertising, this function MUST be called from the Radio Notification module's event handler (see Radio Notification Event Handler for details).
Parameters
[in]radio_activeTRUE if radio is active (or about to become active), FALSE otherwise.
uint32_t ble_flash_page_addr ( uint8_t  page_num,
uint32_t **  pp_page_addr 
)

Function for computing pointer to start of specified flash page.

Parameters
[in]page_numPage number.
[out]pp_page_addrPointer to start of flash page.
Returns
NRF_SUCCESS.
uint32_t ble_flash_page_erase ( uint8_t  page_num)

Function for erasing a flash page.

Note
This operation blocks the CPU, so it should not be done while the radio is running!
Parameters
[in]page_numPage number to erase.
Returns
NRF_SUCCESS on success, an error_code otherwise.
uint32_t ble_flash_page_read ( uint8_t  page_num,
uint32_t *  p_out_array,
uint8_t *  p_word_count 
)

Function for reading data from flash to RAM.

Parameters
[in]page_numPage number to read.
[out]p_out_arrayPointer to a RAM area where the found data will be written. This area has to be 32 bits aligned.
[out]p_word_countNumber of 32 bits words read.
Returns
NRF_SUCCESS on successful upload, NRF_ERROR_NOT_FOUND if no valid data has been found in flash (first 32 bits not equal to the MAGIC_NUMBER+CRC).
uint32_t ble_flash_page_write ( uint8_t  page_num,
uint32_t *  p_in_array,
uint8_t  word_count 
)

Function for erasing the specified flash page, and then writes the given data to this page.

Warning
This operation blocks the CPU. DO NOT use while in a connection!
Parameters
[in]page_numPage number to update.
[in]p_in_arrayPointer to a RAM area containing the elements to write in flash. This area has to be 32 bits aligned.
[in]word_countNumber of 32 bits words to write in flash.
Returns
NRF_SUCCESS on successful flash write, otherwise an error code.
uint32_t ble_flash_word_write ( uint32_t *  p_address,
uint32_t  value 
)

Function for writing one word to flash.

Note
Flash location to be written must have been erased previously.
Parameters
[in]p_addressPointer to flash location to be written.
[in]valueValue to write to flash.
Returns
NRF_SUCCESS.