| 1 |
include ../../py/mkenv.mk |
| 2 |
|
| 3 |
CROSS = 0 |
| 4 |
|
| 5 |
# qstr definitions (must come before including py.mk) |
| 6 |
QSTR_DEFS = qstrdefsport.h |
| 7 |
|
| 8 |
# MicroPython feature configurations |
| 9 |
MICROPY_ROM_TEXT_COMPRESSION ?= 1 |
| 10 |
|
| 11 |
# include py core make definitions |
| 12 |
include $(TOP)/py/py.mk |
| 13 |
|
| 14 |
ifeq ($(CROSS), 1) |
| 15 |
CROSS_COMPILE ?= arm-none-eabi- |
| 16 |
endif |
| 17 |
|
| 18 |
INC += -I. |
| 19 |
INC += -I$(TOP) |
| 20 |
INC += -I$(BUILD) |
| 21 |
|
| 22 |
ifeq ($(CROSS), 1) |
| 23 |
DFU = $(TOP)/tools/dfu.py |
| 24 |
PYDFU = $(TOP)/tools/pydfu.py |
| 25 |
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -fsingle-precision-constant -Wdouble-promotion -Wfloat-conversion |
| 26 |
CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) |
| 27 |
LDFLAGS += -nostdlib -T stm32f405.ld [email protected] --cref --gc-sections |
| 28 |
else |
| 29 |
UNAME_S := $(shell uname -s) |
| 30 |
LD = $(CC) |
| 31 |
CFLAGS += $(INC) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=c99 $(COPT) |
| 32 |
ifeq ($(UNAME_S),Linux) |
| 33 |
LDFLAGS += -Wl,[email protected],--cref -Wl,--gc-sections |
| 34 |
else ifeq ($(UNAME_S),Darwin) |
| 35 |
LDFLAGS += -Wl,-map,[email protected] -Wl,-dead_strip |
| 36 |
endif |
| 37 |
endif |
| 38 |
|
| 39 |
CSUPEROPT = -Os # save some code space |
| 40 |
|
| 41 |
# Tune for Debugging or Optimization |
| 42 |
CFLAGS += -g # always include debug info in the ELF |
| 43 |
ifeq ($(DEBUG), 1) |
| 44 |
CFLAGS += -O0 |
| 45 |
else |
| 46 |
CFLAGS += -Os -DNDEBUG |
| 47 |
CFLAGS += -fdata-sections -ffunction-sections |
| 48 |
endif |
| 49 |
|
| 50 |
# Flags for optional C++ source code |
| 51 |
CXXFLAGS += $(filter-out -std=c99,$(CFLAGS)) |
| 52 |
|
| 53 |
LIBS = |
| 54 |
|
| 55 |
SRC_C = \ |
| 56 |
main.c \ |
| 57 |
uart_core.c \ |
| 58 |
shared/libc/printf.c \ |
| 59 |
shared/readline/readline.c \ |
| 60 |
shared/runtime/pyexec.c \ |
| 61 |
shared/runtime/stdout_helpers.c \ |
| 62 |
$(BUILD)/_frozen_mpy.c \ |
| 63 |
|
| 64 |
ifeq ($(CROSS), 1) |
| 65 |
SRC_C += shared/libc/string0.c |
| 66 |
endif |
| 67 |
|
| 68 |
SRC_QSTR += shared/readline/readline.c shared/runtime/pyexec.c |
| 69 |
|
| 70 |
OBJ += $(PY_CORE_O) |
| 71 |
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) |
| 72 |
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o)) |
| 73 |
|
| 74 |
ifeq ($(CROSS), 1) |
| 75 |
all: $(BUILD)/firmware.dfu |
| 76 |
else |
| 77 |
all: $(BUILD)/firmware.elf |
| 78 |
endif |
| 79 |
|
| 80 |
$(BUILD)/_frozen_mpy.c: $(TOP)/tests/frozen/frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h |
| 81 |
$(ECHO) "MISC freezing bytecode" |
| 82 |
$(Q)$(TOP)/tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@ |
| 83 |
|
| 84 |
$(BUILD)/firmware.elf: $(OBJ) |
| 85 |
$(ECHO) "LINK $@" |
| 86 |
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS) |
| 87 |
$(Q)$(SIZE) $@ |
| 88 |
|
| 89 |
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf |
| 90 |
$(Q)$(OBJCOPY) -O binary -j .isr_vector -j .text -j .data $^ $(BUILD)/firmware.bin |
| 91 |
|
| 92 |
$(BUILD)/firmware.dfu: $(BUILD)/firmware.bin |
| 93 |
$(ECHO) "Create $@" |
| 94 |
$(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/firmware.bin $@ |
| 95 |
|
| 96 |
deploy: $(BUILD)/firmware.dfu |
| 97 |
$(ECHO) "Writing $< to the board" |
| 98 |
$(Q)$(PYTHON) $(PYDFU) -u $< |
| 99 |
|
| 100 |
# Run emulation build on a POSIX system with suitable terminal settings |
| 101 |
run: |
| 102 |
@saved_=`stty -g`; \ |
| 103 |
stty raw opost -echo; \ |
| 104 |
$(BUILD)/firmware.elf; \ |
| 105 |
echo "Exit status: $$?"; \ |
| 106 |
stty $$saved_ |
| 107 |
|
| 108 |
test: $(BUILD)/firmware.elf |
| 109 |
$(Q)/usr/bin/printf "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\004" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol" |
| 110 |
|
| 111 |
include $(TOP)/py/mkrules.mk |