Skip to content

Commit 3d24167

Browse files
Merge branch 'master' into littlefs
2 parents cd03a6f + c08ef51 commit 3d24167

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+819
-483
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ jobs:
4444
script: $TRAVIS_BUILD_DIR/tests/common.sh
4545
env:
4646
- BUILD_TYPE=debug_odd
47+
- name: "Build IPv6 (1)"
48+
script: $TRAVIS_BUILD_DIR/tests/common.sh
49+
env:
50+
- BUILD_TYPE=build6_even
51+
- name: "Build IPv6 (2)"
52+
script: $TRAVIS_BUILD_DIR/tests/common.sh
53+
env:
54+
- BUILD_TYPE=build6_odd
4755
- name: "Platformio (1)"
4856
script: $TRAVIS_BUILD_DIR/tests/common.sh
4957
env:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Arduino core for ESP8266 WiFi chip
33

44
# Quick links
55

6-
- [Latest release documentation](https://arduino-esp8266.readthedocs.io/en/2.5.0-beta1/)
6+
- [Latest release documentation](https://arduino-esp8266.readthedocs.io/en/2.5.0-beta2/)
77
- [Current "git version" documentation](https://arduino-esp8266.readthedocs.io/en/latest/)
88
- [Install git version](https://arduino-esp8266.readthedocs.io/en/latest/installing.html#using-git-version) ([sources](doc/installing.rst#using-git-version))
99

@@ -36,7 +36,7 @@ Starting with 1.6.4, Arduino allows installation of third-party platform package
3636
#### Latest release [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/)
3737
Boards manager link: `http://arduino.esp8266.com/stable/package_esp8266com_index.json`
3838

39-
Documentation: [https://arduino-esp8266.readthedocs.io/en/2.5.0-beta1/](https://arduino-esp8266.readthedocs.io/en/2.5.0-beta1/)
39+
Documentation: [https://arduino-esp8266.readthedocs.io/en/2.5.0-beta2/](https://arduino-esp8266.readthedocs.io/en/2.5.0-beta2/)
4040

4141
### Using git version (basic instructions)
4242
[![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino)

boards.txt

Lines changed: 120 additions & 120 deletions
Large diffs are not rendered by default.

cores/esp8266/Esp.cpp

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ uint64_t EspClass::deepSleepMax()
132132

133133
}
134134

135-
/*
135+
/*
136136
Layout of RTC Memory is as follows:
137137
Ref: Espressif doc 2C-ESP8266_Non_OS_SDK_API_Reference, section 3.3.23 (system_rtc_mem_write)
138138
139139
|<------system data (256 bytes)------->|<-----------------user data (512 bytes)--------------->|
140140
141-
SDK function signature:
141+
SDK function signature:
142142
bool system_rtc_mem_read (
143-
uint32 des_addr,
144-
void * src_addr,
143+
uint32 des_addr,
144+
void * src_addr,
145145
uint32 save_size
146-
)
146+
)
147147
148148
The system data section can't be used by the user, so:
149149
des_addr must be >=64 (i.e.: 256/4) and <192 (i.e.: 768/4)
@@ -160,7 +160,7 @@ Same for write
160160
Note: If the Updater class is in play, e.g.: the application uses OTA, the eboot
161161
command will be stored into the first 128 bytes of user data, then it will be
162162
retrieved by eboot on boot. That means that user data present there will be lost.
163-
Ref:
163+
Ref:
164164
- discussion in PR #5330.
165165
- https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
166166
- Arduino/bootloaders/eboot/eboot_command.h RTC_MEM definition
@@ -266,7 +266,16 @@ uint8_t EspClass::getCpuFreqMHz(void)
266266

267267
uint32_t EspClass::getFlashChipId(void)
268268
{
269-
return spi_flash_get_id();
269+
static uint32_t flash_chip_id = 0;
270+
if (flash_chip_id == 0) {
271+
flash_chip_id = spi_flash_get_id();
272+
}
273+
return flash_chip_id;
274+
}
275+
276+
uint8_t EspClass::getFlashChipVendorId(void)
277+
{
278+
return (getFlashChipId() & 0x000000ff);
270279
}
271280

272281
uint32_t EspClass::getFlashChipRealSize(void)
@@ -569,9 +578,61 @@ bool EspClass::flashEraseSector(uint32_t sector) {
569578
return rc == 0;
570579
}
571580

581+
#if PUYA_SUPPORT
582+
static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
583+
if (data == nullptr) {
584+
return 1; // SPI_FLASH_RESULT_ERR
585+
}
586+
// PUYA flash chips need to read existing data, update in memory and write modified data again.
587+
static uint32_t *flash_write_puya_buf = nullptr;
588+
int rc = 0;
589+
uint32_t* ptr = data;
590+
591+
if (flash_write_puya_buf == nullptr) {
592+
flash_write_puya_buf = (uint32_t*) malloc(PUYA_BUFFER_SIZE);
593+
// No need to ever free this, since the flash chip will never change at runtime.
594+
if (flash_write_puya_buf == nullptr) {
595+
// Memory could not be allocated.
596+
return 1; // SPI_FLASH_RESULT_ERR
597+
}
598+
}
599+
size_t bytesLeft = size;
600+
uint32_t pos = offset;
601+
while (bytesLeft > 0 && rc == 0) {
602+
size_t bytesNow = bytesLeft;
603+
if (bytesNow > PUYA_BUFFER_SIZE) {
604+
bytesNow = PUYA_BUFFER_SIZE;
605+
bytesLeft -= PUYA_BUFFER_SIZE;
606+
} else {
607+
bytesLeft = 0;
608+
}
609+
rc = spi_flash_read(pos, flash_write_puya_buf, bytesNow);
610+
if (rc != 0) {
611+
return rc;
612+
}
613+
for (size_t i = 0; i < bytesNow / 4; ++i) {
614+
flash_write_puya_buf[i] &= *ptr;
615+
++ptr;
616+
}
617+
rc = spi_flash_write(pos, flash_write_puya_buf, bytesNow);
618+
pos += bytesNow;
619+
}
620+
return rc;
621+
}
622+
#endif
623+
572624
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
573625
ets_isr_mask(FLASH_INT_MASK);
574-
int rc = spi_flash_write(offset, (uint32_t*) data, size);
626+
int rc = 0;
627+
#if PUYA_SUPPORT
628+
if (getFlashChipVendorId() == SPI_FLASH_VENDOR_PUYA) {
629+
rc = spi_flash_write_puya(offset, data, size);
630+
}
631+
else
632+
#endif
633+
{
634+
rc = spi_flash_write(offset, data, size);
635+
}
575636
ets_isr_unmask(FLASH_INT_MASK);
576637
return rc == 0;
577638
}

cores/esp8266/Esp.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,52 @@
2323

2424
#include <Arduino.h>
2525

26+
#ifndef PUYA_SUPPORT
27+
#define PUYA_SUPPORT 0
28+
#endif
29+
#ifndef PUYA_BUFFER_SIZE
30+
// Good alternative for buffer size is: SPI_FLASH_SEC_SIZE (= 4k)
31+
// Always use a multiple of flash page size (256 bytes)
32+
#define PUYA_BUFFER_SIZE 256
33+
#endif
34+
35+
// Vendor IDs taken from Flashrom project
36+
// https://review.coreboot.org/cgit/flashrom.git/tree/flashchips.h?h=1.0.x
37+
typedef enum {
38+
SPI_FLASH_VENDOR_ALLIANCE = 0x52, /* Alliance Semiconductor */
39+
SPI_FLASH_VENDOR_AMD = 0x01, /* AMD */
40+
SPI_FLASH_VENDOR_AMIC = 0x37, /* AMIC */
41+
SPI_FLASH_VENDOR_ATMEL = 0x1F, /* Atmel (now used by Adesto) */
42+
SPI_FLASH_VENDOR_BRIGHT = 0xAD, /* Bright Microelectronics */
43+
SPI_FLASH_VENDOR_CATALYST = 0x31, /* Catalyst */
44+
SPI_FLASH_VENDOR_EON = 0x1C, /* EON Silicon Devices, missing 0x7F prefix */
45+
SPI_FLASH_VENDOR_ESMT = 0x8C, /* Elite Semiconductor Memory Technology (ESMT) / EFST Elite Flash Storage */
46+
SPI_FLASH_VENDOR_EXCEL = 0x4A, /* ESI, missing 0x7F prefix */
47+
SPI_FLASH_VENDOR_FIDELIX = 0xF8, /* Fidelix */
48+
SPI_FLASH_VENDOR_FUJITSU = 0x04, /* Fujitsu */
49+
SPI_FLASH_VENDOR_GIGADEVICE = 0xC8, /* GigaDevice */
50+
SPI_FLASH_VENDOR_HYUNDAI = 0xAD, /* Hyundai */
51+
SPI_FLASH_VENDOR_INTEL = 0x89, /* Intel */
52+
SPI_FLASH_VENDOR_ISSI = 0xD5, /* ISSI Integrated Silicon Solutions, see also PMC. */
53+
SPI_FLASH_VENDOR_MACRONIX = 0xC2, /* Macronix (MX) */
54+
SPI_FLASH_VENDOR_NANTRONICS = 0xD5, /* Nantronics, missing prefix */
55+
SPI_FLASH_VENDOR_PMC = 0x9D, /* PMC, missing 0x7F prefix */
56+
SPI_FLASH_VENDOR_PUYA = 0x85, /* Puya semiconductor (shanghai) co. ltd */
57+
SPI_FLASH_VENDOR_SANYO = 0x62, /* Sanyo */
58+
SPI_FLASH_VENDOR_SHARP = 0xB0, /* Sharp */
59+
SPI_FLASH_VENDOR_SPANSION = 0x01, /* Spansion, same ID as AMD */
60+
SPI_FLASH_VENDOR_SST = 0xBF, /* SST */
61+
SPI_FLASH_VENDOR_ST = 0x20, /* ST / SGS/Thomson / Numonyx (later acquired by Micron) */
62+
SPI_FLASH_VENDOR_SYNCMOS_MVC = 0x40, /* SyncMOS (SM) and Mosel Vitelic Corporation (MVC) */
63+
SPI_FLASH_VENDOR_TENX = 0x5E, /* Tenx Technologies */
64+
SPI_FLASH_VENDOR_TI = 0x97, /* Texas Instruments */
65+
SPI_FLASH_VENDOR_TI_OLD = 0x01, /* TI chips from last century */
66+
SPI_FLASH_VENDOR_WINBOND = 0xDA, /* Winbond */
67+
SPI_FLASH_VENDOR_WINBOND_NEX = 0xEF, /* Winbond (ex Nexcom) serial flashes */
68+
69+
SPI_FLASH_VENDOR_UNKNOWN = 0xFF
70+
} SPI_FLASH_VENDOR_t;
71+
2672
/**
2773
* AVR macros for WDT managment
2874
*/
@@ -123,6 +169,8 @@ class EspClass {
123169
uint8_t getCpuFreqMHz();
124170

125171
uint32_t getFlashChipId();
172+
uint8_t getFlashChipVendorId();
173+
126174
//gets the actual chip size based on the flash id
127175
uint32_t getFlashChipRealSize();
128176
//gets the size of the flash as set by the compiler

cores/esp8266/IPAddress.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class IPAddress: public Printable {
149149
/*
150150
lwIP address compatibility
151151
*/
152+
IPAddress(const ipv4_addr& fw_addr) { setV4(); v4() = fw_addr.addr; }
152153
IPAddress(const ipv4_addr* fw_addr) { setV4(); v4() = fw_addr->addr; }
153-
IPAddress(const ip_addr_t& lwip_addr) { _ip = lwip_addr; }
154154

155155
operator ip_addr_t () const { return _ip; }
156156
operator const ip_addr_t*() const { return &_ip; }
@@ -163,6 +163,9 @@ class IPAddress: public Printable {
163163

164164
#if LWIP_IPV6
165165

166+
IPAddress(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); }
167+
IPAddress(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); }
168+
166169
uint16_t* raw6()
167170
{
168171
setV6();

cores/esp8266/cont_util.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
4747
return 0;
4848
}
4949

50-
int ICACHE_RAM_ATTR cont_get_free_stack(cont_t* cont) {
50+
// No need for this to be in IRAM, not expected to be IRQ called
51+
int cont_get_free_stack(cont_t* cont) {
5152
uint32_t *head = cont->stack;
5253
int freeWords = 0;
5354

cores/esp8266/core_esp8266_postmortem.c

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,25 @@ extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack,
6262

6363
extern void custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) __attribute__ ((weak, alias("__custom_crash_callback")));
6464

65-
// Single, non-inlined copy of pgm_read_byte to save IRAM space (as this is not timing critical)
66-
static char ICACHE_RAM_ATTR iram_read_byte (const char *addr) {
67-
return pgm_read_byte(addr);
68-
}
69-
70-
// Required to output the s_panic_file, it's stored in PMEM
71-
#define ets_puts_P(pstr) \
72-
{ \
73-
char c; \
74-
do { \
75-
c = iram_read_byte(pstr++); \
76-
if (c) ets_putc(c); \
77-
} while (c); \
78-
}
7965

80-
// Place these strings in .text because the SPI interface may be in bad shape during an exception.
81-
#define ets_printf_P(str, ...) \
82-
{ \
83-
static const char istr[] ICACHE_RAM_ATTR = (str); \
84-
char mstr[sizeof(str)]; \
85-
for (size_t i=0; i < sizeof(str); i++) mstr[i] = iram_read_byte(&istr[i]); \
86-
ets_printf(mstr, ##__VA_ARGS__); \
66+
// Prints need to use our library function to allow for file and function
67+
// to be safely accessed from flash. This function encapsulates snprintf()
68+
// [which by definition will 0-terminate] and dumping to the UART
69+
static void ets_printf_P(const char *str, ...) {
70+
char destStr[160];
71+
char *c = destStr;
72+
va_list argPtr;
73+
va_start(argPtr, str);
74+
vsnprintf(destStr, sizeof(destStr), str, argPtr);
75+
va_end(argPtr);
76+
while (*c) {
77+
ets_putc(*(c++));
78+
}
8779
}
8880

8981
void __wrap_system_restart_local() {
9082
register uint32_t sp asm("a1");
83+
uint32_t sp_dump = sp;
9184

9285
if (gdb_present()) {
9386
/* When GDBStub is present, exceptions are handled by GDBStub,
@@ -110,28 +103,24 @@ void __wrap_system_restart_local() {
110103
ets_install_putc1(&uart_write_char_d);
111104

112105
if (s_panic_line) {
113-
ets_printf_P("\nPanic ");
114-
ets_puts_P(s_panic_file); // This is in PROGMEM, need special output because ets_printf can't handle ROM parameters
115-
ets_printf_P(":%d %s", s_panic_line, s_panic_func);
106+
ets_printf_P(PSTR("\nPanic %S:%d %S"), s_panic_file, s_panic_line, s_panic_func);
116107
if (s_panic_what) {
117-
ets_printf_P(": Assertion '");
118-
ets_puts_P(s_panic_what); // This is also in PMEM
119-
ets_printf_P("' failed.");
108+
ets_printf_P(PSTR(": Assertion '%S' failed."), s_panic_what);
120109
}
121110
ets_putc('\n');
122111
}
123112
else if (s_unhandled_exception) {
124-
ets_printf_P("\nUnhandled exception: %s\n", s_unhandled_exception);
113+
ets_printf_P(PSTR("\nUnhandled C++ exception: %S\n"), s_unhandled_exception);
125114
}
126115
else if (s_abort_called) {
127-
ets_printf_P("\nAbort called\n");
116+
ets_printf_P(PSTR("\nAbort called\n"));
128117
}
129118
else if (rst_info.reason == REASON_EXCEPTION_RST) {
130-
ets_printf_P("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
119+
ets_printf_P(PSTR("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n"),
131120
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
132121
}
133122
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
134-
ets_printf_P("\nSoft WDT reset\n");
123+
ets_printf_P(PSTR("\nSoft WDT reset\n"));
135124
}
136125

137126
uint32_t cont_stack_start = (uint32_t) &(g_pcont->stack);
@@ -152,54 +141,53 @@ void __wrap_system_restart_local() {
152141
offset = 0x10;
153142
}
154143

155-
ets_printf_P("\n>>>stack>>>\n");
144+
ets_printf_P(PSTR("\n>>>stack>>>\n"));
156145

157-
if (sp > stack_thunk_get_stack_bot() && sp <= stack_thunk_get_stack_top()) {
146+
if (sp_dump > stack_thunk_get_stack_bot() && sp_dump <= stack_thunk_get_stack_top()) {
158147
// BearSSL we dump the BSSL second stack and then reset SP back to the main cont stack
159-
ets_printf_P("\nctx: bearssl \n");
160-
ets_printf_P("sp: %08x end: %08x offset: %04x\n", sp, stack_thunk_get_stack_top(), offset);
161-
print_stack(sp + offset, stack_thunk_get_stack_top());
148+
ets_printf_P(PSTR("\nctx: bearssl\nsp: %08x end: %08x offset: %04x\n"), sp_dump, stack_thunk_get_stack_top(), offset);
149+
print_stack(sp_dump + offset, stack_thunk_get_stack_top());
162150
offset = 0; // No offset needed anymore, the exception info was stored in the bssl stack
163-
sp = stack_thunk_get_cont_sp();
151+
sp_dump = stack_thunk_get_cont_sp();
164152
}
165153

166-
if (sp > cont_stack_start && sp < cont_stack_end) {
167-
ets_printf_P("\nctx: cont \n");
154+
if (sp_dump > cont_stack_start && sp_dump < cont_stack_end) {
155+
ets_printf_P(PSTR("\nctx: cont\n"));
168156
stack_end = cont_stack_end;
169157
}
170158
else {
171-
ets_printf_P("\nctx: sys \n");
159+
ets_printf_P(PSTR("\nctx: sys\n"));
172160
stack_end = 0x3fffffb0;
173161
// it's actually 0x3ffffff0, but the stuff below ets_run
174162
// is likely not really relevant to the crash
175163
}
176164

177-
ets_printf_P("sp: %08x end: %08x offset: %04x\n", sp, stack_end, offset);
165+
ets_printf_P(PSTR("sp: %08x end: %08x offset: %04x\n"), sp_dump, stack_end, offset);
178166

179-
print_stack(sp + offset, stack_end);
167+
print_stack(sp_dump + offset, stack_end);
180168

181-
ets_printf_P("<<<stack<<<\n");
169+
ets_printf_P(PSTR("<<<stack<<<\n"));
182170

183171
// Use cap-X formatting to ensure the standard EspExceptionDecoder doesn't match the address
184172
if (umm_last_fail_alloc_addr) {
185-
ets_printf_P("\nlast failed alloc call: %08X(%d)\n", (uint32_t)umm_last_fail_alloc_addr, umm_last_fail_alloc_size);
173+
ets_printf_P(PSTR("\nlast failed alloc call: %08X(%d)\n"), (uint32_t)umm_last_fail_alloc_addr, umm_last_fail_alloc_size);
186174
}
187175

188-
custom_crash_callback( &rst_info, sp + offset, stack_end );
176+
custom_crash_callback( &rst_info, sp_dump + offset, stack_end );
189177

190178
delayMicroseconds(10000);
191179
__real_system_restart_local();
192180
}
193181

194182

195-
static void ICACHE_RAM_ATTR print_stack(uint32_t start, uint32_t end) {
183+
static void print_stack(uint32_t start, uint32_t end) {
196184
for (uint32_t pos = start; pos < end; pos += 0x10) {
197185
uint32_t* values = (uint32_t*)(pos);
198186

199187
// rough indicator: stack frames usually have SP saved as the second word
200188
bool looksLikeStackFrame = (values[2] == pos + 0x10);
201189

202-
ets_printf_P("%08x: %08x %08x %08x %08x %c\n",
190+
ets_printf_P(PSTR("%08x: %08x %08x %08x %08x %c\n"),
203191
pos, values[0], values[1], values[2], values[3], (looksLikeStackFrame)?'<':' ');
204192
}
205193
}

0 commit comments

Comments
 (0)