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 0x40200000
40 
44 typedef struct
45 {
46  uint8_t unknown0;
47  uint8_t unknown1;
48  enum
49  {
50  MODE_QIO = 0,
51  MODE_QOUT = 1,
52  MODE_DIO = 2,
53  MODE_DOUT = 15,
54  } mode : 8;
55  enum
56  {
57  SPEED_40MHZ = 0,
58  SPEED_26MHZ = 1,
59  SPEED_20MHZ = 2,
60  SPEED_80MHZ = 15,
61  } speed : 4;
62  enum
63  {
64  SIZE_4MBIT = 0,
65  SIZE_2MBIT = 1,
66  SIZE_8MBIT = 2,
67  SIZE_16MBIT = 3,
68  SIZE_32MBIT = 4,
69  } size : 4;
70 } STORE_TYPEDEF_ATTR SPIFlashInfo;
71 
79 uint32_t flashmem_get_address(const void* memptr);
80 
88 uint32_t flashmem_write(const void* from, uint32_t toaddr, uint32_t size);
89 
97 uint32_t flashmem_read(void* to, uint32_t fromaddr, uint32_t size);
98 
103 bool flashmem_erase_sector(uint32_t sector_id);
104 
108 SPIFlashInfo flashmem_get_info();
109 
113 uint8_t flashmem_get_size_type();
114 
118 uint32_t flashmem_get_size_bytes();
119 
124 
132 uint32_t flashmem_find_sector(uint32_t address, uint32_t* pstart, uint32_t* pend);
133 
138 uint32_t flashmem_get_sector_of_address(uint32_t addr);
139 
147 uint32_t flashmem_write_internal(const void* from, uint32_t toaddr, uint32_t size);
148 
156 uint32_t flashmem_read_internal(void* to, uint32_t fromaddr, uint32_t size);
157 
158 /*
159  * @brief Returns the address of the first free block on flash
160  * @retval uint32_t The actual address on flash
161  */
163 
166 #ifdef __cplusplus
167 }
168 #endif
SPIFlashInfo flashmem_get_info()
Get flash memory information block.
uint32_t flashmem_get_size_bytes()
get the total flash memory size
uint8_t flashmem_get_size_type()
Returns a number indicating the size of flash memory chip.
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.
uint8_t unknown1
Definition: esp_spi_flash.h:47
SPI Flash memory information block. Stored at the beginning of flash memory.
Definition: esp_spi_flash.h:44
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.
uint32_t flashmem_read_internal(void *to, uint32_t fromaddr, uint32_t size)
Read from flash memory.
uint8_t unknown0
Definition: esp_spi_flash.h:46
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_write(const void *from, uint32_t toaddr, uint32_t size)
Write a block of data to flash.
uint32_t flashmem_get_sector_of_address(uint32_t addr)
Get sector number containing the given address.
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.