From a93e62c44431b223a27fa8ad237b9c168d995b25 Mon Sep 17 00:00:00 2001 From: HuangRui Date: Wed, 31 Dec 2014 08:08:31 +0800 Subject: [PATCH 1/9] Add node.flashid() and node.flashsize(). --- app/modules/node.c | 29 +++++++ app/platform/flash_api.c | 167 ++++++++++++++++++++++++++++++++++++++- app/platform/flash_api.h | 14 +++- 3 files changed, 205 insertions(+), 5 deletions(-) diff --git a/app/modules/node.c b/app/modules/node.c index 94b2f7a1..3c7a41b2 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -11,6 +11,8 @@ #include "romfs.h" #include "c_string.h" #include "driver/uart.h" +#include "spi_flash.h" +#include "flash_api.h" // Lua: restart() static int ICACHE_FLASH_ATTR node_restart( lua_State* L ) @@ -38,6 +40,31 @@ static int ICACHE_FLASH_ATTR node_chipid( lua_State* L ) return 1; } +// Lua: flashid() +static int ICACHE_FLASH_ATTR node_flashid( lua_State* L ) +{ + uint32_t id = spi_flash_get_id(); + lua_pushinteger( L, id ); + return 1; +} + +// Lua: flashsize() +static int ICACHE_FLASH_ATTR node_flashsize( lua_State* L ) +{ + //uint32_t sz = 0; + //if(lua_type(L, 1) == LUA_TNUMBER) + //{ + // sz = luaL_checkinteger(L, 1); + // if(sz > 0) + // { + // flash_set_size_byte(sz); + // } + //} + uint32_t sz = flash_get_size_byte(); + lua_pushinteger( L, sz ); + return 1; +} + // Lua: heap() static int ICACHE_FLASH_ATTR node_heap( lua_State* L ) { @@ -238,6 +265,8 @@ const LUA_REG_TYPE node_map[] = { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) }, { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) }, + { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) }, + { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) }, { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) }, { LSTRKEY( "key" ), LFUNCVAL( node_key ) }, { LSTRKEY( "led" ), LFUNCVAL( node_led ) }, diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index a99a77df..1620c7c5 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -1,12 +1,16 @@ /****************************************************************************** * Flash api for NodeMCU + * NodeMCU Team + * 2014-12-31 *******************************************************************************/ #include "user_config.h" #include "flash_api.h" #include "spi_flash.h" +#include "c_stdio.h" + SPIFlashInfo *ICACHE_FLASH_ATTR -flash_get_info() +flash_get_info(void) { static SPIFlashInfo spi_flash_info; static bool is_spi_flash_info_initialized = false; @@ -19,8 +23,15 @@ flash_get_info() return &spi_flash_info; } +uint8_t ICACHE_FLASH_ATTR +flash_get_size(void) +{ + SPIFlashInfo *p_spi_flash_info = flash_get_info(); + return p_spi_flash_info->size; +} + uint32_t ICACHE_FLASH_ATTR -flash_get_size_byte() +flash_get_size_byte(void) { static uint32_t flash_size = 0; // Make the code more fast @@ -58,8 +69,69 @@ flash_get_size_byte() return flash_size; } +bool ICACHE_FLASH_ATTR +flash_set_size(uint8_t size) +{ + // Dangerous, here are dinosaur infested!!!!! + // Reboot required!!! + // If you don't know what you're doing, your nodemcu may turn into stone ... + c_printf("\nSet size!!! %d\n", size); + uint8_t data[SPI_FLASH_SEC_SIZE]; + SPIRead(0, data, sizeof(data)); + SPIFlashInfo *p_spi_flash_info = (SPIFlashInfo *)(data); + p_spi_flash_info->size = size; + SPIEraseSector(0); + SPIWrite(data, 0, sizeof(data)); + //p_spi_flash_info = flash_get_info(); + //p_spi_flash_info->size = size; + return true; +} + +bool ICACHE_FLASH_ATTR +flash_set_size_byte(uint32_t size) +{ + // Dangerous, here are dinosaur infested!!!!! + // Reboot required!!! + // If you don't know what you're doing, your nodemcu may turn into stone ... + bool result = true; + uint32_t flash_size = 0; + switch (size) + { + case 256 * 1024: + // 2Mbit, 256kByte + flash_size = SIZE_2MBIT; + flash_set_size(flash_size); + break; + case 512 * 1024: + // 4Mbit, 512kByte + flash_size = SIZE_4MBIT; + flash_set_size(flash_size); + break; + case 1 * 1024 * 1024: + // 8Mbit, 1MByte + flash_size = SIZE_8MBIT; + flash_set_size(flash_size); + break; + case 2 * 1024 * 1024: + // 16Mbit, 2MByte + flash_size = SIZE_16MBIT; + flash_set_size(flash_size); + break; + case 4 * 1024 * 1024: + // 32Mbit, 4MByte + flash_size = SIZE_32MBIT; + flash_set_size(flash_size); + break; + default: + // Unknown flash size. + result = false; + break; + } + return result; +} + uint16_t ICACHE_FLASH_ATTR -flash_get_sec_num() +flash_get_sec_num(void) { static uint16_t result = 0; // Make the code more fast @@ -69,3 +141,92 @@ flash_get_sec_num() } return result; } + +uint8_t ICACHE_FLASH_ATTR +flash_get_mode(void) +{ + SPIFlashInfo *p_spi_flash_info = flash_get_info(); + switch (p_spi_flash_info->mode) + { + // Reserved for future use + case MODE_QIO: + break; + case MODE_QOUT: + break; + case MODE_DIO: + break; + case MODE_DOUT: + break; + } + return p_spi_flash_info->mode; +} + +uint32_t ICACHE_FLASH_ATTR +flash_get_speed(void) +{ + uint32_t speed = 0; + SPIFlashInfo *p_spi_flash_info = flash_get_info(); + switch (p_spi_flash_info->speed) + { + case SPEED_40MHZ: + // 40MHz + speed = 40000000; + break; + case SPEED_26MHZ: + //26.7MHz + speed = 26700000; + break; + case SPEED_20MHZ: + // 20MHz + speed = 20000000; + break; + case SPEED_80MHZ: + //80MHz + speed = 80000000; + break; + } + return speed; +} + +bool ICACHE_FLASH_ATTR +flash_init_data_default(void) +{ + // FLASH SEC - 4 + // Dangerous, here are dinosaur infested!!!!! + // Reboot required!!! + // It will init system data to default! + uint8_t flash_init_data[128] = + { + 0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05, + 0x04, 0xFE, 0xFD, 0xFF, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE1, 0x0A, 0xFF, 0xFF, 0xF8, 0x00, + 0xF8, 0xF8, 0x52, 0x4E, 0x4A, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE1, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + SPIEraseSector((flash_get_sec_num() - 4)); + SPIWrite((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, flash_init_data, sizeof(flash_init_data)); + return true; +} + +bool ICACHE_FLASH_ATTR +flash_init_data_blank(void) +{ + // FLASH SEC - 2 + // Dangerous, here are dinosaur infested!!!!! + // Reboot required!!! + // It will init system config to blank! + SPIEraseSector((flash_get_sec_num() - 2)); + SPIEraseSector((flash_get_sec_num() - 1)); + return true; +} + +bool ICACHE_FLASH_ATTR +flash_self_destruct(void) +{ + // Erase your flash. Good bye! + SPIEraseChip(); + return true; +} \ No newline at end of file diff --git a/app/platform/flash_api.h b/app/platform/flash_api.h index 8ff2b455..5642562f 100644 --- a/app/platform/flash_api.h +++ b/app/platform/flash_api.h @@ -29,6 +29,16 @@ typedef struct __attribute__((packed)) } size : 4; } SPIFlashInfo; -uint32_t flash_get_size_byte(); -uint16_t flash_get_sec_num(); +SPIFlashInfo *flash_get_info(void); +uint8_t flash_get_size(void); +uint32_t flash_get_size_byte(void); +bool flash_set_size(uint8_t); +bool flash_set_size_byte(uint32_t); +uint16_t flash_get_sec_num(void); +uint8_t flash_get_mode(void); +uint32_t flash_get_speed(void); +bool flash_init_data_default(void); +bool flash_init_data_blank(void); +bool flash_self_destruct(void); + #endif // __FLASH_API_H__ From eb27c4fb2744b18dc6d0044f27a19d415e35d38d Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 31 Dec 2014 12:19:53 +0800 Subject: [PATCH 2/9] fix a uart readline bug, which echo 2 CR+LF mistakenly --- app/lua/lua.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/lua/lua.c b/app/lua/lua.c index 13c6f541..a803a306 100644 --- a/app/lua/lua.c +++ b/app/lua/lua.c @@ -645,6 +645,7 @@ void ICACHE_FLASH_ATTR readline(lua_Load *load){ os_timer_setfn(&lua_timer, (os_timer_func_t *)dojob, load); os_timer_arm(&lua_timer, READLINE_INTERVAL, 0); // no repeat } + continue; } /* other control character or not an acsii character */ From 2553795b1e01e784a37a9d99b2efb0948ee636ea Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 31 Dec 2014 13:53:26 +0800 Subject: [PATCH 3/9] add file.read() api, read(n) will read n byte. --- app/modules/file.c | 47 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/app/modules/file.c b/app/modules/file.c index 9edc6fd5..760877d6 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -152,9 +152,15 @@ static int ICACHE_FLASH_ATTR file_check( lua_State* L ) #endif -// Lua: readline() -static int ICACHE_FLASH_ATTR file_readline( lua_State* L ) +// g_read() +static int ICACHE_FLASH_ATTR file_g_read( lua_State* L, int n, int16_t end_char ) { + if(n< 0 || n>LUAL_BUFFERSIZE) + n = LUAL_BUFFERSIZE; + if(end_char < 0 || end_char >255) + end_char = EOF; + signed char ec = (signed char)end_char; + luaL_Buffer b; if((FS_OPEN_OK - 1)==file_fd) return luaL_error(L, "open a file first"); @@ -170,7 +176,7 @@ static int ICACHE_FLASH_ATTR file_readline( lua_State* L ) break; } p[i++] = c; - }while((c!=EOF) && (c!='\n') && (i0 && p[i-1] == '\n') @@ -187,6 +193,40 @@ static int ICACHE_FLASH_ATTR file_readline( lua_State* L ) return 1; /* read at least an `eol' */ } +// Lua: read() +// file.read() will read all byte in file +// file.read(10) will read 10 byte from file, or EOF is reached. +// file.read('q') will read until 'q' or EOF is reached. +static int ICACHE_FLASH_ATTR file_read( lua_State* L ) +{ + unsigned need_len = LUAL_BUFFERSIZE; + int16_t end_char = EOF; + size_t el; + if( lua_type( L, 1 ) == LUA_TNUMBER ) + { + need_len = ( unsigned )luaL_checkinteger( L, 1 ); + if( need_len > LUAL_BUFFERSIZE ){ + need_len = LUAL_BUFFERSIZE; + } + } + else if(lua_isstring(L, 1)) + { + const char *end = luaL_checklstring( L, 1, &el ); + if(el!=1){ + return luaL_error( L, "wrong arg range" ); + } + end_char = (int16_t)end[0]; + } + + return file_g_read(L, need_len, end_char); +} + +// Lua: readline() +static int ICACHE_FLASH_ATTR file_readline( lua_State* L ) +{ + return file_g_read(L, LUAL_BUFFERSIZE, '\n'); +} + // Lua: write("string") static int ICACHE_FLASH_ATTR file_write( lua_State* L ) { @@ -233,6 +273,7 @@ const LUA_REG_TYPE file_map[] = { LSTRKEY( "close" ), LFUNCVAL( file_close ) }, { LSTRKEY( "write" ), LFUNCVAL( file_write ) }, { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) }, + { LSTRKEY( "read" ), LFUNCVAL( file_read ) }, { LSTRKEY( "readline" ), LFUNCVAL( file_readline ) }, #if defined(BUILD_WOFS) { LSTRKEY( "format" ), LFUNCVAL( file_format ) }, From 04a5e674438132e2190a7cd281df09a510dac8a8 Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 31 Dec 2014 14:26:51 +0800 Subject: [PATCH 4/9] add node.info() to get version, chipid, flash info --- app/include/user_config.h | 5 +++++ app/modules/node.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/include/user_config.h b/app/include/user_config.h index a9c75301..ddff4cc1 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -1,6 +1,11 @@ #ifndef __USER_CONFIG_H__ #define __USER_CONFIG_H__ +#define NODE_VERSION_MAJOR 0U +#define NODE_VERSION_MINOR 9U +#define NODE_VERSION_REVISION 4U +#define NODE_VERSION_INTERNAL 0U + #define NODE_VERSION "NodeMcu 0.9.4" #define BUILD_DATE "build 20141230" // #define FLASH_512K diff --git a/app/modules/node.c b/app/modules/node.c index 3c7a41b2..cc2470cc 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -32,6 +32,20 @@ static int ICACHE_FLASH_ATTR node_deepsleep( lua_State* L ) return 0; } +// Lua: info() +static int ICACHE_FLASH_ATTR node_info( lua_State* L ) +{ + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_pushinteger(L, flash_get_size_byte() / 1024); // flash size in KB + lua_pushinteger(L, flash_get_mode()); + lua_pushinteger(L, flash_get_speed()); + return 8; +} + // Lua: chipid() static int ICACHE_FLASH_ATTR node_chipid( lua_State* L ) { @@ -264,6 +278,7 @@ const LUA_REG_TYPE node_map[] = { { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) }, + { LSTRKEY( "info" ), LFUNCVAL( node_info ) }, { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) }, { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) }, { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) }, From 65058bfacd49e432b919a9027c58a534ffc05e33 Mon Sep 17 00:00:00 2001 From: HuangRui Date: Wed, 31 Dec 2014 15:27:27 +0800 Subject: [PATCH 5/9] Auto generate BUILD_DATE. --- app/include/user_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/include/user_config.h b/app/include/user_config.h index ddff4cc1..ab0edf23 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -7,7 +7,7 @@ #define NODE_VERSION_INTERNAL 0U #define NODE_VERSION "NodeMcu 0.9.4" -#define BUILD_DATE "build 20141230" +#define BUILD_DATE "build " __DATE__ // #define FLASH_512K // #define FLASH_1M // #define FLASH_2M From 1105b951759e695144059af0c200cfeb24a2944e Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 31 Dec 2014 16:54:44 +0800 Subject: [PATCH 6/9] add newline to flash_api.c for win vm --- app/platform/flash_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 1620c7c5..57858e10 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -229,4 +229,4 @@ flash_self_destruct(void) // Erase your flash. Good bye! SPIEraseChip(); return true; -} \ No newline at end of file +} From b0ec34567cd44039d7f30c3dadefe1804e2481c0 Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 31 Dec 2014 20:20:38 +0800 Subject: [PATCH 7/9] align flash read/write addr --- app/platform/flash_api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 57858e10..53f95af1 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -12,7 +12,7 @@ SPIFlashInfo *ICACHE_FLASH_ATTR flash_get_info(void) { - static SPIFlashInfo spi_flash_info; + static SPIFlashInfo spi_flash_info __attribute__((aligned(4))); static bool is_spi_flash_info_initialized = false; // Make the code more fast if (!is_spi_flash_info_initialized) @@ -76,7 +76,7 @@ flash_set_size(uint8_t size) // Reboot required!!! // If you don't know what you're doing, your nodemcu may turn into stone ... c_printf("\nSet size!!! %d\n", size); - uint8_t data[SPI_FLASH_SEC_SIZE]; + uint8_t data[SPI_FLASH_SEC_SIZE] __attribute__((aligned(4))); SPIRead(0, data, sizeof(data)); SPIFlashInfo *p_spi_flash_info = (SPIFlashInfo *)(data); p_spi_flash_info->size = size; @@ -195,7 +195,7 @@ flash_init_data_default(void) // Dangerous, here are dinosaur infested!!!!! // Reboot required!!! // It will init system data to default! - uint8_t flash_init_data[128] = + uint8_t flash_init_data[128] __attribute__((aligned(4))) = { 0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05, 0x04, 0xFE, 0xFD, 0xFF, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE1, 0x0A, 0xFF, 0xFF, 0xF8, 0x00, From 1b9479a6501308857a653fcade5b2b100667b4f1 Mon Sep 17 00:00:00 2001 From: HuangRui Date: Thu, 1 Jan 2015 22:22:05 +0800 Subject: [PATCH 8/9] Added NODE_STORE_ATTR __attribute__((aligned(4),packed)) --- app/include/user_config.h | 7 +++++-- app/platform/flash_api.h | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/include/user_config.h b/app/include/user_config.h index ab0edf23..9f4512c7 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -4,10 +4,11 @@ #define NODE_VERSION_MAJOR 0U #define NODE_VERSION_MINOR 9U #define NODE_VERSION_REVISION 4U -#define NODE_VERSION_INTERNAL 0U +#define NODE_VERSION_INTERNAL 0U #define NODE_VERSION "NodeMcu 0.9.4" -#define BUILD_DATE "build " __DATE__ +#define BUILD_DATE "build 20150101" + // #define FLASH_512K // #define FLASH_1M // #define FLASH_2M @@ -34,6 +35,8 @@ #define NODE_ERR #endif /* NODE_ERROR */ +#define NODE_STORE_ATTR __attribute__((aligned(4),packed)) + #define CLIENT_SSL_ENABLE #define GPIO_INTERRUPT_ENABLE diff --git a/app/platform/flash_api.h b/app/platform/flash_api.h index 5642562f..6ba98120 100644 --- a/app/platform/flash_api.h +++ b/app/platform/flash_api.h @@ -1,7 +1,8 @@ #ifndef __FLASH_API_H__ #define __FLASH_API_H__ #include "ets_sys.h" -typedef struct __attribute__((packed)) +#include "user_config.h" +typedef struct { uint8_t unknown0; uint8_t unknown1; @@ -27,7 +28,7 @@ typedef struct __attribute__((packed)) SIZE_16MBIT = 3, SIZE_32MBIT = 4, } size : 4; -} SPIFlashInfo; +} NODE_STORE_ATTR SPIFlashInfo; SPIFlashInfo *flash_get_info(void); uint8_t flash_get_size(void); From 0420b6d72f0bf8eae78ccca3e57ac5014cc4bc88 Mon Sep 17 00:00:00 2001 From: HuangRui Date: Fri, 2 Jan 2015 17:56:34 +0800 Subject: [PATCH 9/9] Add definition of NODE_STORE_TYPEDEF_ATTR and NODE_STORE_ATTR. --- app/include/user_config.h | 3 ++- app/platform/flash_api.c | 26 +++++++------------------- app/platform/flash_api.h | 3 ++- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/app/include/user_config.h b/app/include/user_config.h index 9f4512c7..e0c04807 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -35,7 +35,8 @@ #define NODE_ERR #endif /* NODE_ERROR */ -#define NODE_STORE_ATTR __attribute__((aligned(4),packed)) +#define NODE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed)) +#define NODE_STORE_ATTR __attribute__((aligned(4))) #define CLIENT_SSL_ENABLE #define GPIO_INTERRUPT_ENABLE diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 53f95af1..7a85e5bf 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -7,12 +7,10 @@ #include "flash_api.h" #include "spi_flash.h" -#include "c_stdio.h" - SPIFlashInfo *ICACHE_FLASH_ATTR flash_get_info(void) -{ - static SPIFlashInfo spi_flash_info __attribute__((aligned(4))); +{ + static SPIFlashInfo spi_flash_info NODE_STORE_ATTR; static bool is_spi_flash_info_initialized = false; // Make the code more fast if (!is_spi_flash_info_initialized) @@ -20,7 +18,8 @@ flash_get_info(void) SPIRead(0, &spi_flash_info, sizeof(spi_flash_info)); is_spi_flash_info_initialized = true; } - return &spi_flash_info; + // return (SPIFlashInfo *)(0x40200000); + return &spi_flash_info; } uint8_t ICACHE_FLASH_ATTR @@ -75,8 +74,7 @@ flash_set_size(uint8_t size) // Dangerous, here are dinosaur infested!!!!! // Reboot required!!! // If you don't know what you're doing, your nodemcu may turn into stone ... - c_printf("\nSet size!!! %d\n", size); - uint8_t data[SPI_FLASH_SEC_SIZE] __attribute__((aligned(4))); + uint8_t data[SPI_FLASH_SEC_SIZE] NODE_STORE_ATTR; SPIRead(0, data, sizeof(data)); SPIFlashInfo *p_spi_flash_info = (SPIFlashInfo *)(data); p_spi_flash_info->size = size; @@ -195,19 +193,9 @@ flash_init_data_default(void) // Dangerous, here are dinosaur infested!!!!! // Reboot required!!! // It will init system data to default! - uint8_t flash_init_data[128] __attribute__((aligned(4))) = - { - 0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05, - 0x04, 0xFE, 0xFD, 0xFF, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE1, 0x0A, 0xFF, 0xFF, 0xF8, 0x00, - 0xF8, 0xF8, 0x52, 0x4E, 0x4A, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xE1, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + SPIEraseSector((flash_get_sec_num() - 4)); - SPIWrite((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, flash_init_data, sizeof(flash_init_data)); + SPIWrite((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, 0x10000 - SPI_FLASH_SEC_SIZE + (0), 128); return true; } diff --git a/app/platform/flash_api.h b/app/platform/flash_api.h index 6ba98120..a88e0504 100644 --- a/app/platform/flash_api.h +++ b/app/platform/flash_api.h @@ -2,6 +2,7 @@ #define __FLASH_API_H__ #include "ets_sys.h" #include "user_config.h" + typedef struct { uint8_t unknown0; @@ -28,7 +29,7 @@ typedef struct SIZE_16MBIT = 3, SIZE_32MBIT = 4, } size : 4; -} NODE_STORE_ATTR SPIFlashInfo; +} NODE_STORE_TYPEDEF_ATTR SPIFlashInfo; SPIFlashInfo *flash_get_info(void); uint8_t flash_get_size(void);