@@ -12,6 +12,20 @@ if(NOT MICROPY_PORT_DIR)
1212 get_filename_component (MICROPY_PORT_DIR ${MICROPY_DIR} /ports/esp32 ABSOLUTE )
1313endif ()
1414
15+ # RISC-V specific inclusions
16+ if (CONFIG_IDF_TARGET_ARCH_RISCV)
17+ list (APPEND MICROPY_SOURCE_LIB
18+ ${MICROPY_DIR} /shared/runtime/gchelper_native.c
19+ ${MICROPY_DIR} /shared/runtime/gchelper_rv32i.s
20+ )
21+ endif ()
22+
23+ if (NOT DEFINED MICROPY_PY_TINYUSB)
24+ if (CONFIG_IDF_TARGET_ESP32S2 OR CONFIG_IDF_TARGET_ESP32S3)
25+ set (MICROPY_PY_TINYUSB ON )
26+ endif ()
27+ endif ()
28+
1529# Include core source components.
1630include (${MICROPY_DIR} /py/py.cmake)
1731
@@ -57,7 +71,7 @@ list(APPEND MICROPY_SOURCE_DRIVERS
5771 ${MICROPY_DIR} /drivers/dht/dht.c
5872)
5973
60- string (CONCAT GIT_SUBMODULES " ${GIT_SUBMODULES} " lib/tinyusb)
74+ list ( APPEND GIT_SUBMODULES lib/tinyusb)
6175if (MICROPY_PY_TINYUSB)
6276 set (TINYUSB_SRC "${MICROPY_DIR} /lib/tinyusb/src" )
6377 string (TOUPPER OPT_MCU_${IDF_TARGET} tusb_mcu)
@@ -76,6 +90,7 @@ if(MICROPY_PY_TINYUSB)
7690 ${MICROPY_DIR} /shared/tinyusb/mp_usbd.c
7791 ${MICROPY_DIR} /shared/tinyusb/mp_usbd_cdc.c
7892 ${MICROPY_DIR} /shared/tinyusb/mp_usbd_descriptor.c
93+ ${MICROPY_DIR} /shared/tinyusb/mp_usbd_runtime.c
7994 )
8095
8196 list (APPEND MICROPY_INC_TINYUSB
@@ -121,7 +136,7 @@ set(MICROPY_SOURCE_PORT
121136 ${PROJECT_DIR} /../m5stack/modesp32.c
122137 ${PROJECT_DIR} /../micropython/ports/esp32/machine_hw_spi.c
123138 ${PROJECT_DIR} /../micropython/ports/esp32/mpthreadport.c
124- ${PROJECT_DIR} /../micropython/ports/esp32 /machine_rtc.c
139+ ${PROJECT_DIR} /../m5stack /machine_rtc.c
125140 ${PROJECT_DIR} /../micropython/ports/esp32/machine_sdcard.c
126141 ${PROJECT_DIR} /../micropython/ports/esp32/modespnow.c
127142)
@@ -153,6 +168,7 @@ set(MICROPY_SOURCE_QSTR
153168 ${MICROPY_SOURCE_LIB}
154169 ${MICROPY_SOURCE_PORT}
155170 ${MICROPY_SOURCE_BOARD}
171+ ${MICROPY_SOURCE_TINYUSB}
156172 # ${MICROPY_SOURCE_M5UNIFIED}
157173 ${MICROPY_SOURCE_M5CAMERA}
158174)
@@ -191,7 +207,6 @@ set(IDF_COMPONENTS
191207 ulp
192208 usb
193209 vfs
194- xtensa
195210 esp_http_client
196211 esp-tls
197212 libffi
@@ -200,8 +215,15 @@ set(IDF_COMPONENTS
200215 BOX3GFX
201216 esp32-camera
202217 uiflow_utility
218+ esp_dmx
219+ esp_mm
220+ esp_driver_ppa
203221)
204222
223+ if (CONFIG_IDF_TARGET_ESP32 OR CONFIG_IDF_TARGET_ESP32S2 OR CONFIG_IDF_TARGET_ESP32S3)
224+ list (APPEND IDF_COMPONENTS xtensa)
225+ endif ()
226+
205227if (IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s3" )
206228 list (APPEND IDF_COMPONENTS boards)
207229 list (APPEND IDF_COMPONENTS audio_pipeline)
@@ -211,6 +233,22 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s3")
211233 list (APPEND IDF_COMPONENTS esp_codec_dev)
212234endif ()
213235
236+ # Provide the default LD fragment if not set
237+ if (MICROPY_USER_LDFRAGMENTS)
238+ set (MICROPY_LDFRAGMENTS ${MICROPY_USER_LDFRAGMENTS} )
239+ endif ()
240+
241+ if (UPDATE_SUBMODULES)
242+ # ESP-IDF checks if some paths exist before CMake does. Some paths don't
243+ # yet exist if this is an UPDATE_SUBMODULES pass on a brand new checkout, so remove
244+ # any path which might not exist yet. A "real" build will not set UPDATE_SUBMODULES.
245+ unset (MICROPY_SOURCE_TINYUSB)
246+ unset (MICROPY_SOURCE_EXTMOD)
247+ unset (MICROPY_SOURCE_LIB)
248+ unset (MICROPY_INC_TINYUSB)
249+ unset (MICROPY_INC_CORE)
250+ endif ()
251+
214252# Register the main IDF component.
215253idf_component_register(
216254 SRCS
@@ -230,7 +268,7 @@ idf_component_register(
230268 ${MICROPY_BOARD_DIR}
231269 ${CMAKE_BINARY_DIR}
232270 LDFRAGMENTS
233- linker.lf
271+ ${MICROPY_LDFRAGMENTS}
234272 REQUIRES
235273 ${IDF_COMPONENTS}
236274)
@@ -239,8 +277,10 @@ idf_component_register(
239277set (MICROPY_TARGET ${COMPONENT_TARGET} )
240278
241279# Define mpy-cross flags, for use with frozen code.
242- if (CONFIG_IDF_TARGET_ARCH STREQUAL "xtensa" )
243- set (MICROPY_CROSS_FLAGS -march=xtensawin)
280+ if (CONFIG_IDF_TARGET_ARCH_XTENSA)
281+ set (MICROPY_CROSS_FLAGS -march=xtensawin)
282+ elseif (CONFIG_IDF_TARGET_ARCH_RISCV)
283+ set (MICROPY_CROSS_FLAGS -march=rv32imc)
244284endif ()
245285
246286# Set compile options for this port.
@@ -266,7 +306,7 @@ target_compile_options(${MICROPY_TARGET} PUBLIC
266306)
267307
268308target_link_options (${MICROPY_TARGET} PUBLIC
269- ${MICROPY_LINK_TINYUSB}
309+ ${MICROPY_LINK_TINYUSB}
270310)
271311
272312# Additional include directories needed for private NimBLE headers.
@@ -278,6 +318,20 @@ target_include_directories(${MICROPY_TARGET} PUBLIC
278318target_link_libraries (${MICROPY_TARGET} micropy_extmod_btree)
279319target_link_libraries (${MICROPY_TARGET} usermod)
280320
321+ # Extra linker options
322+ # (when wrap symbols are in standalone files, --undefined ensures
323+ # the linker doesn't skip that file.)
324+ target_link_options (${MICROPY_TARGET} PUBLIC
325+ # Patch LWIP memory pool allocators (see lwip_patch.c)
326+ -Wl,--undefined=memp_malloc
327+ -Wl,--wrap=memp_malloc
328+ -Wl,--wrap=memp_free
329+
330+ # Enable the panic handler wrapper
331+ -Wl,--undefined=esp_panic_handler
332+ -Wl,--wrap=esp_panic_handler
333+ )
334+
281335# Collect all of the include directories and compile definitions for the IDF components,
282336# including those added by the IDF Component Manager via idf_components.yaml.
283337foreach (comp ${__COMPONENT_NAMES_RESOLVED} )
@@ -313,4 +367,4 @@ add_custom_command(
313367 ${GEN_PINS_PREFIX}
314368 VERBATIM
315369 COMMAND_EXPAND_LISTS
316- )
370+ )
0 commit comments