forked from sebnil/DueFlashStorage
-
Notifications
You must be signed in to change notification settings - Fork 4
/
DueFlashStorage.h
executable file
·56 lines (42 loc) · 1.63 KB
/
DueFlashStorage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
DueFlashStorage saves non-volatile data for Arduino Due.
But, it has been modified for use as a firmware writer
Note: uploading new software will erase all flash so data written to flash
using this library will not survive a new software upload.
Inspiration from Pansenti at https://github.com/Pansenti/DueFlash
Rewritten and modified by Sebastian Nilsson
Further modified by Collin Kidder so that it can easily
write firmware to either flash block
*/
#ifndef DUEFLASHSTORAGE_H
#define DUEFLASHSTORAGE_H
#include <Arduino.h>
#include "flash_efc.h"
#include "efc.h"
// 1Kb of data
#define DATA_LENGTH ((IFLASH1_PAGE_SIZE/sizeof(byte))*4)
// choose a start address that's offset to show that it doesn't have to be on a page boundary
#define FLASH_START ((byte *)IFLASH0_ADDR)
// FLASH_DEBUG can be enabled to get debugging information displayed.
#define FLASH_DEBUG
#ifdef FLASH_DEBUG
#define _FLASH_DEBUG(x) SerialUSB.print(x);
#else
#define _FLASH_DEBUG(x)
#endif
// DueFlash is the main class for flash functions
class DueFlashStorage {
public:
DueFlashStorage();
// write() writes the specified amount of data into flash.
// flashStart is the address in memory where the write should start
// data is a pointer to the data to be written
// dataLength is length of data in bytes
byte read(uint32_t address, int block);
byte* readAddress(uint32_t address, int block);
boolean write(uint32_t address, byte value, int block);
boolean write(uint32_t address, byte *data, uint32_t dataLength, int block);
bool getGPNVMBootMode(); //true = boot from FLASH1, false = boot from FLASH0
void setGPNVMBootMode(bool mode);
};
#endif