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 <user_config.h>
19 
27 #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
29 #define INTERNAL_FLASH_READ_UNIT_SIZE 4
30 
31 #define FLASH_TOTAL_SEC_COUNT (flashmem_get_size_sectors())
32 
34 #define SYS_PARAM_SEC_COUNT 4
35 #define FLASH_WORK_SEC_COUNT (FLASH_TOTAL_SEC_COUNT - SYS_PARAM_SEC_COUNT)
36 
37 #define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE
38 #define INTERNAL_FLASH_SIZE ((FLASH_WORK_SEC_COUNT)*INTERNAL_FLASH_SECTOR_SIZE)
39 #define INTERNAL_FLASH_START_ADDRESS FLASH_BASE
40 
41 typedef enum {
42  MODE_QIO = 0,
43  MODE_QOUT = 1,
44  MODE_DIO = 2,
45  MODE_DOUT = 15,
46  MODE_SLOW_READ = 0xFE,
47  MODE_FAST_READ = 0xFF,
48 } SPIFlashMode;
49 
50 typedef enum {
56 
57 typedef enum {
63  SIZE_1MBIT = 0xFF,
64 } SPIFlashSize;
65 
69 typedef struct {
70  uint8_t unknown0;
71  uint8_t unknown1;
72  uint8_t mode : 8;
73  uint8_t speed : 4;
74  uint8_t size : 4;
76 
84 uint32_t flashmem_get_address(const void* memptr);
85 
93 uint32_t flashmem_write(const void* from, uint32_t toaddr, uint32_t size);
94 
102 uint32_t flashmem_read(void* to, uint32_t fromaddr, uint32_t size);
103 
108 bool flashmem_erase_sector(uint32_t sector_id);
109 
113 SPIFlashInfo flashmem_get_info();
114 
118 uint8_t flashmem_get_size_type();
119 
123 uint32_t flashmem_get_size_bytes();
124 
129 
137 uint32_t flashmem_find_sector(uint32_t address, uint32_t* pstart, uint32_t* pend);
138 
143 uint32_t flashmem_get_sector_of_address(uint32_t addr);
144 
152 uint32_t flashmem_write_internal(const void* from, uint32_t toaddr, uint32_t size);
153 
161 uint32_t flashmem_read_internal(void* to, uint32_t fromaddr, uint32_t size);
162 
163 /*
164  * @brief Returns the address of the first free block on flash
165  * @retval uint32_t The actual address on flash
166  */
168 
171 #ifdef __cplusplus
172 }
173 #endif
SPIFlashInfo flashmem_get_info()
Get flash memory information block.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:58
uint8_t size
SPIFlashSize.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:74
Not supported.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:47
uint32_t flashmem_get_size_bytes()
get the total flash memory size
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:59
uint8_t speed
SPIFlashSpeed.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:73
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:44
uint8_t mode
SPIFlashMode.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:72
Not supported.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:63
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:45
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:51
uint8_t flashmem_get_size_type()
Returns a number indicating the size of flash memory chip.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:54
uint16_t flashmem_get_size_sectors()
Get the total number of flash sectors.
uint32_t flashmem_get_address(const void *memptr)
Obtain the flash memory address for a memory pointer.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:52
SPIFlashSize
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:57
uint8_t unknown1
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:71
SPI Flash memory information block. Stored at the beginning of flash memory.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:69
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:42
uint32_t flashmem_write_internal(const void *from, uint32_t toaddr, uint32_t size)
write to flash memory
bool flashmem_erase_sector(uint32_t sector_id)
Erase a single flash sector.
Not supported.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:46
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:62
uint32_t flashmem_read_internal(void *to, uint32_t fromaddr, uint32_t size)
Read from flash memory.
uint8_t unknown0
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:70
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:61
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.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:60
SPIFlashMode
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:41
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:53
SPIFlashSpeed
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:50
uint32_t flashmem_write(const void *from, uint32_t toaddr, uint32_t size)
Write a block of data to flash.
SPI Flash memory information block. Copied from bootloader header. See esp_image_header_t.
Definition: Esp32/Components/spi_flash/include/esp_spi_flash.h:76
uint32_t flashmem_get_sector_of_address(uint32_t addr)
Get sector number containing the given address.
Definition: Esp8266/Components/spi_flash/include/esp_spi_flash.h:43
uint32_t flashmem_get_first_free_block_address()
uint32_t flashmem_read(void *to, uint32_t fromaddr, uint32_t size)
Read a block of data from flash.