8000 Use less free stack, more heap. This lets us claim a whole kilobyte b… · davidgiven/micropython@d39b4db · GitHub
[go: up one dir, main page]

Skip to content

Commit d39b4db

Browse files
committed
Use less free stack, more heap. This lets us claim a whole kilobyte back from
the C stack.
1 parent f17124b commit d39b4db

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

ports/tc32/gccollect.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
#include "py/gc.h"
2828
#include "py/mpthread.h"
2929
#include "shared/runtime/gchelper.h"
30-
// #include "shared/runtime/softtimer.h"
3130

3231
void gc_collect(void) {
32+
/* Check the flag byte to make sure the stack isn't corrupted. */
33+
if (*(uint8_t*)0x80bc00 != 42)
34+
mp_printf(&mp_plat_print, "mpy: stack corrupted! About to crash!\n");
35+
3336
// start the GC
3437
gc_collect_start();
3538

@@ -41,9 +44,6 @@ void gc_collect(void) {
4144
mp_thread_gc_others();
4245
#endif
4346

44-
// trace soft timer nodes
45-
// soft_timer_gc_mark_all();
46-
4747
// end the GC
4848
gc_collect_end();
4949
}

ports/tc32/main.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ MP_NOINLINE static void hard_init() {
7272
MP_NOINLINE static void soft_init() {
7373

7474
/* The Telink SDK doesn't define any symbols for these, so we just hard code
75-
* it. The stack starts at the end of memory, 0x80c000. We leave 2kB for it,
76-
* meaning that our heap needs to end at 0x80b800. */
77-
gc_init((void *)&_end_bss_, (void *)0x80b800);
75+
* it. The stack starts at the end of memory, 0x80c000. We leave 1kB for it,
76+
* meaning that our heap needs to end at 0x80bc00. */
77+
gc_init((void *)&_end_bss_, (void *)0x80bc00);
78+
79+
/* Set up the stack corruption flag byte. */
80+
*(uint8_t*)0x80bc00 = 42;
81+
7882
mp_init();
7983
machine_init();
8084
}

ports/tc32/mpconfigport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
#define MICROPY_DEBUG_PRINTERS (0)
1919
#define MICROPY_ENABLE_FINALISER (1)
2020
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
21+
#define MICROPY_STACKLESS (1)
2122

2223
// This doesn't work. Maybe Telink's floating point emulation is broken.
23-
// #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
24+
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
2425

2526
#define MICROPY_PY_MACHINE (1)
2627
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/tc32/modmachine.c"

0 commit comments

Comments
 (0)
0