Makefile 5.91 KB
Newer Older
1
2
3
4
5
include ../py/mkenv.mk

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

6
7
MICROPY_PY_USSL = 1

8
9
10
# include py core make definitions
include ../py/py.mk

11
12
13
MAKE_FROZEN = ../tools/make-frozen.py

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

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

28
# UART for "os" messages. 0 is normal UART as used by MicroPython REPL,
29
# 1 is debug UART (tx only), -1 to disable.
30
UART_OS = 0
31

32
33
34
CFLAGS_XTENSA = -fsingle-precision-constant -Wdouble-promotion \
	-D__ets__ -DICACHE_FLASH \
	-fno-inline-functions \
35
	-Wl,-EL -mlongcalls -mtext-section-literals -mforce-l32 \
36
	-DLWIP_OPEN_SRC
37

38
CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib -DUART_OS=$(UART_OS) \
39
	$(CFLAGS_XTENSA) $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
40
41

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

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

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

SRC_C = \
58
	strtoll.c \
59
	main.c \
60
	help.c \
61
62
	esp_mphal.c \
	gccollect.c \
63
	lexerstr32.c \
64
	uart.c \
Damien George's avatar
Damien George committed
65
	esppwm.c \
66
	esponewire.c \
67
	espneopixel.c \
68
	espapa102.c \
69
	intr.c \
70
	modpyb.c \
71
	modpybpin.c \
Damien George's avatar
Damien George committed
72
	modpybpwm.c \
73
	modpybrtc.c \
Josef Gajdusek's avatar
Josef Gajdusek committed
74
	modpybadc.c \
75
	modpybuart.c \
76
	modpybspi.c \
77
	modesp.c \
78
	modnetwork.c \
79
	modutime.c \
Josef Gajdusek's avatar
Josef Gajdusek committed
80
	moduos.c \
Paul Sokolovsky's avatar
Paul Sokolovsky committed
81
	modmachine.c \
82
	modonewire.c \
83
	ets_alt_task.c \
84
	$(BUILD)/frozen.c \
85
	fatfs_port.c \
86
	axtls_helpers.c \
87
88

STM_SRC_C = $(addprefix stmhal/,\
89
	pybstdio.c \
90
	input.c \
91
92
	)

93
EXTMOD_SRC_C = $(addprefix extmod/,\
94
	modlwip.c \
95
96
        )

97
LIB_SRC_C = $(addprefix lib/,\
98
	libc/string0.c \
99
100
101
102
	libm/math.c \
	libm/fmodf.c \
	libm/roundf.c \
	libm/ef_sqrt.c \
Damien George's avatar
Damien George committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	libm/kf_rem_pio2.c \
	libm/kf_sin.c \
	libm/kf_cos.c \
	libm/kf_tan.c \
	libm/ef_rem_pio2.c \
	libm/sf_sin.c \
	libm/sf_cos.c \
	libm/sf_tan.c \
	libm/sf_frexp.c \
	libm/sf_modf.c \
	libm/sf_ldexp.c \
	libm/asinfacosf.c \
	libm/atanf.c \
	libm/atan2f.c \
117
	mp-readline/readline.c \
118
	netutils/netutils.c \
119
	timeutils/timeutils.c \
120
	utils/pyexec.c \
121
	utils/pyhelp.c \
122
	utils/printf.c \
123
124
	fatfs/ff.c \
	fatfs/option/ccsbcs.c \
125
126
	)

127
128
129
130
DRIVERS_SRC_C = $(addprefix drivers/,\
	dht/dht.c \
        )

131
132
133
134
135
136
137
138
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))
139
OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
140
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
141
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
142
143
#OBJ += $(BUILD)/pins_$(BOARD).o

144
# List of sources for qstr extraction
145
SRC_QSTR += $(SRC_C) $(STM_SRC_C) $(EXTMOD_SRC_C) $(DRIVERS_SRC_C)
146
147
148
# Append any auto-generated sources that are needed by sources listed in SRC_QSTR
SRC_QSTR_AUTO_DEPS +=

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

151
CONFVARS_FILE = $(BUILD)/confvars
152

153
ifeq ($(wildcard $(CONFVARS_FILE)),)
154
$(shell $(MKDIR) -p $(BUILD))
155
156
157
$(shell echo $(SCRIPTDIR) $(UART_OS) > $(CONFVARS_FILE))
else ifneq ($(shell cat $(CONFVARS_FILE)), $(SCRIPTDIR) $(UART_OS))
$(shell echo $(SCRIPTDIR) $(UART_OS) > $(CONFVARS_FILE))
158
159
endif

160
161
162
$(BUILD)/uart.o: $(CONFVARS_FILE)

$(BUILD)/frozen.c: $(wildcard $(SCRIPTDIR)/*) $(CONFVARS_FILE)
163
164
165
	$(ECHO) "Generating $@"
	$(Q)$(MAKE_FROZEN) $(SCRIPTDIR) > $@

166
167
168
169
.PHONY: deploy

deploy: $(BUILD)/firmware-combined.bin
	$(ECHO) "Writing $< to the board"
170
	$(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --verify --flash_size=8m 0 $<
171
	#$(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --flash_size=8m 0 $(BUILD)/firmware.elf-0x00000.bin 0x9000 $(BUILD)/firmware.elf-0x0[1-f]000.bin
172

173
reset:
174
	echo -e "\r\nimport machine; machine.reset()\r\n" >$(PORT)
175

176
177
178
$(BUILD)/firmware-combined.bin: $(BUILD)/firmware.elf
	$(ECHO) "Create $@"
	$(Q)esptool.py elf2image $^
179
	$(Q)$(PYTHON) makeimg.py $(BUILD)/firmware.elf-0x00000.bin $(BUILD)/firmware.elf-0x0[1-f]000.bin $@
180
181
182

$(BUILD)/firmware.elf: $(OBJ)
	$(ECHO) "LINK $@"
183
	$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
	$(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
213
214
215
216
217

axtls:
	cd ../lib/axtls; cp config/upyconfig config/.config
	cd ../lib/axtls; make oldconfig -B
	cd ../lib/axtls; make clean
218
	cd ../lib/axtls; make all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=3072"