Commit 53ea2b5c authored by Dave Hylands's avatar Dave Hylands Committed by Damien George
Browse files

teensy: Switch over to using frozen modules instead of memzip

I left memzip in for the time being, so you can choose in
the Makefile whether to USE_FROZEN or USE_MEMZIP.

It looks like using frozen saves about 2472 bytes (using my
set of 15 python files), mostly due to overheads in the
zip file format.
parent 074d713b
......@@ -74,6 +74,9 @@ endif
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -Wl,--gc-sections
USE_FROZEN = 1
USE_MEMZIP = 0
SRC_C = \
hal_ftm.c \
hal_gpio.c \
......@@ -81,9 +84,6 @@ SRC_C = \
main.c \
lcd.c \
led.c \
lib/memzip/import.c \
lib/memzip/lexermemzip.c \
lib/memzip/memzip.c \
modpyb.c \
pin_defs_teensy.c \
reg.c \
......@@ -92,7 +92,6 @@ SRC_C = \
uart.c \
usb.c \
STM_SRC_C = $(addprefix stmhal/,\
gccollect.c \
input.c \
......@@ -127,11 +126,55 @@ SRC_TEENSY = $(addprefix core/,\
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(STM_SRC_C:.c=.o) $(STM_SRC_S:.s=.o) $(SRC_TEENSY:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
OBJ += $(BUILD)/pins_gen.o
OBJ += $(BUILD)/memzip-files.o
all: hex
hex: $(BUILD)/micropython.hex
ifeq ($(USE_MEMZIP),1)
SRC_C += \
lib/memzip/import.c \
lib/memzip/lexermemzip.c \
lib/memzip/memzip.c \
OBJ += $(BUILD)/memzip-files.o
MAKE_MEMZIP = ../lib/memzip/make-memzip.py
ifeq ($(MEMZIP_DIR),)
MEMZIP_DIR = memzip_files
endif
$(BUILD)/memzip-files.o: $(BUILD)/memzip-files.c
$(call compile_c)
$(BUILD)/memzip-files.c: $(shell find ${MEMZIP_DIR} -type f)
@$(ECHO) "Creating $@"
$(Q)$(PYTHON) $(MAKE_MEMZIP) --zip-file $(BUILD)/memzip-files.zip --c-file $@ $(MEMZIP_DIR)
endif # USE_MEMZIP
ifeq ($(USE_FROZEN),1)
CFLAGS += -DMICROPY_MODULE_FROZEN
SRC_C += \
lexerfrozen.c
OBJ += $(BUILD)/frozen-files.o
MAKE_FROZEN = ../tools/make-frozen.py
ifeq ($(FROZEN_DIR),)
FROZEN_DIR = memzip_files
endif
$(BUILD)/frozen-files.o: $(BUILD)/frozen-files.c
$(call compile_c)
$(BUILD)/frozen-files.c: $(shell find ${FROZEN_DIR} -type f)
@$(ECHO) "Creating $@"
$(Q)$(PYTHON) $(MAKE_FROZEN) $(FROZEN_DIR) > $@
endif # USE_FROZEN
ifeq ($(ARDUINO),)
post_compile: $(BUILD)/micropython.hex
$(ECHO) "Please define ARDUINO (where TeensyDuino is installed)"
......@@ -161,16 +204,11 @@ $(BUILD)/micropython.elf: $(OBJ)
$(Q)$(CC) $(LDFLAGS) -o "$@" -Wl,-Map,$(@:.elf=.map) $^ $(LIBS)
$(Q)$(SIZE) $@
ifeq ($(MEMZIP_DIR),)
MEMZIP_DIR = memzip_files
endif
$(BUILD)/%.hex: $(BUILD)/%.elf
$(ECHO) "HEX $<"
$(Q)$(OBJCOPY) -O ihex -R .eeprom "$<" "$@"
MAKE_PINS = make-pins.py
MAKE_MEMZIP = ../lib/memzip/make-memzip.py
BOARD_PINS = teensy_pins.csv
AF_FILE = mk20dx256_af.csv
PREFIX_FILE = mk20dx256_prefix.c
......@@ -196,13 +234,6 @@ $(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qst
$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
$(call compile_c)
$(BUILD)/memzip-files.o: $(BUILD)/memzip-files.c
$(call compile_c)
$(BUILD)/memzip-files.c: $(shell find ${MEMZIP_DIR} -type f)
@$(ECHO) "Creating $@"
$(Q)$(PYTHON) $(MAKE_MEMZIP) --zip-file $(BUILD)/memzip-files.zip --c-file $@ $(MEMZIP_DIR)
$(BUILD)/%.pp: $(BUILD)/%.c
$(ECHO) "PreProcess $<"
$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<
......
#include <stdio.h>
#include "py/lexer.h"
mp_import_stat_t mp_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
return NULL;
}
......@@ -22,6 +22,10 @@
#include "uart.h"
#include "pin.h"
#if MICROPY_MODULE_FROZEN
#include "py/compile.h"
#include "py/frozenmod.h"
#endif
extern uint32_t _heap_start;
......@@ -301,14 +305,27 @@ soft_reset:
}
#endif
#if MICROPY_MODULE_FROZEN
{
mp_lexer_t *lex = mp_find_frozen_module("boot", 4);
mp_parse_compile_execute(lex, MP_PARSE_FILE_INPUT, mp_globals_get(), mp_locals_get());
}
#else
if (!pyexec_file("/boot.py")) {
flash_error(4);
}
#endif
// Turn bootup LED off
led_state(PYB_LED_BUILTIN, 0);
// run main script
#if MICROPY_MODULE_FROZEN
{
mp_lexer_t *lex = mp_find_frozen_module("main", 4);
mp_parse_compile_execute(lex, MP_PARSE_FILE_INPUT, mp_globals_get(), mp_locals_get());
}
#else
{
vstr_t *vstr = vstr_new();
vstr_add_str(vstr, "/");
......@@ -322,6 +339,7 @@ soft_reset:
}
vstr_free(vstr);
}
#endif
// enter REPL
// REPL mode can change, or it can request a soft reset
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment