Skip to content

Commit 29dc460

Browse files
Merge branch 'master' of https://github.com/esp8266/Arduino into irqunsafe
2 parents 3ba69e9 + 831d643 commit 29dc460

37 files changed

+253
-38
lines changed

cores/esp8266/core_esp8266_postmortem.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ void __wrap_system_restart_local() {
108108
else
109109
rst_info.reason = s_user_reset_reason;
110110

111-
// TODO: ets_install_putc1 definition is wrong in ets_sys.h, need cast
112-
ets_install_putc1((void *)&uart_write_char_d);
111+
ets_install_putc1(&uart_write_char_d);
113112

114113
if (s_panic_line) {
115114
ets_printf_P(PSTR("\nPanic %S:%d %S"), s_panic_file, s_panic_line, s_panic_func);

cores/esp8266/libc_replacements.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) __attribute__((
100100
int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) {
101101
(void) r;
102102
if (file->_file == STDOUT_FILENO) {
103-
return ets_putc(c);
103+
ets_putc(c);
104+
return c;
104105
}
105106
return EOF;
106107
}

cores/esp8266/spiffs_api.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525

2626
using namespace fs;
2727

28+
29+
// Deprecated functions, to be deleted in next release
30+
int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src) {
31+
return flash_hal_write(addr, size, src);
32+
}
33+
int32_t spiffs_hal_erase(uint32_t addr, uint32_t size) {
34+
return flash_hal_erase(addr, size);
35+
}
36+
int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
37+
return flash_hal_read(addr, size, dst);
38+
}
39+
40+
41+
42+
2843
namespace spiffs_impl {
2944

3045
FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode)

cores/esp8266/spiffs_api.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ extern "C" {
3939

4040
using namespace fs;
4141

42+
// The following are deprecated symbols and functions, to be removed at the next major release.
43+
// They are provided only for backwards compatibility and to give libs a chance to update.
44+
45+
extern "C" uint32_t _SPIFFS_start __attribute__((deprecated));
46+
extern "C" uint32_t _SPIFFS_end __attribute__((deprecated));
47+
extern "C" uint32_t _SPIFFS_page __attribute__((deprecated));
48+
extern "C" uint32_t _SPIFFS_block __attribute__((deprecated));
49+
50+
#define SPIFFS_PHYS_ADDR ((uint32_t) (&_SPIFFS_start) - 0x40200000)
51+
#define SPIFFS_PHYS_SIZE ((uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start))
52+
#define SPIFFS_PHYS_PAGE ((uint32_t) &_SPIFFS_page)
53+
#define SPIFFS_PHYS_BLOCK ((uint32_t) &_SPIFFS_block)
54+
55+
extern int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src) __attribute__((deprecated));
56+
extern int32_t spiffs_hal_erase(uint32_t addr, uint32_t size) __attribute__((deprecated));
57+
extern int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) __attribute__((deprecated));
58+
59+
60+
61+
4262
namespace spiffs_impl {
4363

4464
int getSpiffsMode(OpenMode openMode, AccessMode accessMode);

cores/esp8266/uart.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ void
899899
uart_set_debug(int uart_nr)
900900
{
901901
s_uart_debug_nr = uart_nr;
902-
void (*func)(char) = NULL;
903-
switch(s_uart_debug_nr)
902+
fp_putc_t func = NULL;
903+
switch(s_uart_debug_nr)
904904
{
905905
case UART0:
906906
func = &uart0_write_char;
@@ -929,7 +929,7 @@ uart_set_debug(int uart_nr)
929929
} else {
930930
system_set_os_print(0);
931931
}
932-
ets_install_putc1((void *) func);
932+
ets_install_putc1(func);
933933
}
934934
}
935935

cores/esp8266/umm_malloc/umm_performance.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,8 @@ bool ICACHE_FLASH_ATTR get_umm_get_perf_data(struct _UMM_TIME_STATS *p, size_t s
3939
Objective: To be able to print "last gasp" diagnostic messages
4040
when interrupts are disabled and w/o availability of heap resources.
4141
*/
42-
43-
// ROM _putc1, ignores CRs and sends CR/LF for LF, newline.
44-
// Always returns character sent.
45-
int constexpr (*_rom_putc1)(int) = (int (*)(int))0x40001dcc;
46-
void uart_buff_switch(uint8_t);
47-
4842
int _isr_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
4943
int ICACHE_RAM_ATTR _isr_safe_printf_P(const char *fmt, ...) {
50-
#ifdef DEBUG_ESP_PORT
51-
#define VALUE(x) __STRINGIFY(x)
52-
// Preprocessor and compiler together will optimize away the if.
53-
if (strcmp("Serial1", VALUE(DEBUG_ESP_PORT)) == 0) {
54-
uart_buff_switch(1U);
55-
} else {
56-
uart_buff_switch(0U);
57-
}
58-
#else
59-
uart_buff_switch(0U); // Side effect, clears RX FIFO
60-
#endif
6144
/*
6245
To use ets_strlen() and ets_memcpy() safely with PROGMEM, flash storage,
6346
the PROGMEM address must be word (4 bytes) aligned. The destination
@@ -71,7 +54,7 @@ int ICACHE_RAM_ATTR _isr_safe_printf_P(const char *fmt, ...) {
7154
ets_memcpy(ram_buf, fmt, buf_len);
7255
va_list argPtr;
7356
va_start(argPtr, fmt);
74-
int result = ets_vprintf(_rom_putc1, ram_buf, argPtr);
57+
int result = ets_vprintf(ets_uart_putc1, ram_buf, argPtr);
7558
va_end(argPtr);
7659
return result;
7760
}

libraries/EEPROM/EEPROM.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "Arduino.h"
2323
#include "EEPROM.h"
24+
#include "debug.h"
2425

2526
extern "C" {
2627
#include "c_types.h"
@@ -49,10 +50,14 @@ EEPROMClass::EEPROMClass(void)
4950
}
5051

5152
void EEPROMClass::begin(size_t size) {
52-
if (size <= 0)
53+
if (size <= 0) {
54+
DEBUGV("EEPROMClass::begin error, size == 0\n");
5355
return;
54-
if (size > SPI_FLASH_SEC_SIZE)
56+
}
57+
if (size > SPI_FLASH_SEC_SIZE) {
58+
DEBUGV("EEPROMClass::begin error, %d > %d\n", size, SPI_FLASH_SEC_SIZE);
5559
size = SPI_FLASH_SEC_SIZE;
60+
}
5661

5762
size = (size + 3) & (~3);
5863

@@ -67,8 +72,11 @@ void EEPROMClass::begin(size_t size) {
6772
_size = size;
6873

6974
noInterrupts();
70-
spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
75+
auto ret = spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
7176
interrupts();
77+
if (ret != SPI_FLASH_RESULT_OK) {
78+
DEBUGV("EEPROMClass::begin spi_flash_read failed, %d\n", (int)ret);
79+
}
7280

7381
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
7482
}
@@ -88,19 +96,27 @@ void EEPROMClass::end() {
8896

8997

9098
uint8_t EEPROMClass::read(int const address) {
91-
if (address < 0 || (size_t)address >= _size)
99+
if (address < 0 || (size_t)address >= _size) {
100+
DEBUGV("EEPROMClass::read error, address %d > %d or %d < 0\n", address, _size, address);
92101
return 0;
93-
if(!_data)
102+
}
103+
if (!_data) {
104+
DEBUGV("EEPROMClass::read without ::begin\n");
94105
return 0;
106+
}
95107

96108
return _data[address];
97109
}
98110

99111
void EEPROMClass::write(int const address, uint8_t const value) {
100-
if (address < 0 || (size_t)address >= _size)
112+
if (address < 0 || (size_t)address >= _size) {
113+
DEBUGV("EEPROMClass::write error, address %d > %d or %d < 0\n", address, _size, address);
101114
return;
102-
if(!_data)
115+
}
116+
if(!_data) {
117+
DEBUGV("EEPROMClass::read without ::begin\n");
103118
return;
119+
}
104120

105121
// Optimise _dirty. Only flagged if data written is different.
106122
uint8_t* pData = &_data[address];
@@ -121,14 +137,20 @@ bool EEPROMClass::commit() {
121137
return false;
122138

123139
noInterrupts();
124-
if(spi_flash_erase_sector(_sector) == SPI_FLASH_RESULT_OK) {
125-
if(spi_flash_write(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size) == SPI_FLASH_RESULT_OK) {
140+
auto flashret = spi_flash_erase_sector(_sector);
141+
if (flashret == SPI_FLASH_RESULT_OK) {
142+
flashret = spi_flash_write(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
143+
if (flashret == SPI_FLASH_RESULT_OK) {
126144
_dirty = false;
127145
ret = true;
128146
}
129147
}
130148
interrupts();
131149

150+
if (flashret != SPI_FLASH_RESULT_OK) {
151+
DEBUGV("EEPROMClass::commit failed, %d\n", (int)flashret);
152+
}
153+
132154
return ret;
133155
}
134156

libraries/EEPROM/examples/eeprom_read/eeprom_read.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ byte value;
1414

1515
void setup() {
1616
// initialize serial and wait for port to open:
17-
Serial.begin(9600);
17+
Serial.begin(115200);
1818
while (!Serial) {
1919
; // wait for serial port to connect. Needed for Leonardo only
2020
}

libraries/EEPROM/examples/eeprom_write/eeprom_write.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
int addr = 0;
1414

1515
void setup() {
16+
Serial.begin(115200);
1617
EEPROM.begin(512);
1718
}
1819

@@ -33,7 +34,11 @@ void loop() {
3334
addr = addr + 1;
3435
if (addr == 512) {
3536
addr = 0;
36-
EEPROM.commit();
37+
if (EEPROM.commit()) {
38+
Serial.println("EEPROM successfully committed");
39+
} else {
40+
Serial.println("ERROR! EEPROM commit failed");
41+
}
3742
}
3843

3944
delay(100);

tools/boards.txt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,12 @@ def flash_map (flashsize_kb, fs_kb = 0):
12741274
print("PROVIDE ( _FS_page = 0x%X );" % page)
12751275
print("PROVIDE ( _FS_block = 0x%X );" % fs_blocksize)
12761276
print("PROVIDE ( _EEPROM_start = 0x%08x );" % (0x40200000 + eeprom_start))
1277+
# Re-add deprecated symbols pointing to the same address as the new standard ones
1278+
print("/* The following symbols are DEPRECATED and will be REMOVED in a future release */")
1279+
print("PROVIDE ( _SPIFFS_start = 0x%08X );" % (0x40200000 + fs_start))
1280+
print("PROVIDE ( _SPIFFS_end = 0x%08X );" % (0x40200000 + fs_end))
1281+
print("PROVIDE ( _SPIFFS_page = 0x%X );" % page)
1282+
print("PROVIDE ( _SPIFFS_block = 0x%X );" % fs_blocksize)
12771283
print("")
12781284
print('INCLUDE "local.eagle.app.v6.common.ld"')
12791285

tools/sdk/include/ets_sys.h

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@
3333
extern "C" {
3434
#endif
3535

36+
/*
37+
* This "print character function" prototype is modeled after the argument for
38+
* ets_install_putc1() found in "ESP8266_NONOS_SDK/include/osapi.h". This
39+
* deviates away from the familiar C library definition of putchar; however, it
40+
* agrees with the code we are working with. Note, in the ROM some "printf
41+
* character functions" always return 0 (uart_tx_one_char and ets_putc), some
42+
* return last character printed (buildin _putc1), and some return nothing
43+
* (ets_write_char). Using a void return type safely represents them all.
44+
*/
45+
typedef void (*fp_putc_t)(char);
46+
3647
typedef uint32_t ETSSignal;
3748
typedef uint32_t ETSParam;
3849

@@ -205,15 +216,41 @@ char *ets_strstr(const char *haystack, const char *needle);
205216
int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
206217
int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
207218
int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
208-
void ets_install_putc1(void* routine);
219+
void ets_install_putc1(fp_putc_t routine);
209220
void ets_isr_mask(int intr);
210221
void ets_isr_unmask(int intr);
211222
void ets_isr_attach(int intr, int_handler_t handler, void *arg);
212223
void ets_intr_lock();
213224
void ets_intr_unlock();
214225
int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg) __attribute__ ((format (printf, 3, 0)));
215-
int ets_vprintf(int (*print_function)(int), const char * format, va_list arg) __attribute__ ((format (printf, 2, 0)));
216-
int ets_putc(int);
226+
int ets_vprintf(fp_putc_t print_function, const char * format, va_list arg) __attribute__ ((format (printf, 2, 0)));
227+
228+
/*
229+
* ets_putc(), a "print character function" in ROM, prints a character to a
230+
* UART. It always returns 0; however, the prototype here is defined with void
231+
* return to make compatible with other usages of fp_putc_t. ets_putc() provides
232+
* a "raw", print as is, interface. '\r' and '\n' are each printed exactly as is
233+
* w/o addition. For a "cooked" interface use ets_uart_putc1().
234+
* The use of this function requires a prior setup call to uart_buff_switch() to
235+
* select the UART.
236+
*/
237+
void ets_putc(char);
238+
239+
/*
240+
* ets_uart_putc1(), a "print character function" in ROM, prints a character to
241+
* a UART. It returns the character printed; however, the prototype here is
242+
* defined with void return to make compatible with other usages of fp_putc_t.
243+
* This function provides additional processing to characters '\r' and '\n'. It
244+
* filters out '\r'. When called with '\n', it prints characters '\r' and '\n'.
245+
* This is sometimes refered to as a "cooked" interface. For a "raw", print as
246+
* is, interface use ets_putc(). The use of this function requires a prior setup
247+
* call to uart_buff_switch() to select the UART.
248+
* ets_uart_putc1() is used internally by ets_uart_printf. It is also the
249+
* function that gets installed by ets_uart_install_printf through a call to
250+
* ets_install_putc1.
251+
*/
252+
void ets_uart_putc1(char);
253+
217254
bool ets_task(ETSTask task, uint8 prio, ETSEvent *queue, uint8 qlen);
218255
bool ets_post(uint8 prio, ETSSignal sig, ETSParam par);
219256
void ets_update_cpu_frequency(uint32_t ticks_per_us);

tools/sdk/ld/eagle.flash.16m14m.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ PROVIDE ( _FS_end = 0x411FA000 );
1919
PROVIDE ( _FS_page = 0x100 );
2020
PROVIDE ( _FS_block = 0x2000 );
2121
PROVIDE ( _EEPROM_start = 0x411fb000 );
22+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
23+
PROVIDE ( _SPIFFS_start = 0x40400000 );
24+
PROVIDE ( _SPIFFS_end = 0x411FA000 );
25+
PROVIDE ( _SPIFFS_page = 0x100 );
26+
PROVIDE ( _SPIFFS_block = 0x2000 );
2227

2328
INCLUDE "local.eagle.app.v6.common.ld"

tools/sdk/ld/eagle.flash.16m15m.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ PROVIDE ( _FS_end = 0x411FA000 );
1919
PROVIDE ( _FS_page = 0x100 );
2020
PROVIDE ( _FS_block = 0x2000 );
2121
PROVIDE ( _EEPROM_start = 0x411fb000 );
22+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
23+
PROVIDE ( _SPIFFS_start = 0x40300000 );
24+
PROVIDE ( _SPIFFS_end = 0x411FA000 );
25+
PROVIDE ( _SPIFFS_page = 0x100 );
26+
PROVIDE ( _SPIFFS_block = 0x2000 );
2227

2328
INCLUDE "local.eagle.app.v6.common.ld"

tools/sdk/ld/eagle.flash.1m.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ PROVIDE ( _FS_end = 0x402FB000 );
1919
PROVIDE ( _FS_page = 0x0 );
2020
PROVIDE ( _FS_block = 0x0 );
2121
PROVIDE ( _EEPROM_start = 0x402fb000 );
22+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
23+
PROVIDE ( _SPIFFS_start = 0x402FB000 );
24+
PROVIDE ( _SPIFFS_end = 0x402FB000 );
25+
PROVIDE ( _SPIFFS_page = 0x0 );
26+
PROVIDE ( _SPIFFS_block = 0x0 );
2227

2328
INCLUDE "local.eagle.app.v6.common.ld"

tools/sdk/ld/eagle.flash.1m128.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ PROVIDE ( _FS_end = 0x402FB000 );
1919
PROVIDE ( _FS_page = 0x100 );
2020
PROVIDE ( _FS_block = 0x1000 );
2121
PROVIDE ( _EEPROM_start = 0x402fb000 );
22+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
23+
PROVIDE ( _SPIFFS_start = 0x402DB000 );
24+
PROVIDE ( _SPIFFS_end = 0x402FB000 );
25+
PROVIDE ( _SPIFFS_page = 0x100 );
26+
PROVIDE ( _SPIFFS_block = 0x1000 );
2227

2328
INCLUDE "local.eagle.app.v6.common.ld"

tools/sdk/ld/eagle.flash.1m144.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ PROVIDE ( _FS_end = 0x402FB000 );
1919
PROVIDE ( _FS_page = 0x100 );
2020
PROVIDE ( _FS_block = 0x1000 );
2121
PROVIDE ( _EEPROM_start = 0x402fb000 );
22+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
23+
PROVIDE ( _SPIFFS_start = 0x402D7000 );
24+
PROVIDE ( _SPIFFS_end = 0x402FB000 );
25+
PROVIDE ( _SPIFFS_page = 0x100 );
26+
PROVIDE ( _SPIFFS_block = 0x1000 );
2227

2328
INCLUDE "local.eagle.app.v6.common.ld"

tools/sdk/ld/eagle.flash.1m160.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ PROVIDE ( _FS_end = 0x402FB000 );
1919
PROVIDE ( _FS_page = 0x100 );
2020
PROVIDE ( _FS_block = 0x1000 );
2121
PROVIDE ( _EEPROM_start = 0x402fb000 );
22+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
23+
PROVIDE ( _SPIFFS_start = 0x402D3000 );
24+
PROVIDE ( _SPIFFS_end = 0x402FB000 );
25+
PROVIDE ( _SPIFFS_page = 0x100 );
26+
PROVIDE ( _SPIFFS_block = 0x1000 );
2227

2328
INCLUDE "local.eagle.app.v6.common.ld"

tools/sdk/ld/eagle.flash.1m192.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ PROVIDE ( _FS_end = 0x402FB000 );
1919
PROVIDE ( _FS_page = 0x100 );
2020
PROVIDE ( _FS_block = 0x1000 );
2121
PROVIDE ( _EEPROM_start = 0x402fb000 );
22+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
23+
PROVIDE ( _SPIFFS_start = 0x402CB000 );
24+
PROVIDE ( _SPIFFS_end = 0x402FB000 );
25+
PROVIDE ( _SPIFFS_page = 0x100 );
26+
PROVIDE ( _SPIFFS_block = 0x1000 );
2227

2328
INCLUDE "local.eagle.app.v6.common.ld"

0 commit comments

Comments
 (0)