flashmem.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 <esp_attr.h>
15 #include <sming_attr.h>
16 #include <stdint.h>
17 
18 // Platform-safe typedefs for flash access, including emulation
19 typedef uintptr_t flash_addr_t;
20 typedef uint32_t flash_sector_t;
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
33 // Flash memory access must be aligned and in multiples of 4-byte words
34 #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
35 #define INTERNAL_FLASH_READ_UNIT_SIZE 4
36 
37 #define FLASH_TOTAL_SEC_COUNT (flashmem_get_size_sectors())
38 
39 /*
40 // Defined in 'flashmem.h' above
41 
42 #define INTERNAL_FLASH_SECTOR_SIZE 4096
43 #define INTERNAL_FLASH_START_ADDRESS 0x40200000
44 
45 typedef enum {
46  MODE_QIO = 0,
47  MODE_QOUT = 1,
48  MODE_DIO = 2,
49  MODE_DOUT = 15,
50  MODE_SLOW_READ = 0xFE, ///< Not supported
51  MODE_FAST_READ = 0xFF, ///< Not supported
52 } SPIFlashMode;
53 
54 typedef enum {
55  SPEED_40MHZ = 0,
56  SPEED_26MHZ = 1,
57  SPEED_20MHZ = 2,
58  SPEED_80MHZ = 15,
59 } SPIFlashSpeed;
60 
61 typedef enum {
62  SIZE_4MBIT = 0,
63  SIZE_2MBIT = 1,
64  SIZE_8MBIT = 2,
65  SIZE_16MBIT = 3,
66  SIZE_32MBIT = 4,
67  SIZE_1MBIT = 0xFF, ///< Not supported
68 } SPIFlashSize;
69 
70 */
71 
74 typedef struct {
78 } SPIFlashInfo;
79 
87 flash_addr_t flashmem_get_address(const void* memptr);
88 
96 uint32_t flashmem_write(const void* from, flash_addr_t toaddr, uint32_t size);
97 
105 uint32_t flashmem_read(void* to, flash_addr_t fromaddr, uint32_t size);
106 
112 
117 
122 
127 
132 
141 
147 
148 /*
149  * @brief Returns the address of the first free block on flash
150  * @retval uint32_t The actual address on flash
151  * @deprecated Partition tables make this function obsolete.
152  */
154 {
155  return 0;
156 }
157 
158 /*
159  * @brief Get unique 32-bit flash identification code
160  */
161 uint32_t spi_flash_get_id(void);
162 
165 #ifdef __cplusplus
166 }
167 #endif
SPIFlashSpeed
Definition: Esp32/Components/spi_flash/include/esp_spi_flash.h:38
SPIFlashMode
Definition: Esp32/Components/spi_flash/include/esp_spi_flash.h:29
SPIFlashSize
Definition: Esp32/Components/spi_flash/include/esp_spi_flash.h:45
uintptr_t flash_addr_t
Definition: flashmem.h:19
uint32_t flash_sector_t
Definition: flashmem.h:20
uint32_t spi_flash_get_id(void)
bool flashmem_erase_sector(flash_sector_t sector_id)
Erase a single flash sector.
SPIFlashInfo flashmem_get_info(void)
Get flash memory information block.
SPIFlashSize flashmem_get_size_type(void)
Returns a number indicating the size of flash memory chip.
flash_sector_t flashmem_get_size_sectors(void)
Get the total number of flash sectors.
uint32_t flashmem_read(void *to, flash_addr_t fromaddr, uint32_t size)
Read a block of data from flash.
flash_sector_t flashmem_get_sector_of_address(flash_addr_t addr)
Get sector number containing the given address.
uint32_t flashmem_write(const void *from, flash_addr_t toaddr, uint32_t size)
Write a block of data to flash.
uint32_t flashmem_get_first_free_block_address(void)
Definition: flashmem.h:153
flash_sector_t flashmem_find_sector(flash_addr_t address, flash_addr_t *pstart, flash_addr_t *pend)
Helper function: find the flash sector in which an address resides.
flash_addr_t flashmem_get_address(const void *memptr)
Obtain the flash memory address for a memory pointer.
flash_addr_t flashmem_get_size_bytes(void)
get the total flash memory size
#define SMING_DEPRECATED
Definition: sming_attr.h:37
SPI Flash memory information block.
Definition: flashmem.h:74
SPIFlashSpeed speed
Definition: flashmem.h:76
SPIFlashSize size
Definition: flashmem.h:77
SPIFlashMode mode
Definition: flashmem.h:75