@@ -59,7 +59,13 @@ include $(TOP)/supervisor/supervisor.mk
59
59
# Include make rules and variables common across CircuitPython builds.
60
60
include $(TOP ) /py/circuitpy_defns.mk
61
61
62
+ ifeq ($(IDF_TARGET ) ,esp32s2)
63
+ IDF_TARGET_ARCH = xtensa
62
64
CROSS_COMPILE = xtensa-$(IDF_TARGET ) -elf-
65
+ else ifeq ($(IDF_TARGET),esp32c3)
66
+ IDF_TARGET_ARCH = riscv
67
+ CROSS_COMPILE = riscv32-esp-elf-
68
+ endif
63
69
64
70
# ######################################
65
71
# CFLAGS
@@ -95,7 +101,7 @@ INC += -I.\
95
101
-isystem esp-idf/components/esp_wifi/include \
96
102
-isystem esp-idf/components/freertos/include \
97
103
-isystem esp-idf/components/freertos/include/freertos \
98
- -isystem esp-idf/components/freertos/port/xtensa /include \
104
+ -isystem esp-idf/components/freertos/port/$( IDF_TARGET_ARCH ) /include \
99
105
-isystem esp-idf/components/hal/include \
100
106
-isystem esp-idf/components/hal/$(IDF_TARGET ) /include \
101
107
-isystem esp-idf/components/hal/platform_port/include \
@@ -112,8 +118,13 @@ INC += -I.\
112
118
-isystem esp-idf/components/soc/include \
113
119
-isystem esp-idf/components/soc/$(IDF_TARGET ) /include \
114
120
-isystem esp-idf/components/spi_flash/include \
115
- -isystem esp-idf/components/xtensa/include \
116
- -isystem esp-idf/components/xtensa/$(IDF_TARGET ) /include
121
+ -isystem esp-idf/components/$(IDF_TARGET_ARCH ) /include \
122
+ -isystem esp-idf/components/$(IDF_TARGET_ARCH ) /$(IDF_TARGET ) /include
123
+
124
+ # See https://github.com/espressif/esp-idf/issues/6906
125
+ ifeq ($(IDF_TARGET ) ,esp32c3)
126
+ CFLAGS += -include "esp32c3_fix.h"
127
+ endif
117
128
118
129
CFLAGS += -DHAVE_CONFIG_H \
119
130
-DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" \
@@ -139,7 +150,11 @@ endif
139
150
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
140
151
CFLAGS += $(OPTIMIZATION_FLAGS )
141
152
142
- CFLAGS += $(INC ) -Werror -Wall -mlongcalls -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS ) $(C_DEFS ) $(CFLAGS_MOD ) $(COPT )
153
+ CFLAGS += $(INC ) -Werror -Wall -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS ) $(C_DEFS ) $(CFLAGS_MOD ) $(COPT )
154
+
155
+ ifeq ($(IDF_TARGET_ARCH ) ,xtensa)
156
+ CFLAGS += -mlongcalls
157
+ endif
143
158
144
159
LDFLAGS = $(CFLAGS ) -Wl,-nostdlib -Wl,-Map=$@ .map -Wl,-cref -Wl,--undefined=uxTopUsedPriority
145
160
@@ -153,9 +168,17 @@ LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/$(IDF_TARGET) \
153
168
-T$(IDF_TARGET ) .rom.ld \
154
169
-T$(IDF_TARGET ) .rom.api.ld \
155
170
-T$(IDF_TARGET ) .rom.libgcc.ld \
156
- -T$(IDF_TARGET ) .rom.newlib-data.ld \
171
+ -T$(IDF_TARGET ) .rom.newlib-nano.ld
172
+
173
+ ifeq ($(IDF_TARGET ) ,esp32c3)
174
+ LDFLAGS += -Tesp32c3.rom.newlib.ld \
175
+ -Tesp32c3.rom.version.ld \
176
+ -Tesp32c3.rom.eco3.ld
177
+ else
178
+ LDFLAGS += -T$(IDF_TARGET ) .rom.newlib-data.ld \
157
179
-T$(IDF_TARGET ) .rom.newlib-funcs.ld \
158
180
-T$(IDF_TARGET ) .rom.spiflash.ld
181
+ endif
159
182
160
183
LDFLAGS += -Wl,-Bstatic \
161
184
-Wl,--no-warn-mismatch \
@@ -170,33 +193,44 @@ LIBS += -lm
170
193
endif
171
194
172
195
# TinyUSB defines
173
- CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S2 -DCFG_TUSB_OS=OPT_OS_FREERTOS -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024
174
- CFLAGS += -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128
175
- CFLAGS += -DCFG_TUD_VENDOR_RX_BUFSIZE=128 -DCFG_TUD_VENDOR_TX_BUFSIZE=128
176
-
196
+ ifeq ($(CIRCUITPY_USB ) ,1)
197
+ CFLAGS += \
198
+ -DCFG_TUSB_MCU=OPT_MCU_ESP32S2 \
199
+ -DCFG_TUSB_OS=OPT_OS_FREERTOS \
200
+ -DCFG_TUD_CDC_RX_BUFSIZE=1024 \
201
+ -DCFG_TUD_CDC_TX_BUFSIZE=1024 \
202
+ -DCFG_TUD_MSC_BUFSIZE=4096 \
203
+ -DCFG_TUD_MIDI_RX_BUFSIZE=128 \
204
+ -DCFG_TUD_MIDI_TX_BUFSIZE=128 \
205
+ -DCFG_TUD_VENDOR_RX_BUFSIZE=128 \
206
+ -DCFG_TUD_VENDOR_TX_BUFSIZE=128
207
+ endif
177
208
178
209
# #####################################
179
210
# source
180
211
# #####################################
181
212
182
-
183
213
SRC_C += \
184
214
background.c \
185
- cam.c \
186
- i2s_lcd_esp32s2_driver.c \
187
215
fatfs_port.c \
188
216
mphalport.c \
189
217
bindings/espidf/__init__.c \
190
218
boards/$(BOARD ) /board.c \
191
219
boards/$(BOARD ) /pins.c \
192
220
modules/$(CIRCUITPY_MODULE ) .c \
193
221
lib/netutils/netutils.c \
194
- peripherals/pcnt.c \
195
222
peripherals/rmt.c \
196
223
peripherals/timer.c \
197
- peripherals/touch.c \
198
224
peripherals/$(IDF_TARGET ) /pins.c
199
225
226
+ ifneq ($(IDF_TARGET ) ,esp32c3)
227
+ SRC_C += \
228
+ cam.c \
229
+ i2s_lcd_esp32s2_driver.c \
230
+ peripherals/pcnt.c \
231
+ peripherals/touch.c
232
+ endif
233
+
200
234
$(BUILD ) /i2s_lcd_esp32s2_driver.o : CFLAGS += -Wno-sign-compare
201
235
202
236
ifneq ($(CIRCUITPY_USB ) ,0)
@@ -251,7 +285,7 @@ ifeq ($(DEBUG), 1)
251
285
else
252
286
DEBUG_SDKCONFIG = esp-idf-config/sdkconfig-opt.defaults
253
287
endif
254
- SDKCONFIGS = esp-idf-config/$( IDF_TARGET ) / sdkconfig.defaults;$(DEBUG_SDKCONFIG ) ;$(FLASH_SDKCONFIG ) ;boards/$(BOARD ) /sdkconfig
288
+ SDKCONFIGS = esp-idf-config/sdkconfig.defaults;$(DEBUG_SDKCONFIG ) ;$(FLASH_SDKCONFIG ) ;boards/$(BOARD ) /sdkconfig
255
289
256
290
# create the config headers
257
291
$(BUILD ) /esp-idf/config/sdkconfig.h : boards/$(BOARD ) /sdkconfig | $(BUILD ) /esp-idf
@@ -280,26 +314,46 @@ menuconfig: $(BUILD)/esp-idf/config
280
314
# qstr builds include headers so we need to make sure they are up to date
281
315
$(HEADER_BUILD ) /qstr.split : | $(BUILD ) /esp-idf/config/sdkconfig.h
282
316
283
- ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET ) app_update bootloader_support driver efuse esp_adc_cal esp_common esp_event esp_hw_support esp_netif esp_pm esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant xtensa
317
+ ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET ) $( IDF_TARGET_ARCH ) app_update bootloader_support driver efuse esp_adc_cal esp_common esp_event esp_hw_support esp_netif esp_pm esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant
284
318
285
319
ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK ) , $(BUILD ) /esp-idf/esp-idf/$(component ) /lib$(component ) .a)
286
320
ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENTS_LINK ) , $(BUILD ) /esp-idf/esp-idf/$(component ) /lib$(component ) .a)
287
321
288
322
MBEDTLS_COMPONENTS_LINK = crypto tls x509
289
323
MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK ) , $(BUILD ) /esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component ) .a)
290
324
291
- BINARY_BLOBS = esp-idf/components/xtensa/$(IDF_TARGET ) /libxt_hal.a
292
- BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a librtc.a libsmartconfig.a libphy.a
293
- BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET ) /, $(BINARY_WIFI_BLOBS ) )
325
+ BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libphy.a
326
+ ifneq ($(IDF_TARGET ) ,esp32c3)
327
+ BINARY_WIFI_BLOBS += librtc.a
328
+ endif
329
+ BINARY_BLOBS = $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET ) /, $(BINARY_WIFI_BLOBS ) )
294
330
331
+ ifeq ($(IDF_TARGET_ARCH ) ,xtensa)
332
+ BINARY_BLOBS += esp-idf/components/xtensa/$(IDF_TARGET ) /libxt_hal.a
295
333
ESP_IDF_COMPONENTS_EXPANDED += esp-idf/components/xtensa/$(IDF_TARGET ) /libxt_hal.a
334
+ endif
335
+
336
+ ifeq ($(IDF_TARGET ) , esp32c3)
337
+ ESPTOOL_BAUDRATE = 230400
338
+ BOOTLOADER_OFFSET = 0x0000
339
+ else
340
+ ESPTOOL_BAUDRATE = 460800
341
+ BOOTLOADER_OFFSET = 0x1000
342
+ endif
343
+ PARTITION_TABLE_OFFSET = 0x8000
344
+ FIRMWARE_OFFSET = 0x10000
345
+
296
346
ESP_AUTOGEN_LD = $(BUILD ) /esp-idf/esp-idf/$(IDF_TARGET ) /$(IDF_TARGET ) _out.ld $(BUILD ) /esp-idf/esp-idf/$(IDF_TARGET ) /ld/$(IDF_TARGET ) .project.ld
297
347
298
348
FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE ) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE )
299
349
300
- ESPTOOL_FLAGS ?= -b 460800 --before=default_reset --after=no_reset
350
+ ESPTOOL_FLAGS ?= -b $( ESPTOOL_BAUDRATE ) --before=default_reset --after=no_reset
301
351
352
+ ifeq ($(IDF_TARGET ) ,esp32c3)
353
+ all : $(BUILD ) /firmware.bin
354
+ else
302
355
all : $(BUILD ) /firmware.bin $(BUILD ) /firmware.uf2
356
+ endif
303
357
304
358
.PHONY : esp-idf-stamp
305
359
esp-idf-stamp : $(BUILD ) /esp-idf/config/sdkconfig.h
@@ -336,7 +390,7 @@ esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
336
390
esp-idf/spi_flash/libspi_flash.a \
337
391
esp-idf/vfs/libvfs.a \
338
392
esp-idf/wpa_supplicant/libwpa_supplicant.a \
339
- esp-idf/xtensa/libxtensa .a
393
+ esp-idf/$( IDF_TARGET_ARCH ) /lib $( IDF_TARGET_ARCH ) .a
340
394
341
395
$(BUILD ) /firmware.elf : $(OBJ ) | esp-idf-stamp
342
396
$(STEPECHO ) " LINK $@ "
@@ -348,7 +402,7 @@ $(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf | tools/build_memory_
348
402
$(Q )$(PYTHON3 ) tools/build_memory_info.py $< $(BUILD ) /esp-idf/sdkconfig $@
349
403
350
404
$(BUILD ) /firmware.bin : $(BUILD ) /circuitpython-firmware.bin | esp-idf-stamp
351
- $(Q )$(PYTHON ) ../../tools/join_bins.py $@ 0x1000 $(BUILD ) /esp-idf/bootloader/bootloader.bin 0x8000 $(BUILD ) /esp-idf/partition_table/partition-table.bin 0x10000 $(BUILD ) /circuitpython-firmware.bin
405
+ $(Q )$(PYTHON ) ../../tools/join_bins.py $@ $( BOOTLOADER_OFFSET ) $(BUILD ) /esp-idf/bootloader/bootloader.bin $( PARTITION_TABLE_OFFSET ) $(BUILD ) /esp-idf/partition_table/partition-table.bin $( FIRMWARE_OFFSET ) $(BUILD ) /circuitpython-firmware.bin
352
406
353
407
$(BUILD ) /firmware.uf2 : $(BUILD ) /circuitpython-firmware.bin
354
408
$(STEPECHO ) " Create $@ "
@@ -358,7 +412,7 @@ flash: $(BUILD)/firmware.bin
358
412
esptool.py --chip $(IDF_TARGET ) -p $(PORT ) $(ESPTOOL_FLAGS ) write_flash $(FLASH_FLAGS ) 0x0000 $^
359
413
360
414
flash-circuitpython-only : $(BUILD ) /circuitpython-firmware.bin
361
- esptool.py --chip $(IDF_TARGET ) -p $(PORT ) $(ESPTOOL_FLAGS ) write_flash $(FLASH_FLAGS ) 0x10000 $^
415
+ esptool.py --chip $(IDF_TARGET ) -p $(PORT ) $(ESPTOOL_FLAGS ) write_flash $(FLASH_FLAGS ) $( FIRMWARE_OFFSET ) $^
362
416
363
417
monitor : $(BUILD ) /firmware.elf
364
418
cp $< build/circuitpython.elf
0 commit comments