Skip to content

Commit cc47218

Browse files
committed
cpu/esp32: makefile migration to ESP-IDF v5.4
1 parent 4ddaa4a commit cc47218

File tree

2 files changed

+76
-35
lines changed

2 files changed

+76
-35
lines changed

cpu/esp32/Makefile.dep

+9-21
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ ifneq (,$(filter esp_eth,$(USEMODULE)))
3636
USEMODULE += esp_idf_eth
3737
USEMODULE += esp_idf_event
3838
USEMODULE += esp_idf_gpio
39-
USEMODULE += esp_idf_spi_flash
4039
USEMODULE += netdev_eth
4140
USEMODULE += netopt
42-
USEMODULE += ztimer_msec
4341
endif
4442

4543
ifneq (,$(filter esp_wifi_any,$(USEMODULE)))
@@ -50,7 +48,6 @@ ifneq (,$(filter esp_wifi_any,$(USEMODULE)))
5048
USEMODULE += esp_idf_event
5149
USEMODULE += esp_idf_heap
5250
USEMODULE += esp_idf_nvs_flash
53-
USEMODULE += esp_idf_spi_flash
5451
USEMODULE += esp_idf_wifi
5552
USEMODULE += esp_idf_wpa_supplicant
5653
USEMODULE += esp_idf_wpa_supplicant_esp_supplicant
@@ -71,9 +68,12 @@ ifneq (,$(filter esp_hw_counter,$(USEMODULE)))
7168
endif
7269

7370
ifneq (,$(filter esp_idf_nvs_flash,$(USEMODULE)))
71+
# NVS flash uses MBed TLS for encryption
72+
USEPKG += mbedtls
73+
USEMODULE += mbedtls_contrib
7474
# add additional modules required by esp_idf_nvs_flash
75+
USEMODULE += esp_idf_spi_flash
7576
USEMODULE += pthread
76-
USEMODULE += mtd
7777
endif
7878

7979
ifneq (,$(filter esp_idf_wifi,$(USEMODULE)))
@@ -116,7 +116,6 @@ ifneq (,$(filter esp_spi_ram,$(USEMODULE)))
116116
FEATURES_OPTIONAL += esp_spi_oct
117117
USEMODULE += esp_idf_gpio
118118
USEMODULE += esp_idf_heap
119-
USEMODULE += esp_idf_spi_flash
120119
USEMODULE += esp_idf_spi_ram
121120
endif
122121

@@ -125,21 +124,14 @@ ifneq (,$(filter esp_spi_oct,$(FEATURES_USED)))
125124
endif
126125

127126
ifneq (,$(filter esp_idf_heap,$(USEMODULE)))
128-
# The ESP-IDF heap component uses the TLSF implementation that is part of
129-
# the component. To avoid conflicts with modules and packages that use the
130-
# RIOT package `tlsf`, this package is also used for the ESP-IDF heap instead
131-
# of its own implementation. There does not seem to be any differences in
132-
# the implementations of TLSF with the exception of heap poisoning, which
133-
# is not configured.
134-
# TODO: replace esp32_sdk_tlsf by tlsf after upgrading tlsf package
135-
# USEPKG += tlsf
136-
ifneq (,$(filter tlsf,$(USEPKG)))
137-
# we don't allow to use the tlsf package together with esp_idf_heap for now
138-
$(error "Package tlsf and esp_idf_heap can't be used together")
139-
endif
127+
# ESP-IDF heap component uses its own and modified TLSF implementation
140128
USEPKG += esp32_sdk_tlsf
141129
endif
142130

131+
ifneq (,$(filter esp_jtag,$(USEMODULE)))
132+
FEATURES_REQUIRED += esp_jtag
133+
endif
134+
143135
ifneq (,$(filter lcd_parallel_ll_mcu,$(USEMODULE)))
144136
USEMODULE += esp_lcd
145137
USEMODULE += esp_idf_lcd
@@ -199,10 +191,6 @@ ifneq (,$(filter tinyusb_portable_espressif,$(USEMODULE)))
199191
USEMODULE += esp_idf_usb
200192
endif
201193

202-
ifneq (,$(filter esp_jtag,$(USEMODULE)))
203-
FEATURES_REQUIRED += esp_jtag
204-
endif
205-
206194
# enable bootloader reset over USB, requires CDC ACM to be used
207195
ifneq (,$(filter usbus_cdc_acm tinyusb_class_cdc,$(USEMODULE)))
208196
USEMODULE += usb_board_reset

cpu/esp32/Makefile.include

+67-14
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,17 @@ INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/include
126126

127127
INCLUDES += -I$(ESP32_SDK_DIR)/components
128128
INCLUDES += -I$(ESP32_SDK_DIR)/components/bootloader_support/include
129-
INCLUDES += -I$(ESP32_SDK_DIR)/components/driver/include
129+
INCLUDES += -I$(ESP32_SDK_DIR)/components/driver/deprecated
130+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_adc/include
130131
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_common/include
132+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_driver_gpio/include
131133
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_hw_support/include
132134
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_hw_support/include/soc
135+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_hw_support/port/$(CPU_FAM)/include
133136
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)
134137
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_rom/include
135-
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_rom/include/$(CPU_FAM)
138+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/include
139+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/include/$(CPU_FAM)
136140
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_system/include
137141
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_system/port/include
138142
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_timer/include
@@ -144,7 +148,9 @@ INCLUDES += -I$(ESP32_SDK_DIR)/components/log/include
144148
INCLUDES += -I$(ESP32_SDK_DIR)/components/newlib/platform_include
145149
INCLUDES += -I$(ESP32_SDK_DIR)/components/soc/include
146150
INCLUDES += -I$(ESP32_SDK_DIR)/components/soc/$(CPU_FAM)/include
151+
INCLUDES += -I$(ESP32_SDK_DIR)/components/soc/$(CPU_FAM)/register
147152
INCLUDES += -I$(ESP32_SDK_DIR)/components/spi_flash/include
153+
INCLUDES += -I$(ESP32_SDK_DIR)/components/spi_flash/include/spi_flash
148154

149155
ifneq (,$(filter riscv32%,$(TARGET_ARCH)))
150156
INCLUDES += -I$(ESP32_SDK_DIR)/components/riscv/include
@@ -156,22 +162,36 @@ ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
156162
endif
157163

158164
ifneq (,$(filter esp_ble,$(USEMODULE)))
159-
INCLUDES += -I$(ESP32_SDK_DIR)/components/bt/include/$(CPU_FAM)/include
165+
ifeq (esp32,$(CPU_FAM))
166+
INCLUDES += -I$(ESP32_SDK_DIR)/components/bt/include/$(CPU_FAM)/include
167+
else ifneq (,$(filter esp32s3 esp32c3,$(CPU_FAM)))
168+
INCLUDES += -I$(ESP32_SDK_DIR)/components/bt/include/esp32c3/include
169+
endif
160170
endif
161171

162172
ifneq (,$(filter esp_ble_nimble,$(USEMODULE)))
163173
INCLUDES += -I$(RIOTCPU)/$(CPU)/include/esp_ble_nimble
164174
INCLUDES += $(NIMIBASE)/nimble/transport/common/hci_h4/include
165175
endif
166176

177+
ifneq (,$(filter esp_i2c_hw,$(USEMODULE)))
178+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_driver_i2c/include
179+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_pm/include
180+
endif
181+
167182
ifneq (,$(filter esp_spi_ram,$(USEMODULE)))
168-
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_hw_support/include/soc/$(CPU_FAM)
183+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_psram/include
169184
endif
170185

171186
ifneq (,$(filter esp_idf_lcd,$(USEMODULE)))
172187
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_lcd/include
173188
endif
174189

190+
ifneq (,$(filter esp_idf_nvs_flash,$(USEMODULE)))
191+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_partition/include
192+
CFLAGS += -DMBEDTLS_CIPHER_MODE_XTS
193+
endif
194+
175195
ifneq (,$(filter esp_idf_spi_flash,$(USEMODULE)))
176196
INCLUDES += -I$(ESP32_SDK_DIR)/components/spi_flash/include
177197
endif
@@ -202,14 +222,26 @@ ifneq (,$(filter esp_eth,$(USEMODULE)))
202222
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_wifi/include
203223
endif
204224

225+
ifneq (,$(filter periph_sdmmc,$(USEMODULE)))
226+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_driver_sdmmc/include
227+
INCLUDES += -I$(ESP32_SDK_DIR)/components/sdmmc/include
228+
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_hw_support/dma/include
229+
endif
230+
231+
ifneq (,$(filter ws281x_esp32_hw,$(USEMODULE)))
232+
INCLUDES += -I$(ESP32_SDK_DIR)/components/driver/deprecated
233+
CFLAGS += -DCONFIG_RMT_SUPPRESS_DEPRECATE_WARN
234+
endif
235+
205236
CFLAGS += -DCPU_FAM_$(call uppercase_and_underscore,$(CPU_FAM))
206237

207-
# we use ESP32 only in single core mode
238+
# we use ESP32x SoC only in single core mode
208239
CFLAGS += -DCONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
209240
CFLAGS += -DCONFIG_FREERTOS_UNICORE
210241

211242
# other ESP-IDF configurations
212243
CFLAGS += -DCONFIG_IDF_TARGET_$(call uppercase_and_underscore,$(CPU_FAM))
244+
CFLAGS += -DCONFIG_IDF_TARGET=\"$(CPU_FAM)\"
213245
CFLAGS += -DESP_PLATFORM
214246
CFLAGS += -DLOG_TAG_IN_BRACKETS
215247

@@ -246,7 +278,9 @@ CFLAGS += -D_CONST=const
246278

247279
# TODO no relaxation yet
248280
ifneq (,$(filter riscv%,$(TARGET_ARCH)))
281+
CFLAGS += -DCONFIG_IDF_TARGET_ARCH_RISCV
249282
CFLAGS += -mno-relax -march=rv32imc_zicsr_zifencei -mabi=ilp32 -DRISCV_NO_RELAX
283+
LDGENFLAGS += -DCONFIG_IDF_TARGET_ARCH_RISCV
250284
LINKFLAGS += -mno-relax -march=rv32imc_zicsr_zifencei -mabi=ilp32
251285
GCC_NEW_RISCV_ISA ?= $(shell echo "typedef int dont_be_pedantic;" | \
252286
$(TARGET_ARCH)-gcc -march=rv32imac -mabi=ilp32 \
@@ -258,6 +292,8 @@ ifneq (,$(filter riscv%,$(TARGET_ARCH)))
258292
endif
259293

260294
ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
295+
CFLAGS += -DCONFIG_IDF_TARGET_ARCH_XTENSA
296+
LDGENFLAGS += -DCONFIG_IDF_TARGET_ARCH_XTENSA
261297
LINKFLAGS += -L$(ESP32_SDK_DIR)/components/xtensa/$(CPU_FAM)
262298
ARCHIVES += -lxt_hal
263299
endif
@@ -272,13 +308,25 @@ LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.
272308
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.api.ld
273309
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.libgcc.ld
274310

275-
ifeq (esp32s2,$(CPU_FAM))
276-
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.spiflash.ld
311+
ifeq (esp32,$(CPU_FAM))
312+
# We don't use newlibc functions in ROM for ESP32
313+
# LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.newlib-data.ld
314+
# LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.newlib-funcs.lds
315+
else ifeq (esp32s2,$(CPU_FAM))
316+
# We don't use newlibc functions in ROM for ESP32-S2
317+
# LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.newlib-data.ld
318+
# LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.newlib-funcs.ld
319+
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.spiflash_legacy.ld
320+
else ifeq (esp32s3,$(CPU_FAM))
321+
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.ble_cca.ld
322+
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.bt_funcs.ld
323+
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.newlib.ld
277324
else ifeq (esp32c3,$(CPU_FAM))
325+
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.ble_cca.ld
326+
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.bt_funcs.ld
278327
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.newlib.ld
279328
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.eco3.ld
280-
else ifeq (esp32s3,$(CPU_FAM))
281-
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.newlib.ld
329+
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/riscv/ld/rom.api.ld
282330
endif
283331

284332
LINKFLAGS += -nostdlib -lgcc -Wl,-gc-sections
@@ -293,6 +341,7 @@ endif
293341
ifneq (,$(filter esp_wifi_any,$(USEMODULE)))
294342
LINKFLAGS += -L$(ESP32_SDK_LIB_WIFI_DIR)/$(CPU_FAM)
295343
LINKFLAGS += -L$(ESP32_SDK_LIB_PHY_DIR)/$(CPU_FAM)
344+
LINKFLAGS += -L$(ESP32_SDK_LIB_COEXIST_DIR)/$(CPU_FAM)
296345
ARCHIVES += -lcoexist -lcore -lmesh -lnet80211 -lpp
297346
ARCHIVES += -lphy -lstdc++
298347
ifeq (esp32,$(CPU_FAM))
@@ -342,13 +391,17 @@ ifneq (,$(filter esp_jtag,$(USEMODULE)))
342391
endif
343392

344393
LD_SCRIPTS += $(BINDIR)/memory.ld $(BINDIR)/sections.ld
394+
LDGENFLAGS += -DLD_FILE_GEN
395+
LDGENFLAGS += -DRESERVE_RTC_MEM=0x18
396+
LDGENFLAGS += -DESP_BOOTLOADER_RESERVE_RTC=0x18
345397

346-
$(BINDIR)/memory.ld: $(RIOTCPU)/$(CPU)/ld/$(CPU_FAM)/memory.ld.in \
398+
$(BINDIR)/memory.ld: $(RIOTCPU)/$(CPU)/vendor/ld/$(CPU_FAM)/memory.ld.in \
347399
$(BINDIR)/riotbuild/riotbuild.h pkg-prepare
348-
$(Q)$(CC) -DLD_FILE_GEN $(INCLUDES) -include '$(BINDIR)/riotbuild/riotbuild.h' \
349-
-I$(RIOTCPU)/$(CPU)/ld -P -x c -E $< -o $@
350-
$(BINDIR)/sections.ld: $(RIOTCPU)/$(CPU)/ld/$(CPU_FAM)/sections.ld.in \
400+
$(Q)$(CC) $(INCLUDES) -include '$(BINDIR)/riotbuild/riotbuild.h' \
401+
$(LDGENFLAGS) -I$(RIOTCPU)/$(CPU)/vendor/ld -P -x c -E $< -o $@
402+
$(BINDIR)/sections.ld: $(RIOTCPU)/$(CPU)/vendor/ld/$(CPU_FAM)/sections.ld.in \
351403
$(BINDIR)/riotbuild/riotbuild.h pkg-prepare
352-
$(Q)$(CC) -DLD_FILE_GEN -include '$(BINDIR)/riotbuild/riotbuild.h' -C -P -x c -E $< -o $@
404+
$(Q)$(CC) $(INCLUDES) -include '$(BINDIR)/riotbuild/riotbuild.h' \
405+
$(LDGENFLAGS) -I$(RIOTCPU)/$(CPU)/vendor/ld -C -P -x c -E $< -o $@
353406

354407
$(BOOTLOADER_BIN):

0 commit comments

Comments
 (0)