Esp8266/Components/spi_flash/include/esp_spi_flash.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Based on NodeMCU platform_flash
8  * https://github.com/nodemcu/nodemcu-firmware
9  *
10  ****/
11 
12 #pragma once
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include <spi_flash.h>
19 #include <esp_attr.h>
20 
29 #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
30 #define INTERNAL_FLASH_READ_UNIT_SIZE 4
31 
32 #define FLASH_TOTAL_SEC_COUNT (flashmem_get_size_sectors())
33 
35 #define SYS_PARAM_SEC_COUNT 4
36 #define FLASH_WORK_SEC_COUNT (FLASH_TOTAL_SEC_COUNT - SYS_PARAM_SEC_COUNT)
37 
38 #define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE
39 #define INTERNAL_FLASH_SIZE ((FLASH_WORK_SEC_COUNT)*INTERNAL_FLASH_SECTOR_SIZE)
40 #define INTERNAL_FLASH_START_ADDRESS 0x40200000
41 
42 typedef enum {
43  MODE_QIO = 0,
44  MODE_QOUT = 1,
45  MODE_DIO = 2,
46  MODE_DOUT = 15,
47  MODE_SLOW_READ = 0xFE,
48  MODE_FAST_READ = 0xFF,
49 } SPIFlashMode;
50 
51 typedef enum {
57 
58 typedef enum {
64  SIZE_1MBIT = 0xFF,
65 } SPIFlashSize;
66 
70 typedef struct {
71  uint8_t unknown0;
72  uint8_t unknown1;
73  uint8_t mode : 8;
74  uint8_t speed : 4;
75  uint8_t size : 4;
77 
85 uint32_t flashmem_get_address(const void* memptr);
86 
94 uint32_t flashmem_write(const void* from, uint32_t toaddr, uint32_t size);
95 
103 uint32_t flashmem_read(void* to, uint32_t fromaddr, uint32_t size);
104 
109 bool flashmem_erase_sector(uint32_t sector_id);
110 
115 
119 uint8_t flashmem_get_size_type();
120 
124 uint32_t flashmem_get_size_bytes();
125 
129 uint16_t flashmem_get_size_sectors();
130 
138 uint32_t flashmem_find_sector(uint32_t address, uint32_t* pstart, uint32_t* pend);
139 
144 uint32_t flashmem_get_sector_of_address(uint32_t addr);
145 
153 uint32_t flashmem_write_internal(const void* from, uint32_t toaddr, uint32_t size);
154 
162 uint32_t flashmem_read_internal(void* to, uint32_t fromaddr, uint32_t size);
163 
164 /*
165  * @brief Returns the address of the first free block on flash
166  * @retval uint32_t The actual address on flash
167  */
169 
172 #ifdef __cplusplus
173 }
174 #endif
SPIFlashInfo flashmem_get_info()
Get flash memory information block.
uint32_t flashmem_read(void *to, uint32_t fromaddr, uint32_t size)
Read a block of data from flash.
SPIFlashSpeed
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:51
bool flashmem_erase_sector(uint32_t sector_id)
Erase a single flash sector.
uint8_t flashmem_get_size_type()
Returns a number indicating the size of flash memory chip.
uint32_t flashmem_write(const void *from, uint32_t toaddr, uint32_t size)
Write a block of data to flash.
uint16_t flashmem_get_size_sectors()
Get the total number of flash sectors.
SPIFlashMode
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:42
static uint32_t flashmem_get_address(const void *memptr)
Obtain the flash memory address for a memory pointer.
Definition: Esp32/Components/spi_flash/include/esp_spi_flash.h:90
SPIFlashSize
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:58
uint32_t flashmem_read_internal(void *to, uint32_t fromaddr, uint32_t size)
Read from flash memory.
uint32_t flashmem_get_sector_of_address(uint32_t addr)
Get sector number containing the given address.
uint32_t flashmem_get_size_bytes()
get the total flash memory size
uint32_t flashmem_write_internal(const void *from, uint32_t toaddr, uint32_t size)
write to flash memory
uint32_t flashmem_find_sector(uint32_t address, uint32_t *pstart, uint32_t *pend)
Helper function: find the flash sector in which an address resides.
uint32_t flashmem_get_first_free_block_address()
@ SPEED_80MHZ
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:55
@ SPEED_26MHZ
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:53
@ SPEED_20MHZ
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:54
@ SPEED_40MHZ
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:52
@ MODE_QOUT
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:44
@ MODE_FAST_READ
Not supported.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:48
@ MODE_DOUT
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:46
@ MODE_DIO
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:45
@ MODE_QIO
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:43
@ MODE_SLOW_READ
Not supported.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:47
@ SIZE_32MBIT
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:63
@ SIZE_1MBIT
Not supported.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:64
@ SIZE_16MBIT
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:62
@ SIZE_8MBIT
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:61
@ SIZE_4MBIT
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:59
@ SIZE_2MBIT
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:60
SPI Flash memory information block. Copied from bootloader header. See esp_image_header_t.
Definition: Esp32/Components/spi_flash/include/esp_spi_flash.h:77
SPI Flash memory information block. Stored at the beginning of flash memory.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:70
uint8_t unknown1
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:72
uint8_t unknown0
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:71
uint8_t size
SPIFlashSize.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:75
uint8_t speed
SPIFlashSpeed.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:74
uint8_t mode
SPIFlashMode.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:73