Skip to content

Commit ad81a2e

Browse files
committed
minimal: Add ability and description to build without the compiler.
1 parent 3b2fd4d commit ad81a2e

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

minimal/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,15 @@ This version of the build will work out-of-the-box on a pyboard (and
3333
anything similar), and will give you a MicroPython REPL on UART1 at 9600
3434
baud. Pin PA13 will also be driven high, and this turns on the red LED on
3535
the pyboard.
36+
37+
## Building without the built-in MicroPython compiler
38+
39+
This minimal port can be built with the built-in MicroPython compiler
40+
disabled. This will reduce the firmware by about 20k on a Thumb2 machine,
41+
and by about 40k on 32-bit x86. Without the compiler the REPL will be
42+
disabled, but pre-compiled scripts can still be executed.
43+
44+
To test out this feature, change the `MICROPY_ENABLE_COMPILER` config
45+
option to "0" in the mpconfigport.h file in this directory. Then
46+
recompile and run the firmware and it will execute the frozentest.py
47+
file.

minimal/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "py/gc.h"
1010
#include "lib/utils/pyexec.h"
1111

12+
#if MICROPY_ENABLE_COMPILER
1213
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
1314
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
1415
if (lex == NULL) {
@@ -28,6 +29,7 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
2829
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
2930
}
3031
}
32+
#endif
3133

3234
static char *stack_top;
3335
static char heap[2048];
@@ -40,6 +42,7 @@ int main(int argc, char **argv) {
4042
gc_init(heap, heap + sizeof(heap));
4143
#endif
4244
mp_init();
45+
#if MICROPY_ENABLE_COMPILER
4346
#if MICROPY_REPL_EVENT_DRIVEN
4447
pyexec_event_repl_init();
4548
for (;;) {
@@ -53,6 +56,9 @@ int main(int argc, char **argv) {
5356
#endif
5457
//do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
5558
//do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT);
59+
#else
60+
pyexec_frozen_module("frozentest.py");
61+
#endif
5662
mp_deinit();
5763
return 0;
5864
}

minimal/mpconfigport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
// options to control how Micro Python is built
44

5+
// You can disable the built-in MicroPython compiler by setting the following
6+
// config option to 0. If you do this then you won't get a REPL prompt, but you
7+
// will still be able to execute pre-compiled scripts, compiled with mpy-cross.
8+
#define MICROPY_ENABLE_COMPILER (1)
9+
510
#define MICROPY_QSTR_BYTES_IN_HASH (1)
611
#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
712
#define MICROPY_ALLOC_PATH_MAX (256)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy