ESP8266
flash_utils.h
1 /*
2  flash_utils.h - Flash access function and data structures
3  Copyright (c) 2015 Ivan Grokhotkov. All right reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 
21 #ifndef FLASH_UTILS_H
22 #define FLASH_UTILS_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 int SPIEraseBlock(uint32_t block);
29 int SPIEraseSector(uint32_t sector);
30 int SPIRead(uint32_t addr, void *dest, size_t size);
31 int SPIWrite(uint32_t addr, void *src, size_t size);
32 int SPIEraseAreaEx(const uint32_t start, const uint32_t size);
33 
34 #define FLASH_SECTOR_SIZE 0x1000
35 #define FLASH_BLOCK_SIZE 0x10000
36 #define APP_START_OFFSET 0x1000
37 
38 typedef struct {
39  unsigned char magic;
40  unsigned char num_segments;
41 
42  /* SPI Flash Interface (0 = QIO, 1 = QOUT, 2 = DIO, 0x3 = DOUT) */
43  unsigned char flash_mode;
44 
45  /* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M,
46  Low four bits: 0 = 40MHz, 1= 26MHz, 2 = 20MHz, 0xf = 80MHz */
47  unsigned char flash_size_freq;
48 
49  uint32_t entry;
51 
52 
53 typedef struct {
54  uint32_t address;
55  uint32_t size;
57 
58 #ifdef __cplusplus
59 }
60 #endif
61 
62 
63 #endif //FLASH_UTILS_H
uint32_t size
Definition: flash_utils.h:55
unsigned char flash_size_freq
Definition: flash_utils.h:47
unsigned char flash_mode
Definition: flash_utils.h:43
Definition: flash_utils.h:53
unsigned char num_segments
Definition: flash_utils.h:40
Definition: flash_utils.h:38
uint32_t entry
Definition: flash_utils.h:49
unsigned char magic
Definition: flash_utils.h:39
uint32_t address
Definition: flash_utils.h:54