C Language Development Kit/Snippets/Flash/programbuffer

From OptiWiki

Jump to: navigation, search
Description Programs a buffer into a user block of the Flash.
void programbuffer( unsigned char *buffer, unsigned char *target_address, int len);
unsigned char *buffer
The buffer that must be stored in Flash.
unsigned char *target_address
The block in Flash where the buffer must go to.
int len
The size of the block to be stored.
Returns None
Remarks Before data can be written in flash the block must be erased first.
#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