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

Committer:
bosko1523
Date:
Sun Jan 15 20:37:39 2017 +0000
Revision:
0:0414cef3e9d6
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.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko1523 0:0414cef3e9d6 1 #ifndef _FLASH_H_MB_
bosko1523 0:0414cef3e9d6 2 #define _FLASH_H_MB_
bosko1523 0:0414cef3e9d6 3
bosko1523 0:0414cef3e9d6 4 #include "mbed.h"
bosko1523 0:0414cef3e9d6 5 #include "IAP.h"
bosko1523 0:0414cef3e9d6 6
bosko1523 0:0414cef3e9d6 7 // Data for NXP LPC1768 from data table which is explained in datasheet UM10360 page 626.
bosko1523 0:0414cef3e9d6 8 #define MEM_SIZE 256
bosko1523 0:0414cef3e9d6 9 #define TARGET_SECTOR 29
bosko1523 0:0414cef3e9d6 10
bosko1523 0:0414cef3e9d6 11 /** This is simple library for storing data to flash memory and
bosko1523 0:0414cef3e9d6 12 * reading it. This allows us to have retain data without having to have
bosko1523 0:0414cef3e9d6 13 * external flash chip. This class uses NXP LPC1768 internal flash memory
bosko1523 0:0414cef3e9d6 14 * which give us 256B of flash size.
bosko1523 0:0414cef3e9d6 15 *
bosko1523 0:0414cef3e9d6 16 * Author: TVZ Mechatronics Team
bosko1523 0:0414cef3e9d6 17 *
bosko1523 0:0414cef3e9d6 18 * Example of use:
bosko1523 0:0414cef3e9d6 19 * @code
bosko1523 0:0414cef3e9d6 20 * #include "mbed.h"
bosko1523 0:0414cef3e9d6 21 * #include "Flash.h"
bosko1523 0:0414cef3e9d6 22 *
bosko1523 0:0414cef3e9d6 23 * BusOut display(LED1, LED2, LED3, LED4);
bosko1523 0:0414cef3e9d6 24 * InterruptIn cntUp(p5);
bosko1523 0:0414cef3e9d6 25 * Timer debounceUp;
bosko1523 0:0414cef3e9d6 26 * Flash flash;
bosko1523 0:0414cef3e9d6 27 *
bosko1523 0:0414cef3e9d6 28 * char retainData[MEM_SIZE];
bosko1523 0:0414cef3e9d6 29 * uint8_t counter;
bosko1523 0:0414cef3e9d6 30 *
bosko1523 0:0414cef3e9d6 31 * void countUp(void) {
bosko1523 0:0414cef3e9d6 32 * if (debounceUp.read_ms() > 500) {
bosko1523 0:0414cef3e9d6 33 * if (counter > 15)
bosko1523 0:0414cef3e9d6 34 * counter = 0;
bosko1523 0:0414cef3e9d6 35 * else
bosko1523 0:0414cef3e9d6 36 * counter++;
bosko1523 0:0414cef3e9d6 37 *
bosko1523 0:0414cef3e9d6 38 * retainData[0] = counter;
bosko1523 0:0414cef3e9d6 39 * flash.writeFlash(retainData);
bosko1523 0:0414cef3e9d6 40 *
bosko1523 0:0414cef3e9d6 41 * debounceUp.reset();
bosko1523 0:0414cef3e9d6 42 * }
bosko1523 0:0414cef3e9d6 43 * }
bosko1523 0:0414cef3e9d6 44 *
bosko1523 0:0414cef3e9d6 45 * int main() {
bosko1523 0:0414cef3e9d6 46 * cntUp.rise(&countUp);
bosko1523 0:0414cef3e9d6 47 * debounceUp.start();
bosko1523 0:0414cef3e9d6 48 *
bosko1523 0:0414cef3e9d6 49 * flash.readFlash(retainData);
bosko1523 0:0414cef3e9d6 50 * counter = retainData[0];
bosko1523 0:0414cef3e9d6 51 *
bosko1523 0:0414cef3e9d6 52 * while(1) {
bosko1523 0:0414cef3e9d6 53 * display = counter;
bosko1523 0:0414cef3e9d6 54 * }
bosko1523 0:0414cef3e9d6 55 * }
bosko1523 0:0414cef3e9d6 56 * @endcode
bosko1523 0:0414cef3e9d6 57 */
bosko1523 0:0414cef3e9d6 58 class Flash {
bosko1523 0:0414cef3e9d6 59 public:
bosko1523 0:0414cef3e9d6 60 /** Constructor */
bosko1523 0:0414cef3e9d6 61 Flash();
bosko1523 0:0414cef3e9d6 62 /** Function recevies data array wich is stored in flash memory */
bosko1523 0:0414cef3e9d6 63 void writeFlash(char data[MEM_SIZE]);
bosko1523 0:0414cef3e9d6 64 /** Function returning data to pointer to array of size 256 wich is stored in flash memory */
bosko1523 0:0414cef3e9d6 65 void readFlash(char *data);
bosko1523 0:0414cef3e9d6 66 private:
bosko1523 0:0414cef3e9d6 67 IAP iap;
bosko1523 0:0414cef3e9d6 68 };
bosko1523 0:0414cef3e9d6 69
bosko1523 0:0414cef3e9d6 70 #endif