Skip to content

Commit 1079f94

Browse files
authored
Merge pull request #905 from jepler/main-stack-usage
main: move code pertaining to boot.py out of line
2 parents aa63684 + 654591e commit 1079f94

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

main.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -233,40 +233,7 @@ bool start_mp(safe_mode_t safe_mode) {
233233
}
234234
}
235235

236-
int __attribute__((used)) main(void) {
237-
// initialise the cpu and peripherals
238-
safe_mode_t safe_mode = port_init();
239-
240-
rgb_led_status_init();
241-
242-
// Stack limit should be less than real stack size, so we have a chance
243-
// to recover from limit hit. (Limit is measured in bytes.)
244-
mp_stack_set_top((char*)&_estack);
245-
mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024);
246-
247-
#if MICROPY_MAX_STACK_USAGE
248-
// _ezero (same as _ebss) is an int, so start 4 bytes above it.
249-
mp_stack_set_bottom(&_ezero + 1);
250-
mp_stack_fill_with_sentinel();
251-
#endif
252-
253-
// Create a new filesystem only if we're not in a safe mode.
254-
// A power brownout here could make it appear as if there's
255-
// no SPI flash filesystem, and we might erase the existing one.
256-
filesystem_init(safe_mode == NO_SAFE_MODE, false);
257-
258-
// Reset everything and prep MicroPython to run boot.py.
259-
reset_port();
260-
reset_board();
261-
reset_mp();
262-
263-
// Turn on autoreload by default but before boot.py in case it wants to change it.
264-
autoreload_enable();
265-
266-
// By default our internal flash is readonly to local python code and
267-
// writable over USB. Set it here so that boot.py can change it.
268-
filesystem_writable_by_python(false);
269-
236+
void run_boot_py(safe_mode_t safe_mode) {
270237
// If not in safe mode, run boot before initing USB and capture output in a
271238
// file.
272239
if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) {
@@ -338,6 +305,43 @@ int __attribute__((used)) main(void) {
338305
reset_port();
339306
reset_mp();
340307
}
308+
}
309+
310+
int __attribute__((used)) main(void) {
311+
// initialise the cpu and peripherals
312+
safe_mode_t safe_mode = port_init();
313+
314+
rgb_led_status_init();
315+
316+
// Stack limit should be less than real stack size, so we have a chance
317+
// to recover from limit hit. (Limit is measured in bytes.)
318+
mp_stack_set_top((char*)&_estack);
319+
mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024);
320+
321+
#if MICROPY_MAX_STACK_USAGE
322+
// _ezero (same as _ebss) is an int, so start 4 bytes above it.
323+
mp_stack_set_bottom(&_ezero + 1);
324+
mp_stack_fill_with_sentinel();
325+
#endif
326+
327+
// Create a new filesystem only if we're not in a safe mode.
328+
// A power brownout here could make it appear as if there's
329+
// no SPI flash filesystem, and we might erase the existing one.
330+
filesystem_init(safe_mode == NO_SAFE_MODE, false);
331+
332+
// Reset everything and prep MicroPython to run boot.py.
333+
reset_port();
334+
reset_board();
335+
reset_mp();
336+
337+
// Turn on autoreload by default but before boot.py in case it wants to change it.
338+
autoreload_enable();
339+
340+
// By default our internal flash is readonly to local python code and
341+
// writable over USB. Set it here so that boot.py can change it.
342+
filesystem_writable_by_python(false);
343+
344+
run_boot_py(safe_mode);
341345

342346
// Start serial and HID after giving boot.py a chance to tweak behavior.
343347
serial_init();

0 commit comments

Comments
 (0)