Makefile 4.33 KB
Newer Older
1
2
3
4
5
6
7
8
include ../py/mkenv.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h #$(BUILD)/pins_qstr.h

# include py core make definitions
include ../py/py.mk

9
10
11
MAKE_FROZEN = ../tools/make-frozen.py

SCRIPTDIR = scripts
12
PORT = /dev/ttyACM0
13
BAUD = 115200
14
CROSS_COMPILE = xtensa-lx106-elf-
15
ESP_SDK = $(shell $(CC) -print-sysroot)/usr
16

17
INC += -I.
18
INC += -I..
19
INC += -I../stmhal
20
INC += -I../lib/mp-readline
21
INC += -I../lib/netutils
22
INC += -I../lib/timeutils
23
24
25
INC += -I$(BUILD)
INC += -I$(ESP_SDK)/include

26
27
UART_OS = 1

28
29
30
31
32
CFLAGS_XTENSA = -fsingle-precision-constant -Wdouble-promotion \
	-D__ets__ -DICACHE_FLASH \
	-fno-inline-functions \
	-Wl,-EL -mlongcalls -mtext-section-literals \

33
34
CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib -DUART_OS=$(UART_OS) \
	$(CFLAGS_XTENSA) $(COPT)
35
36
37
38
39

LDFLAGS = -nostdlib -T esp8266.ld -Map=$(@:.elf=.map) --cref
LIBS = -L$(ESP_SDK)/lib -lmain -ljson -llwip -lpp -lnet80211 -lwpa -lphy -lnet80211

LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
40
LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
41
42
43
44
45
46
47
48
49
50
51
52

# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g
COPT = -O0
else
CFLAGS += -fdata-sections -ffunction-sections
COPT += -Os -DNDEBUG
LDFLAGS += --gc-sections
endif

SRC_C = \
53
	strtoll.c \
54
55
56
57
58
	main.c \
	esp_mphal.c \
	gccollect.c \
	uart.c \
	modpyb.c \
59
	modpybpin.c \
60
	modpybrtc.c \
Josef Gajdusek's avatar
Josef Gajdusek committed
61
	modpybadc.c \
62
	modesp.c \
63
	modnetwork.c \
64
	modutime.c \
Josef Gajdusek's avatar
Josef Gajdusek committed
65
	moduos.c \
66
	utils.c \
67
	$(BUILD)/frozen.c \
68
69
70

STM_SRC_C = $(addprefix stmhal/,\
	printf.c \
71
	pybstdio.c \
72
73
74
	)

LIB_SRC_C = $(addprefix lib/,\
75
	libc/string0.c \
76
	mp-readline/readline.c \
77
	netutils/netutils.c \
78
	timeutils/timeutils.c \
79
	utils/pyexec.c \
80
81
82
83
84
85
86
87
88
89
	)

SRC_S = \
	gchelper.s \

OBJ =
OBJ += $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
90
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
91
92
93
94
#OBJ += $(BUILD)/pins_$(BOARD).o

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

95
CONFVARS_FILE = $(BUILD)/confvars
96

97
ifeq ($(wildcard $(CONFVARS_FILE)),)
98
$(shell $(MKDIR) -p $(BUILD))
99
100
101
$(shell echo $(SCRIPTDIR) $(UART_OS) > $(CONFVARS_FILE))
else ifneq ($(shell cat $(CONFVARS_FILE)), $(SCRIPTDIR) $(UART_OS))
$(shell echo $(SCRIPTDIR) $(UART_OS) > $(CONFVARS_FILE))
102
103
endif

104
105
106
$(BUILD)/uart.o: $(CONFVARS_FILE)

$(BUILD)/frozen.c: $(wildcard $(SCRIPTDIR)/*) $(CONFVARS_FILE)
107
108
109
	$(ECHO) "Generating $@"
	$(Q)$(MAKE_FROZEN) $(SCRIPTDIR) > $@

110
111
112
113
.PHONY: deploy

deploy: $(BUILD)/firmware-combined.bin
	$(ECHO) "Writing $< to the board"
114
	#$(Q)esptool.py --port $(PORT) write_flash 0 $<
115
	$(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash 0 $(BUILD)/firmware.elf-0x00000.bin 0x10000 $(BUILD)/firmware.elf-0x10000.bin
116

117
118
119
reset:
	echo -e "\r\nimport pyb; pyb.hard_reset()\r\n" >$(PORT)

120
121
122
123
124
125
126
$(BUILD)/firmware-combined.bin: $(BUILD)/firmware.elf
	$(ECHO) "Create $@"
	$(Q)esptool.py elf2image $^
	$(Q)$(PYTHON) makeimg.py $(BUILD)/firmware.elf-0x00000.bin $(BUILD)/firmware.elf-0x10000.bin $@

$(BUILD)/firmware.elf: $(OBJ)
	$(ECHO) "LINK $@"
127
	$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
	$(Q)$(SIZE) $@

#MAKE_PINS = boards/make-pins.py
#BOARD_PINS = boards/$(BOARD)/pins.csv
#AF_FILE = boards/stm32f4xx_af.csv
#PREFIX_FILE = boards/stm32f4xx_prefix.c
#GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
#GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
#GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
#GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
#GEN_PINS_AF_PY = $(BUILD)/pins_af.py

# Making OBJ use an order-only depenedency on the generated pins.h file
# has the side effect of making the pins.h file before we actually compile
# any of the objects. The normal dependency generation will deal with the
# case when pins.h is modified. But when it doesn't exist, we don't know
# which source files might need it.
#$(OBJ): | $(HEADER_BUILD)/pins.h

# Use a pattern rule here so that make will only call make-pins.py once to make
# both pins_$(BOARD).c and pins.h
#$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
#	$(ECHO) "Create $@"
#	$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
#
#$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
#	$(call compile_c)

include ../py/mkrules.mk