diff options
Diffstat (limited to 'minimal')
-rw-r--r-- | minimal/Makefile | 5 | ||||
-rw-r--r-- | minimal/README.md | 12 | ||||
-rw-r--r-- | minimal/frozentest.mpy | bin | 255 -> 255 bytes | |||
-rw-r--r-- | minimal/main.c | 21 | ||||
-rw-r--r-- | minimal/mpconfigport.h | 7 |
5 files changed, 31 insertions, 14 deletions
diff --git a/minimal/Makefile b/minimal/Makefile index 411751735..d61515797 100644 --- a/minimal/Makefile +++ b/minimal/Makefile @@ -14,7 +14,6 @@ endif INC += -I. INC += -I.. -INC += -I../lib/mp-readline INC += -I../stmhal INC += -I$(BUILD) @@ -22,9 +21,9 @@ ifeq ($(CROSS), 1) DFU = ../tools/dfu.py PYDFU = ../tools/pydfu.py CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion -CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) +CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) else -CFLAGS = -m32 $(INC) -Wall -Werror -ansi -std=gnu99 $(COPT) +CFLAGS = -m32 $(INC) -Wall -Werror -std=c99 $(COPT) endif #Debugging/Optimization diff --git a/minimal/README.md b/minimal/README.md index 7c42e082e..14b8c00a3 100644 --- a/minimal/README.md +++ b/minimal/README.md @@ -33,3 +33,15 @@ This version of the build will work out-of-the-box on a pyboard (and anything similar), and will give you a MicroPython REPL on UART1 at 9600 baud. Pin PA13 will also be driven high, and this turns on the red LED on the pyboard. + +## Building without the built-in MicroPython compiler + +This minimal port can be built with the built-in MicroPython compiler +disabled. This will reduce the firmware by about 20k on a Thumb2 machine, +and by about 40k on 32-bit x86. Without the compiler the REPL will be +disabled, but pre-compiled scripts can still be executed. + +To test out this feature, change the `MICROPY_ENABLE_COMPILER` config +option to "0" in the mpconfigport.h file in this directory. Then +recompile and run the firmware and it will execute the frozentest.py +file. diff --git a/minimal/frozentest.mpy b/minimal/frozentest.mpy Binary files differindex c8345b191..87f9581bf 100644 --- a/minimal/frozentest.mpy +++ b/minimal/frozentest.mpy diff --git a/minimal/main.c b/minimal/main.c index 5e104e7e8..114fb9695 100644 --- a/minimal/main.c +++ b/minimal/main.c @@ -7,17 +7,14 @@ #include "py/runtime.h" #include "py/repl.h" #include "py/gc.h" +#include "py/mperrno.h" #include "lib/utils/pyexec.h" +#if MICROPY_ENABLE_COMPILER void do_str(const char *src, mp_parse_input_kind_t input_kind) { - mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); - if (lex == NULL) { - printf("MemoryError: lexer could not allocate memory\n"); - return; - } - nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { + mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); qstr source_name = lex->source_name; mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true); @@ -28,6 +25,7 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) { mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); } } +#endif static char *stack_top; static char heap[2048]; @@ -40,6 +38,7 @@ int main(int argc, char **argv) { gc_init(heap, heap + sizeof(heap)); #endif mp_init(); + #if MICROPY_ENABLE_COMPILER #if MICROPY_REPL_EVENT_DRIVEN pyexec_event_repl_init(); for (;;) { @@ -53,6 +52,9 @@ int main(int argc, char **argv) { #endif //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); //do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT); + #else + pyexec_frozen_module("frozentest.py"); + #endif mp_deinit(); return 0; } @@ -68,7 +70,7 @@ void gc_collect(void) { } mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return NULL; + mp_raise_OSError(MP_ENOENT); } mp_import_stat_t mp_import_stat(const char *path) { @@ -81,6 +83,7 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); void nlr_jump_fail(void *val) { + while (1); } void NORETURN __fatal_error(const char *msg) { @@ -103,7 +106,7 @@ extern uint32_t _estack, _sidata, _sdata, _edata, _sbss, _ebss; void Reset_Handler(void) __attribute__((naked)); void Reset_Handler(void) { // set stack pointer - asm volatile ("ldr sp, =_estack"); + __asm volatile ("ldr sp, =_estack"); // copy .data section from flash to RAM for (uint32_t *src = &_sidata, *dest = &_sdata; dest < &_edata;) { *dest++ = *src++; @@ -122,7 +125,7 @@ void Default_Handler(void) { } } -uint32_t isr_vector[] __attribute__((section(".isr_vector"))) = { +const uint32_t isr_vector[] __attribute__((section(".isr_vector"))) = { (uint32_t)&_estack, (uint32_t)&Reset_Handler, (uint32_t)&Default_Handler, // NMI_Handler diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h index 5236babf6..47fc98429 100644 --- a/minimal/mpconfigport.h +++ b/minimal/mpconfigport.h @@ -2,6 +2,11 @@ // options to control how Micro Python is built +// You can disable the built-in MicroPython compiler by setting the following +// config option to 0. If you do this then you won't get a REPL prompt, but you +// will still be able to execute pre-compiled scripts, compiled with mpy-cross. +#define MICROPY_ENABLE_COMPILER (1) + #define MICROPY_QSTR_BYTES_IN_HASH (1) #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_ALLOC_PATH_MAX (256) @@ -52,8 +57,6 @@ // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) // This port is intended to be 32-bit, but unfortunately, int32_t for |