Skip to content

Commit 28253c5

Browse files
d-a-vdevyte
authored andcommitted
boards.txt generator (#3722)
+ generates boards.rst + generate and replace boards section in package.json + generate ldscripts + new debug option: OOM + new led menu for generic board
1 parent 4b319d9 commit 28253c5

File tree

8 files changed

+1769
-152
lines changed

8 files changed

+1769
-152
lines changed

boards.txt

+214-98
Large diffs are not rendered by default.

cores/esp8266/Arduino.h

+6
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,9 @@ extern "C" void configTime(long timezone, int daylightOffset_sec,
283283
#include "pins_arduino.h"
284284

285285
#endif
286+
287+
#ifdef DEBUG_ESP_OOM
288+
// reinclude *alloc redefinition because of <cstdlib> undefining them
289+
// this is mandatory for allowing OOM *alloc definitions in .ino files
290+
#include "umm_malloc/umm_malloc_cfg.h"
291+
#endif

cores/esp8266/heap.c

+93-4
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,105 @@ void* _calloc_r(struct _reent* unused, size_t count, size_t size)
3232
return calloc(count, size);
3333
}
3434

35-
void* ICACHE_RAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
35+
void ICACHE_RAM_ATTR vPortFree(void *ptr, const char* file, int line)
3636
{
3737
(void) file;
3838
(void) line;
39-
return malloc(size);
39+
free(ptr);
4040
}
4141

42-
void ICACHE_RAM_ATTR vPortFree(void *ptr, const char* file, int line)
42+
#ifdef DEBUG_ESP_OOM
43+
44+
void* ICACHE_RAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
45+
{
46+
return malloc_loc(size, file, line);
47+
}
48+
49+
void* ICACHE_RAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
50+
{
51+
return calloc_loc(count, size, file, line);
52+
}
53+
54+
void* ICACHE_RAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
55+
{
56+
return realloc_loc(ptr, size, file, line);
57+
}
58+
59+
void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
60+
{
61+
return calloc_loc(1, size, file, line);
62+
}
63+
64+
#undef malloc
65+
#undef calloc
66+
#undef realloc
67+
68+
static const char oom_fmt[] ICACHE_RODATA_ATTR STORE_ATTR = ":oom(%d)@?\n";
69+
static const char oom_fmt_1[] ICACHE_RODATA_ATTR STORE_ATTR = ":oom(%d)@";
70+
static const char oom_fmt_2[] ICACHE_RODATA_ATTR STORE_ATTR = ":%d\n";
71+
72+
void* malloc (size_t s)
73+
{
74+
void* ret = umm_malloc(s);
75+
if (!ret)
76+
os_printf(oom_fmt, (int)s);
77+
return ret;
78+
}
79+
80+
void* calloc (size_t n, size_t s)
81+
{
82+
void* ret = umm_calloc(n, s);
83+
if (!ret)
84+
os_printf(oom_fmt, (int)s);
85+
return ret;
86+
}
87+
88+
void* realloc (void* p, size_t s)
89+
{
90+
void* ret = umm_realloc(p, s);
91+
if (!ret)
92+
os_printf(oom_fmt, (int)s);
93+
return ret;
94+
}
95+
96+
void print_loc (size_t s, const char* file, int line)
97+
{
98+
os_printf(oom_fmt_1, (int)s);
99+
os_printf(file);
100+
os_printf(oom_fmt_2, line);
101+
}
102+
103+
void* malloc_loc (size_t s, const char* file, int line)
104+
{
105+
void* ret = umm_malloc(s);
106+
if (!ret)
107+
print_loc(s, file, line);
108+
return ret;
109+
}
110+
111+
void* calloc_loc (size_t n, size_t s, const char* file, int line)
112+
{
113+
void* ret = umm_calloc(n, s);
114+
if (!ret)
115+
print_loc(s, file, line);
116+
return ret;
117+
}
118+
119+
void* realloc_loc (void* p, size_t s, const char* file, int line)
120+
{
121+
void* ret = umm_realloc(p, s);
122+
if (!ret)
123+
print_loc(s, file, line);
124+
return ret;
125+
}
126+
127+
#else
128+
129+
void* ICACHE_RAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
43130
{
44131
(void) file;
45132
(void) line;
46-
free(ptr);
133+
return malloc(size);
47134
}
48135

49136
void* ICACHE_RAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
@@ -67,6 +154,8 @@ void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
67154
return calloc(1, size);
68155
}
69156

157+
#endif // !defined(DEBUG_ESP_OOM)
158+
70159
size_t xPortGetFreeHeapSize(void)
71160
{
72161
return umm_free_heap_size();

cores/esp8266/umm_malloc/umm_malloc_cfg.h

+57-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
* Configuration for umm_malloc
33
*/
44

5+
// with DEBUG_ESP_OOM debug option activated,
6+
// implying gcc option '-include this-file'
7+
// this file is included in *every* source file
8+
// *before* any other include file
9+
10+
#ifndef __ASSEMBLER__
11+
512
#ifndef _UMM_MALLOC_CFG_H
613
#define _UMM_MALLOC_CFG_H
714

815
#include <debug.h>
9-
//#ifdef __cplusplus
10-
//extern "C" {
11-
//#endif
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
#include <stdlib.h>
21+
#include <osapi.h>
22+
1223
#include "c_types.h"
13-
//#ifdef __cplusplus
14-
//}
15-
//#endif
1624
/*
1725
* There are a number of defines you can set at compile time that affect how
1826
* the memory allocator will operate.
@@ -59,8 +67,34 @@
5967
* ----------------------------------------------------------------------------
6068
*/
6169

70+
/////////////////////////////////////////////////
71+
#ifdef DEBUG_ESP_OOM
72+
73+
#define MEMLEAK_DEBUG
74+
75+
// umm_*alloc are not renamed to *alloc
76+
77+
void *umm_malloc( size_t size );
78+
void *umm_calloc( size_t num, size_t size );
79+
void *umm_realloc( void *ptr, size_t size );
80+
#define umm_free free
81+
#define umm_zalloc(s) umm_calloc(1,s)
82+
83+
void* malloc_loc (size_t s, const char* file, int line);
84+
void* calloc_loc (size_t n, size_t s, const char* file, int line);
85+
void* realloc_loc (void* p, size_t s, const char* file, int line);
86+
87+
// *alloc are macro calling *alloc_loc calling+checking umm_*alloc()
88+
// they are defined at the bottom of this file
89+
90+
/////////////////////////////////////////////////
91+
#else // !defined(ESP_DEBUG_OOM)
92+
93+
// umm_*alloc are renamed to *alloc
6294
#define UMM_REDEFINE_MEM_FUNCTIONS
6395

96+
#endif
97+
6498
#define UMM_BEST_FIT
6599

66100
/* Start addresses and the size of the heap */
@@ -140,4 +174,21 @@ extern char _heap_start;
140174
#define UMM_POISONED_BLOCK_LEN_TYPE uint32_t
141175

142176
#define UMM_HEAP_CORRUPTION_CB() panic()
177+
178+
#ifdef __cplusplus
179+
}
180+
#endif
181+
143182
#endif /* _UMM_MALLOC_CFG_H */
183+
184+
#ifdef DEBUG_ESP_OOM
185+
// this must be outside from "#ifndef _UMM_MALLOC_CFG_H"
186+
// because Arduino.h's <cstdlib> does #undef *alloc
187+
// so Arduino.h recall us to redefine them
188+
#define malloc(s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; malloc_loc(s, mem_debug_file, __LINE__); })
189+
#define calloc(n,s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; calloc_loc(n, s, mem_debug_file, __LINE__); })
190+
#define realloc(p,s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; realloc_loc(p, s, mem_debug_file, __LINE__); })
191+
192+
#endif
193+
194+
#endif /* !__ASSEMBLER__ */

platform.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ build.lwip_lib=-llwip_gcc
2121
build.lwip_include=lwip/include
2222
build.lwip_flags=-DLWIP_OPEN_SRC
2323

24+
build.led=
25+
2426
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
2527
compiler.sdk.path={runtime.platform.path}/tools/sdk
2628
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
@@ -72,13 +74,13 @@ recipe.hooks.core.prebuild.1.pattern=bash -c "mkdir -p {build.path}/core && echo
7274
recipe.hooks.core.prebuild.1.pattern.windows=
7375

7476
## Compile c files
75-
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
77+
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
7678

7779
## Compile c++ files
78-
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
80+
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
7981

8082
## Compile S files
81-
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
83+
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
8284

8385
## Create archives
8486
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"

0 commit comments

Comments
 (0)