Esp32/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 #include_next <esp_spi_flash.h>
15 #include <esp32/rom/spi_flash.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <user_config.h>
22 
30 #define SPI_FLASH_RESULT_OK 0
31 
33 #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
34 #define INTERNAL_FLASH_READ_UNIT_SIZE 4
35 
36 #define FLASH_TOTAL_SEC_COUNT (flashmem_get_size_sectors())
37 
39 #define SYS_PARAM_SEC_COUNT 4
40 #define FLASH_WORK_SEC_COUNT (FLASH_TOTAL_SEC_COUNT - SYS_PARAM_SEC_COUNT)
41 
42 #define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE
43 #define INTERNAL_FLASH_SIZE ((FLASH_WORK_SEC_COUNT)*INTERNAL_FLASH_SECTOR_SIZE)
44 #define INTERNAL_FLASH_START_ADDRESS 0x40200000
45 
49 typedef struct
50 {
51  uint8_t unknown0;
52  uint8_t unknown1;
53  enum
54  {
55  MODE_QIO = 0,
56  MODE_QOUT = 1,
57  MODE_DIO = 2,
58  MODE_DOUT = 15,
59  } mode : 8;
60  enum
61  {
62  SPEED_40MHZ = 0,
63  SPEED_26MHZ = 1,
64  SPEED_20MHZ = 2,
65  SPEED_80MHZ = 15,
66  } speed : 4;
67  enum
68  {
69  SIZE_4MBIT = 0,
70  SIZE_2MBIT = 1,
71  SIZE_8MBIT = 2,
72  SIZE_16MBIT = 3,
73  SIZE_32MBIT = 4,
74  } size : 4;
75 } STORE_TYPEDEF_ATTR SPIFlashInfo;
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.
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.
SPI Flash memory information block. Stored at the beginning of flash memory.
Definition: Esp8266/Components/spi_flash/include/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.
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.