Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
32b29112
Commit
32b29112
authored
Dec 01, 2015
by
Terry Ellison
Browse files
Merge pull request #746 from DiUS/vdd33
Remove adc.readvdd33() limitation.
parents
e9e2efc4
1e3c2316
Changes
4
Show whitespace changes
Inline
Side-by-side
app/include/user_config.h
View file @
32b29112
...
@@ -11,11 +11,13 @@
...
@@ -11,11 +11,13 @@
// #define FLASH_16M
// #define FLASH_16M
#define FLASH_AUTOSIZE
#define FLASH_AUTOSIZE
#define FLASH_SAFE_API
#define FLASH_SAFE_API
// #define DEVELOP_VERSION
#define FULL_VERSION_FOR_USER
#define USE_OPTIMIZE_PRINTF
// Byte 107 of esp_init_data_default, only one of these 3 can be picked
#define ESP_INIT_DATA_ENABLE_READVDD33
//#define ESP_INIT_DATA_ENABLE_READADC
//#define ESP_INIT_DATA_FIXED_VDD33_VALUE 33
// #define DEVELOP_VERSION
#ifdef DEVELOP_VERSION
#ifdef DEVELOP_VERSION
#define NODE_DEBUG
#define NODE_DEBUG
#define COAP_DEBUG
#define COAP_DEBUG
...
...
app/modules/adc.c
View file @
32b29112
...
@@ -23,25 +23,7 @@ static int adc_sample( lua_State* L )
...
@@ -23,25 +23,7 @@ static int adc_sample( lua_State* L )
// Lua: readvdd33()
// Lua: readvdd33()
static
int
adc_readvdd33
(
lua_State
*
L
)
static
int
adc_readvdd33
(
lua_State
*
L
)
{
{
uint32_t
vdd33
=
0
;
lua_pushinteger
(
L
,
system_get_vdd33
());
if
(
STATION_MODE
==
wifi_get_opmode
())
{
// Bug fix
if
(
wifi_station_get_connect_status
()
!=
0
)
{
return
luaL_error
(
L
,
"Can't read vdd33 while station is connected"
);
}
else
{
vdd33
=
system_get_vdd33
();
}
}
else
{
vdd33
=
system_get_vdd33
();
}
lua_pushinteger
(
L
,
vdd33
);
return
1
;
return
1
;
}
}
...
...
app/platform/flash_api.c
View file @
32b29112
...
@@ -8,7 +8,17 @@
...
@@ -8,7 +8,17 @@
#include "spi_flash.h"
#include "spi_flash.h"
#include "c_stdio.h"
#include "c_stdio.h"
static
volatile
const
uint8_t
flash_init_data
[
128
]
ICACHE_STORE_ATTR
ICACHE_RODATA_ATTR
=
#if defined(ESP_INIT_DATA_ENABLE_READVDD33)
# define INIT_107 0xff
#elif defined(ESP_INIT_DATA_ENABLE_READADC)
# define INIT_107 0x00
#elif defined(ESP_INIT_DATA_FIXED_VDD33_VALUE)
# define INIT_107 ESP_INIT_DATA_FIXED_VDD33_VALUE
#else
# define INIT_107 0xff
#endif
static
const
uint8_t
flash_init_data
[
128
]
=
{
{
0x05
,
0x00
,
0x04
,
0x02
,
0x05
,
0x05
,
0x05
,
0x02
,
0x05
,
0x00
,
0x04
,
0x05
,
0x05
,
0x04
,
0x05
,
0x05
,
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
,
0x04
,
0xFE
,
0xFD
,
0xFF
,
0xF0
,
0xF0
,
0xF0
,
0xE0
,
0xE0
,
0xE0
,
0xE1
,
0x0A
,
0xFF
,
0xFF
,
0xF8
,
0x00
,
...
@@ -16,7 +26,7 @@ static volatile const uint8_t flash_init_data[128] ICACHE_STORE_ATTR ICACHE_RODA
...
@@ -16,7 +26,7 @@ static volatile const uint8_t flash_init_data[128] ICACHE_STORE_ATTR ICACHE_RODA
0x01
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x02
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
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
,
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
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
INIT_107
,
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
};
};
...
@@ -316,26 +326,13 @@ bool flash_rom_set_speed(uint32_t speed)
...
@@ -316,26 +326,13 @@ bool flash_rom_set_speed(uint32_t speed)
return
true
;
return
true
;
}
}
bool
flash_init_data_written
(
void
)
{
// FLASH SEC - 4
uint32_t
data
[
2
]
ICACHE_STORE_ATTR
;
#if defined(FLASH_SAFE_API)
if
(
SPI_FLASH_RESULT_OK
==
flash_safe_read
((
flash_safe_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
data
,
sizeof
(
data
)))
#else
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_read
((
flash_rom_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
data
,
sizeof
(
data
)))
#endif // defined(FLASH_SAFE_API)
{
if
(
data
[
0
]
==
0xFFFFFFFF
&&
data
[
1
]
==
0xFFFFFFFF
)
{
return
false
;
}
}
return
true
;
}
bool
flash_init_data_default
(
void
)
bool
flash_init_data_default
(
void
)
{
{
/* Can't copy directly from flash (which is where the default data lives)
* due to it being unmapped during the write, so bounce via ram buffer. */
uint8_t
init_data
[
128
];
os_memcpy
(
init_data
,
flash_init_data
,
128
);
// FLASH SEC - 4
// FLASH SEC - 4
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// Reboot required!!!
...
@@ -344,7 +341,7 @@ bool flash_init_data_default(void)
...
@@ -344,7 +341,7 @@ bool flash_init_data_default(void)
#if defined(FLASH_SAFE_API)
#if defined(FLASH_SAFE_API)
if
(
SPI_FLASH_RESULT_OK
==
flash_safe_erase_sector
((
flash_safe_get_sec_num
()
-
4
)))
if
(
SPI_FLASH_RESULT_OK
==
flash_safe_erase_sector
((
flash_safe_get_sec_num
()
-
4
)))
{
{
if
(
SPI_FLASH_RESULT_OK
==
flash_safe_write
((
flash_safe_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
flash_
init_data
,
128
))
if
(
SPI_FLASH_RESULT_OK
==
flash_safe_write
((
flash_safe_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
init_data
,
128
))
{
{
result
=
true
;
result
=
true
;
}
}
...
@@ -352,7 +349,7 @@ bool flash_init_data_default(void)
...
@@ -352,7 +349,7 @@ bool flash_init_data_default(void)
#else
#else
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
((
flash_rom_get_sec_num
()
-
4
)))
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
((
flash_rom_get_sec_num
()
-
4
)))
{
{
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
((
flash_rom_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
flash_
init_data
,
128
))
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
((
flash_rom_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
init_data
,
128
))
{
{
result
=
true
;
result
=
true
;
}
}
...
...
app/user/user_main.c
View file @
32b29112
...
@@ -30,7 +30,14 @@
...
@@ -30,7 +30,14 @@
#define SIG_LUA 0
#define SIG_LUA 0
#define SIG_UARTINPUT 1
#define SIG_UARTINPUT 1
#define TASK_QUEUE_LEN 4
#define TASK_QUEUE_LEN 4
os_event_t
*
taskQueue
;
static
os_event_t
*
taskQueue
;
/* Important: no_init_data CAN NOT be left as zero initialised, as that
* initialisation will happen after user_start_trampoline, but before
* the user_init, thus clobbering our state!
*/
static
uint8_t
no_init_data
=
0xff
;
/* Note: the trampoline *must* be explicitly put into the .text segment, since
/* Note: the trampoline *must* be explicitly put into the .text segment, since
...
@@ -47,6 +54,30 @@ void TEXT_SECTION_ATTR user_start_trampoline (void)
...
@@ -47,6 +54,30 @@ void TEXT_SECTION_ATTR user_start_trampoline (void)
// is where the cpu clock actually gets bumped to 80MHz.
// is where the cpu clock actually gets bumped to 80MHz.
rtctime_early_startup
();
rtctime_early_startup
();
#endif
#endif
/* Minimal early detection of missing esp_init_data.
* If it is missing, the SDK will write its own and thus we'd end up
* using that unless the flash size field is incorrect. This then leads
* to different esp_init_data being used depending on whether the user
* flashed with the right flash size or not (and the better option would
* be to flash with an *incorrect* flash size, counter-intuitively).
* To avoid that mess, we read out the flash size and do a test for
* esp_init_data based on that size. If it's missing, flag for later.
* If the flash size was incorrect, we'll end up fixing it all up
* anyway, so this ends up solving the conundrum. Only remaining issue
* is lack of spare code bytes in iram, so this is deliberately quite
* terse and not as readable as one might like.
*/
SPIFlashInfo
sfi
;
SPIRead
(
0
,
&
sfi
,
sizeof
(
sfi
));
// Cache read not enabled yet, safe to use
if
(
sfi
.
size
<
2
)
// Compensate for out-of-order 4mbit vs 2mbit values
sfi
.
size
^=
1
;
uint32_t
flash_end_addr
=
(
256
*
1024
)
<<
sfi
.
size
;
uint32_t
init_data_hdr
=
0xffffffff
;
SPIRead
(
flash_end_addr
-
4
*
SPI_FLASH_SEC_SIZE
,
&
init_data_hdr
,
sizeof
(
init_data_hdr
));
no_init_data
=
(
init_data_hdr
==
0xffffffff
);
call_user_start
();
call_user_start
();
}
}
...
@@ -111,10 +142,9 @@ void nodemcu_init(void)
...
@@ -111,10 +142,9 @@ void nodemcu_init(void)
NODE_ERR
(
"Self adjust flash size.
\n
"
);
NODE_ERR
(
"Self adjust flash size.
\n
"
);
// Fit hardware real flash size.
// Fit hardware real flash size.
flash_rom_set_size_byte
(
flash_safe_get_size_byte
());
flash_rom_set_size_byte
(
flash_safe_get_size_byte
());
// Flash init data at FLASHSIZE - 0x04000 Byte.
// Write out init data at real location.
flash_init_data_default
();
no_init_data
=
true
;
// Flash blank data at FLASHSIZE - 0x02000 Byte.
flash_init_data_blank
();
if
(
!
fs_format
()
)
if
(
!
fs_format
()
)
{
{
NODE_ERR
(
"
\n
i*** ERROR ***: unable to format. FS might be compromised.
\n
"
);
NODE_ERR
(
"
\n
i*** ERROR ***: unable to format. FS might be compromised.
\n
"
);
...
@@ -127,12 +157,15 @@ void nodemcu_init(void)
...
@@ -127,12 +157,15 @@ void nodemcu_init(void)
}
}
#endif // defined(FLASH_SAFE_API)
#endif // defined(FLASH_SAFE_API)
if
(
!
flash_init_data_written
()
){
if
(
no_init_data
)
{
NODE_ERR
(
"Restore init data.
\n
"
);
NODE_ERR
(
"Restore init data.
\n
"
);
// Flash init data at FLASHSIZE - 0x04000 Byte.
// Flash init data at FLASHSIZE - 0x04000 Byte.
flash_init_data_default
();
flash_init_data_default
();
// Flash blank data at FLASHSIZE - 0x02000 Byte.
// Flash blank data at FLASHSIZE - 0x02000 Byte.
flash_init_data_blank
();
flash_init_data_blank
();
// Reboot to make the new data come into effect
system_restart
();
}
}
#if defined( BUILD_WOFS )
#if defined( BUILD_WOFS )
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment