Skip to content

Commit 324576f

Browse files
author
Me No Dev
committed
Merge remote-tracking branch 'esp8266/master'
2 parents 20f372a + 56a3733 commit 324576f

Some content is hidden

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

44 files changed

+2180
-687
lines changed

cores/esp8266/Esp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ uint32_t EspClass::getFlashChipSizeByChipId(void) {
283283
case 0x1340EF: // W25Q40
284284
return (512_kB);
285285

286+
// BergMicro
287+
case 0x1640E0: // BG25Q32
288+
return (4_MB);
289+
case 0x1540E0: // BG25Q16
290+
return (2_MB);
291+
case 0x1440E0: // BG25Q80
292+
return (1_MB);
293+
case 0x1340E0: // BG25Q40
294+
return (512_kB);
295+
286296
default:
287297
return 0;
288298
}

cores/esp8266/StreamString.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
StreamString.cpp
3+
4+
Copyright (c) 2015 Markus Sattler. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
21+
*/
22+
23+
#include <Arduino.h>
24+
#include "StreamString.h"
25+
26+
size_t StreamString::write(const uint8_t *buffer, size_t size) {
27+
if(reserve(length() + size + 1)) {
28+
for(size_t i = 0; i < size; i++) {
29+
if(write(*buffer)) {
30+
buffer++;
31+
} else {
32+
return i;
33+
}
34+
}
35+
36+
}
37+
return 0;
38+
}
39+
40+
size_t StreamString::write(uint8_t data) {
41+
return concat((char) data);
42+
}
43+
44+
int StreamString::available() {
45+
return length();
46+
}
47+
48+
int StreamString::read() {
49+
if(length()) {
50+
char c = charAt(0);
51+
remove(0, 1);
52+
return c;
53+
54+
}
55+
return -1;
56+
}
57+
58+
int StreamString::peek() {
59+
if(length()) {
60+
char c = charAt(0);
61+
return c;
62+
}
63+
return -1;
64+
}
65+
66+
void StreamString::flush() {
67+
}
68+

cores/esp8266/StreamString.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
StreamString.h
3+
4+
Copyright (c) 2015 Markus Sattler. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
21+
*/
22+
23+
#ifndef STREAMSTRING_H_
24+
#define STREAMSTRING_H_
25+
26+
27+
class StreamString: public Stream, public String {
28+
29+
size_t write(const uint8_t *buffer, size_t size);
30+
size_t write(uint8_t data);
31+
32+
int available();
33+
int read();
34+
int peek();
35+
void flush();
36+
37+
};
38+
39+
40+
#endif /* STREAMSTRING_H_ */

cores/esp8266/abi.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
*/
1818

1919
#include <stdlib.h>
20+
#include <assert.h>
21+
#include <debug.h>
2022
extern "C" {
2123
#include "ets_sys.h"
2224
#include "os_type.h"
2325
#include "osapi.h"
2426
#include "mem.h"
25-
#include "user_interface.h"
2627
}
2728

29+
2830
void *operator new(size_t size) {
2931
size = ((size + 3) & ~((size_t)0x3));
3032
return os_malloc(size);
@@ -47,27 +49,26 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
4749
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
4850

4951
void __cxa_pure_virtual(void) {
50-
abort();
52+
panic();
5153
}
5254

5355
void __cxa_deleted_virtual(void) {
54-
abort();
56+
panic();
5557
}
5658

5759
namespace std {
5860
void __throw_bad_function_call() {
59-
abort();
61+
panic();
6062
}
6163

6264
void __throw_length_error(char const*) {
63-
abort();
65+
panic();
6466
}
6567

6668
void __throw_bad_alloc() {
67-
abort();
69+
panic();
6870
}
6971
}
7072

7173
// TODO: rebuild windows toolchain to make this unnecessary:
7274
void* __dso_handle;
73-

cores/esp8266/core_esp8266_main.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
6666

6767
static uint32_t g_micros_at_task_start;
6868

69-
70-
extern "C" void abort() {
71-
do {
72-
*((int*)0) = 0;
73-
} while(true);
74-
}
75-
7669
extern "C" void esp_yield() {
7770
if (cont_can_yield(&g_cont)) {
7871
cont_yield(&g_cont);
@@ -89,7 +82,7 @@ extern "C" void __yield() {
8982
esp_yield();
9083
}
9184
else {
92-
abort();
85+
panic();
9386
}
9487
}
9588

@@ -117,9 +110,8 @@ static void loop_wrapper() {
117110
static void loop_task(os_event_t *events) {
118111
g_micros_at_task_start = system_get_time();
119112
cont_run(&g_cont, &loop_wrapper);
120-
if(cont_check(&g_cont) != 0) {
121-
ets_printf("\r\nsketch stack overflow detected\r\n");
122-
abort();
113+
if (cont_check(&g_cont) != 0) {
114+
panic();
123115
}
124116
}
125117

cores/esp8266/core_esp8266_postmortem.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stdint.h>
2323
#include <stddef.h>
2424
#include <stdbool.h>
25+
#include "debug.h"
2526
#include "ets_sys.h"
2627
#include "user_interface.h"
2728
#include "esp8266_peri.h"
@@ -30,6 +31,11 @@
3031
extern void __real_system_restart_local();
3132
extern cont_t g_cont;
3233

34+
static const char* s_panic_file = 0;
35+
static int s_panic_line = 0;
36+
static const char* s_panic_func = 0;
37+
38+
static bool s_abort_called = false;
3339

3440
void uart_write_char_d(char c);
3541
static void uart0_write_char_d(char c);
@@ -56,7 +62,13 @@ void __wrap_system_restart_local() {
5662

5763
ets_install_putc1(&uart_write_char_d);
5864

59-
if (rst_info.reason == REASON_EXCEPTION_RST) {
65+
if (s_panic_line) {
66+
ets_printf("\nPanic %s:%d %s\n", s_panic_file, s_panic_line, s_panic_func);
67+
}
68+
else if (s_abort_called) {
69+
ets_printf("Abort called\n");
70+
}
71+
else if (rst_info.reason == REASON_EXCEPTION_RST) {
6072
ets_printf("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
6173
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
6274
}
@@ -158,3 +170,25 @@ static void uart1_write_char_d(char c) {
158170
}
159171
USF(1) = c;
160172
}
173+
void abort() __attribute__((noreturn));
174+
175+
void abort(){
176+
// cause exception
177+
s_abort_called = true;
178+
do {
179+
*((int*)0) = 0;
180+
} while(true);
181+
}
182+
183+
void __assert_func(const char *file, int line, const char *func, const char *what) {
184+
s_panic_file = file;
185+
s_panic_line = line;
186+
s_panic_func = func;
187+
}
188+
189+
void __panic_func(const char* file, int line, const char* func) {
190+
s_panic_file = file;
191+
s_panic_line = line;
192+
s_panic_func = func;
193+
abort();
194+
}

cores/esp8266/debug.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define ARD_DEBUG_H
33

44
#include <stddef.h>
5+
#include <stdint.h>
6+
57
//#define DEBUGV(...) ets_printf(__VA_ARGS__)
68

79
#ifndef DEBUGV
@@ -14,4 +16,16 @@ void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16);
1416
void hexdump(uint8_t *mem, uint32_t len, uint8_t cols);
1517
#endif
1618

19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn));
24+
#define panic() __panic_func(__FILE__, __LINE__, __func__)
25+
26+
#ifdef __cplusplus
27+
}
28+
#endif
29+
30+
1731
#endif//ARD_DEBUG_H

cores/esp8266/time.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ int gettimeofday(struct timeval *tp, void *tzp)
124124
tp->tv_sec = (s_bootTime + millis()) / 1000;
125125
tp->tv_usec = micros() * 1000;
126126
}
127+
return 0;
127128
}

0 commit comments

Comments
 (0)