This is library for storing data array in internal flash memory of MCU LPC1768. The flash data is empty every time we download program to MCU so it can be used in project where we don't have acces to file system like mbed development board uses.

Dependencies:   IAP

Dependents:   Flash_Example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Flash.h Source File

Flash.h

00001 #ifndef _FLASH_H_MB_
00002 #define _FLASH_H_MB_
00003 
00004 #include "mbed.h"
00005 #include "IAP.h"
00006 
00007 // Data for NXP LPC1768 from data table which is explained in datasheet UM10360 page 626.
00008 #define MEM_SIZE 256
00009 #define TARGET_SECTOR 29
00010 
00011 /** This is simple library for storing data to flash memory and
00012  * reading it. This allows us to have retain data without having to have  
00013  * external flash chip. This class uses NXP LPC1768 internal flash memory
00014  * which give us 256B of flash size.
00015  * 
00016  * Author: TVZ Mechatronics Team
00017  *
00018  * Example of use:
00019  * @code
00020  * #include "mbed.h"
00021  * #include "Flash.h"
00022  *
00023  * BusOut display(LED1, LED2, LED3, LED4);
00024  * InterruptIn cntUp(p5);
00025  * Timer debounceUp;
00026  * Flash flash;
00027  *
00028  * char retainData[MEM_SIZE];
00029  * uint8_t counter;
00030  *
00031  * void countUp(void) {
00032  *    if (debounceUp.read_ms() > 500) {
00033  *        if (counter > 15)
00034  *            counter = 0;
00035  *        else
00036  *            counter++;
00037  *            
00038  *        retainData[0] = counter;
00039  *        flash.writeFlash(retainData);
00040  *        
00041  *        debounceUp.reset();
00042  *    }
00043  * }
00044  * 
00045  * int main() {
00046  *    cntUp.rise(&countUp);
00047  *    debounceUp.start();
00048  *
00049  *    flash.readFlash(retainData);
00050  *    counter = retainData[0];
00051  *
00052  *    while(1) {
00053  *        display = counter;
00054  *    }
00055  * }
00056  * @endcode
00057  */
00058 class Flash {
00059     public:
00060         /** Constructor */
00061         Flash();
00062         /** Function recevies data array wich is stored in flash memory */
00063         void writeFlash(char data[MEM_SIZE]);
00064         /** Function returning data to pointer to array of size 256 wich is stored in flash memory */
00065         void readFlash(char *data);
00066     private:
00067         IAP iap;
00068 };
00069 
00070 #endif