C Language Development Kit/Snippets/Flash/eraseblock

From OptiWiki

Jump to: navigation, search
Description Erase a user block from the Flash.
int eraseblock( unsigned blocknr );
unsigned blocknr
The block number in Flash that must be erased.
Returns 0 on success
Remarks Before data can be written in flash, the block in which the data must be written, must be erased first. This means that all data that was present in that entire block will be lost.
#define CHECK_STRING         "DEMO"
void store_settings_in_flash(unsigned char *settings)
    unsigned char *address;
    // Erase settings block (Do not use other block numbers!)
    // Set pointer to start of Flash section
    address = (unsigned char *)FLASH_ADDRESS;
    // Store check string in front of the settings
    programbuffer((unsigned char *)CHECK_STRING, address, strlen(CHECK_STRING));
    address += strlen(CHECK_STRING);
    // Store settings in flash (incl. string terminator)
    programbuffer(settings, address, strlen((char *)settings) + 1);
    address += strlen((char *)settings) + 1;

Personal tools