Skip to content

Commit bda7041

Browse files
atxdpgeorge
authored andcommitted
esp8266: Add support for frozen modules
1 parent d39d96b commit bda7041

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

esp8266/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ QSTR_DEFS = qstrdefsport.h #$(BUILD)/pins_qstr.h
66
# include py core make definitions
77
include ../py/py.mk
88

9+
MAKE_FROZEN = ../tools/make-frozen.py
10+
11+
SCRIPTDIR = scripts
912
PORT = /dev/ttyACM0
1013
CROSS_COMPILE = xtensa-lx106-elf-
1114
ESP_SDK = $(shell $(CC) -print-sysroot)/usr
@@ -51,6 +54,7 @@ SRC_C = \
5154
modpybpin.c \
5255
modesp.c \
5356
utils.c \
57+
$(BUILD)/frozen.c \
5458

5559
STM_SRC_C = $(addprefix stmhal/,\
5660
printf.c \
@@ -77,6 +81,19 @@ OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
7781

7882
all: $(BUILD)/firmware-combined.bin
7983

84+
SCRIPTDIR_FILE = $(BUILD)/scriptdir
85+
86+
ifeq ($(wildcard $(SCRIPTDIR_FILE)),)
87+
$(shell $(MKDIR) -p $(BUILD))
88+
$(shell echo $(SCRIPTDIR) > $(SCRIPTDIR_FILE))
89+
else ifneq ($(shell cat $(SCRIPTDIR_FILE)), $(SCRIPTDIR))
90+
$(shell echo $(SCRIPTDIR) > $(SCRIPTDIR_FILE))
91+
endif
92+
93+
$(BUILD)/frozen.c: $(wildcard $(SCRIPTDIR)/*) $(SCRIPTDIR_FILE)
94+
$(ECHO) "Generating $@"
95+
$(Q)$(MAKE_FROZEN) $(SCRIPTDIR) > $@
96+
8097
.PHONY: deploy
8198

8299
deploy: $(BUILD)/firmware-combined.bin

esp8266/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/runtime0.h"
3333
#include "py/runtime.h"
3434
#include "py/stackctrl.h"
35+
#include "py/frozenmod.h"
3536
#include "py/gc.h"
3637
#include "pyexec.h"
3738
#include "gccollect.h"
@@ -46,6 +47,10 @@ STATIC void mp_reset(void) {
4647
mp_init();
4748
mp_obj_list_init(mp_sys_path, 0);
4849
mp_obj_list_init(mp_sys_argv, 0);
50+
#if MICROPY_MODULE_FROZEN
51+
mp_lexer_t *lex = mp_find_frozen_module("main", 4);
52+
mp_parse_compile_execute(lex, MP_PARSE_FILE_INPUT, mp_globals_get(), mp_locals_get());
53+
#endif
4954
}
5055

5156
void soft_reset(void) {

esp8266/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
3737
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
3838
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
39+
#define MICROPY_MODULE_FROZEN (1)
3940

4041
// type definitions for the specific machine
4142

esp8266/scripts/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This script is run on boot

0 commit comments

Comments
 (0)