blob: 2c81e8c2b3a50aa141baf8d888a7dacb9a9f44c1 [file] [log] [blame]
Damien George9b908822020-09-23 15:55:55 +10001# Set location of base MicroPython directory.
Damien George0009a7d2021-06-24 16:03:25 +10002if(NOT MICROPY_DIR)
Damien Georgee4650122023-05-09 09:52:54 +10003 get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUTE)
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -07004endif()
5
Damien Georgee4650122023-05-09 09:52:54 +10006# Set location of the ESP32 port directory.
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -07007if(NOT MICROPY_PORT_DIR)
8 get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE)
Damien George0009a7d2021-06-24 16:03:25 +10009endif()
Damien George9b908822020-09-23 15:55:55 +100010
11# Include core source components.
12include(${MICROPY_DIR}/py/py.cmake)
Damien George9b908822020-09-23 15:55:55 +100013
Jim Mussaredad123ed2023-07-31 17:24:38 +100014# CMAKE_BUILD_EARLY_EXPANSION is set during the component-discovery phase of
15# `idf.py build`, so none of the extmod/usermod (and in reality, most of the
16# micropython) rules need to happen. Specifically, you cannot invoke add_library.
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040017if(NOT CMAKE_BUILD_EARLY_EXPANSION)
Damien Georgebd375df2022-06-08 12:21:51 +100018 # Enable extmod components that will be configured by extmod.cmake.
19 # A board may also have enabled additional components.
20 set(MICROPY_PY_BTREE ON)
21
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040022 include(${MICROPY_DIR}/py/usermod.cmake)
Damien George212fe7f2021-04-08 23:45:28 +100023 include(${MICROPY_DIR}/extmod/extmod.cmake)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040024endif()
25
Damien Georgee4650122023-05-09 09:52:54 +100026list(APPEND MICROPY_QSTRDEFS_PORT
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070027 ${MICROPY_PORT_DIR}/qstrdefsport.h
Damien George75db0b92021-02-21 11:33:15 +110028)
29
Damien Georgee4650122023-05-09 09:52:54 +100030list(APPEND MICROPY_SOURCE_SHARED
Damien George136369d2021-07-09 14:19:15 +100031 ${MICROPY_DIR}/shared/readline/readline.c
32 ${MICROPY_DIR}/shared/netutils/netutils.c
33 ${MICROPY_DIR}/shared/timeutils/timeutils.c
34 ${MICROPY_DIR}/shared/runtime/interrupt_char.c
robert-hha04a1412024-03-10 15:14:20 +010035 ${MICROPY_DIR}/shared/runtime/mpirq.c
Damien George136369d2021-07-09 14:19:15 +100036 ${MICROPY_DIR}/shared/runtime/stdout_helpers.c
37 ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
38 ${MICROPY_DIR}/shared/runtime/pyexec.c
39)
40
Damien Georgee4650122023-05-09 09:52:54 +100041list(APPEND MICROPY_SOURCE_LIB
Damien George9b908822020-09-23 15:55:55 +100042 ${MICROPY_DIR}/lib/littlefs/lfs1.c
43 ${MICROPY_DIR}/lib/littlefs/lfs1_util.c
44 ${MICROPY_DIR}/lib/littlefs/lfs2.c
45 ${MICROPY_DIR}/lib/littlefs/lfs2_util.c
Damien Georgec9eb6bc2023-12-12 16:05:03 +110046 ${MICROPY_DIR}/lib/mbedtls_errors/esp32_mbedtls_errors.c
Damien George9b908822020-09-23 15:55:55 +100047 ${MICROPY_DIR}/lib/oofatfs/ff.c
48 ${MICROPY_DIR}/lib/oofatfs/ffunicode.c
Damien George9b908822020-09-23 15:55:55 +100049)
50
Damien Georgee4650122023-05-09 09:52:54 +100051list(APPEND MICROPY_SOURCE_DRIVERS
Damien George9b908822020-09-23 15:55:55 +100052 ${MICROPY_DIR}/drivers/bus/softspi.c
53 ${MICROPY_DIR}/drivers/dht/dht.c
54)
55
Andrew Leech42479212024-05-23 17:23:41 +100056string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/tinyusb)
57if(MICROPY_PY_TINYUSB)
58 set(TINYUSB_SRC "${MICROPY_DIR}/lib/tinyusb/src")
59 string(TOUPPER OPT_MCU_${IDF_TARGET} tusb_mcu)
60
61 list(APPEND MICROPY_DEF_TINYUSB
62 CFG_TUSB_MCU=${tusb_mcu}
63 )
64
65 list(APPEND MICROPY_SOURCE_TINYUSB
66 ${TINYUSB_SRC}/tusb.c
67 ${TINYUSB_SRC}/common/tusb_fifo.c
68 ${TINYUSB_SRC}/device/usbd.c
69 ${TINYUSB_SRC}/device/usbd_control.c
70 ${TINYUSB_SRC}/class/cdc/cdc_device.c
71 ${TINYUSB_SRC}/portable/synopsys/dwc2/dcd_dwc2.c
72 ${MICROPY_DIR}/shared/tinyusb/mp_usbd.c
73 ${MICROPY_DIR}/shared/tinyusb/mp_usbd_cdc.c
74 ${MICROPY_DIR}/shared/tinyusb/mp_usbd_descriptor.c
75 )
76
77 list(APPEND MICROPY_INC_TINYUSB
78 ${TINYUSB_SRC}
79 ${MICROPY_DIR}/shared/tinyusb/
80 )
81
82 list(APPEND MICROPY_LINK_TINYUSB
83 -Wl,--wrap=dcd_event_handler
84 )
85endif()
86
Damien Georgee4650122023-05-09 09:52:54 +100087list(APPEND MICROPY_SOURCE_PORT
Daniƫl van de Giessenc10a74b2024-03-13 18:23:17 +010088 panichandler.c
Damien George03eae482023-10-25 19:13:11 +110089 adc.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070090 main.c
Damien George1db40ed2023-06-21 15:09:26 +100091 ppp_set_auth.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070092 uart.c
93 usb.c
94 usb_serial_jtag.c
95 gccollect.c
96 mphalport.c
97 fatfs_port.c
98 help.c
99 machine_bitstream.c
100 machine_timer.c
101 machine_pin.c
102 machine_touchpad.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -0700103 machine_dac.c
104 machine_i2c.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -0700105 network_common.c
106 network_lan.c
107 network_ppp.c
108 network_wlan.c
109 mpnimbleport.c
110 modsocket.c
111 modesp.c
112 esp32_nvs.c
113 esp32_partition.c
114 esp32_rmt.c
115 esp32_ulp.c
116 modesp32.c
117 machine_hw_spi.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -0700118 mpthreadport.c
119 machine_rtc.c
120 machine_sdcard.c
121 modespnow.c
Damien George9b908822020-09-23 15:55:55 +1000122)
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -0700123list(TRANSFORM MICROPY_SOURCE_PORT PREPEND ${MICROPY_PORT_DIR}/)
Damien Georgecb31c0a2023-07-15 00:03:59 +1000124list(APPEND MICROPY_SOURCE_PORT ${CMAKE_BINARY_DIR}/pins.c)
Damien George9b908822020-09-23 15:55:55 +1000125
Damien Georgee4650122023-05-09 09:52:54 +1000126list(APPEND MICROPY_SOURCE_QSTR
Damien George9b908822020-09-23 15:55:55 +1000127 ${MICROPY_SOURCE_PY}
128 ${MICROPY_SOURCE_EXTMOD}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400129 ${MICROPY_SOURCE_USERMOD}
Damien George136369d2021-07-09 14:19:15 +1000130 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000131 ${MICROPY_SOURCE_LIB}
132 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000133 ${MICROPY_SOURCE_BOARD}
Andrew Leech42479212024-05-23 17:23:41 +1000134 ${MICROPY_SOURCE_TINYUSB}
Damien George9b908822020-09-23 15:55:55 +1000135)
136
Damien Georgee4650122023-05-09 09:52:54 +1000137list(APPEND IDF_COMPONENTS
Damien George9b908822020-09-23 15:55:55 +1000138 app_update
139 bootloader_support
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100140 bt
Damien George9b908822020-09-23 15:55:55 +1000141 driver
Damien Georgee4650122023-05-09 09:52:54 +1000142 esp_adc
143 esp_app_format
Damien George9b908822020-09-23 15:55:55 +1000144 esp_common
145 esp_eth
146 esp_event
Damien Georgee4650122023-05-09 09:52:54 +1000147 esp_hw_support
148 esp_netif
149 esp_partition
150 esp_pm
151 esp_psram
Damien George9b908822020-09-23 15:55:55 +1000152 esp_ringbuf
153 esp_rom
Damien Georgee4650122023-05-09 09:52:54 +1000154 esp_system
155 esp_timer
Damien George9b908822020-09-23 15:55:55 +1000156 esp_wifi
157 freertos
Damien Georgee4650122023-05-09 09:52:54 +1000158 hal
Damien George9b908822020-09-23 15:55:55 +1000159 heap
160 log
161 lwip
162 mbedtls
Damien George9b908822020-09-23 15:55:55 +1000163 newlib
164 nvs_flash
165 sdmmc
166 soc
167 spi_flash
Damien George9b908822020-09-23 15:55:55 +1000168 ulp
Andrew Leech42479212024-05-23 17:23:41 +1000169 usb
Damien George9b908822020-09-23 15:55:55 +1000170 vfs
Damien George9b908822020-09-23 15:55:55 +1000171)
172
Damien George9b908822020-09-23 15:55:55 +1000173# Register the main IDF component.
174idf_component_register(
175 SRCS
176 ${MICROPY_SOURCE_PY}
177 ${MICROPY_SOURCE_EXTMOD}
Damien George136369d2021-07-09 14:19:15 +1000178 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000179 ${MICROPY_SOURCE_LIB}
180 ${MICROPY_SOURCE_DRIVERS}
181 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000182 ${MICROPY_SOURCE_BOARD}
Andrew Leech42479212024-05-23 17:23:41 +1000183 ${MICROPY_SOURCE_TINYUSB}
Damien George9b908822020-09-23 15:55:55 +1000184 INCLUDE_DIRS
Damien George5dcc9b32021-04-09 00:59:16 +1000185 ${MICROPY_INC_CORE}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400186 ${MICROPY_INC_USERMOD}
Andrew Leech42479212024-05-23 17:23:41 +1000187 ${MICROPY_INC_TINYUSB}
Damien George9b908822020-09-23 15:55:55 +1000188 ${MICROPY_PORT_DIR}
189 ${MICROPY_BOARD_DIR}
190 ${CMAKE_BINARY_DIR}
Jim Mussaredacbdbcd2024-03-21 15:46:41 +1100191 LDFRAGMENTS
192 linker.lf
Damien George9b908822020-09-23 15:55:55 +1000193 REQUIRES
194 ${IDF_COMPONENTS}
195)
196
197# Set the MicroPython target as the current (main) IDF component target.
198set(MICROPY_TARGET ${COMPONENT_TARGET})
199
200# Define mpy-cross flags, for use with frozen code.
Andrew Leech6d799372023-06-26 11:53:28 +1000201if(CONFIG_IDF_TARGET_ARCH STREQUAL "xtensa")
Damien George9b908822020-09-23 15:55:55 +1000202set(MICROPY_CROSS_FLAGS -march=xtensawin)
Alessandro Gatti95ce61d2023-10-31 13:28:25 +0100203endif()
Damien George9b908822020-09-23 15:55:55 +1000204
205# Set compile options for this port.
206target_compile_definitions(${MICROPY_TARGET} PUBLIC
Damien Georgeab9d47e2021-04-08 23:56:28 +1000207 ${MICROPY_DEF_CORE}
Jim Mussared2fbf42d2023-07-25 15:03:30 +1000208 ${MICROPY_DEF_BOARD}
Andrew Leech42479212024-05-23 17:23:41 +1000209 ${MICROPY_DEF_TINYUSB}
Damien George9b908822020-09-23 15:55:55 +1000210 MICROPY_ESP_IDF_4=1
211 MICROPY_VFS_FAT=1
212 MICROPY_VFS_LFS2=1
213 FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
214 LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
215 LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
216)
217
218# Disable some warnings to keep the build output clean.
219target_compile_options(${MICROPY_TARGET} PUBLIC
220 -Wno-clobbered
221 -Wno-deprecated-declarations
222 -Wno-missing-field-initializers
223)
224
Andrew Leech42479212024-05-23 17:23:41 +1000225target_link_options(${MICROPY_TARGET} PUBLIC
226 ${MICROPY_LINK_TINYUSB}
227)
228
Damien George5dbb8222021-03-17 12:35:59 +1100229# Additional include directories needed for private NimBLE headers.
230target_include_directories(${MICROPY_TARGET} PUBLIC
231 ${IDF_PATH}/components/bt/host/nimble/nimble
232)
233
Damien Georgeab9d47e2021-04-08 23:56:28 +1000234# Add additional extmod and usermod components.
235target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400236target_link_libraries(${MICROPY_TARGET} usermod)
237
Luca Burelli31ef7c12023-07-05 18:03:11 +0200238# Collect all of the include directories and compile definitions for the IDF components,
239# including those added by the IDF Component Manager via idf_components.yaml.
240foreach(comp ${__COMPONENT_NAMES_RESOLVED})
Damien George0fabda32021-04-08 23:42:22 +1000241 micropy_gather_target_properties(__idf_${comp})
Damien Georgee4650122023-05-09 09:52:54 +1000242 micropy_gather_target_properties(${comp})
Damien George9b908822020-09-23 15:55:55 +1000243endforeach()
244
Damien George9b908822020-09-23 15:55:55 +1000245# Include the main MicroPython cmake rules.
246include(${MICROPY_DIR}/py/mkrules.cmake)
Damien Georgecb31c0a2023-07-15 00:03:59 +1000247
248# Generate source files for named pins (requires mkrules.cmake for MICROPY_GENHDR_DIR).
249
250set(GEN_PINS_PREFIX "${MICROPY_PORT_DIR}/boards/pins_prefix.c")
251set(GEN_PINS_MKPINS "${MICROPY_PORT_DIR}/boards/make-pins.py")
252set(GEN_PINS_SRC "${CMAKE_BINARY_DIR}/pins.c")
253set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h")
254
255if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv")
256 set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/pins.csv")
257 set(GEN_PINS_BOARD_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}")
258endif()
259
260target_sources(${MICROPY_TARGET} PRIVATE ${GEN_PINS_HDR})
261
262add_custom_command(
263 OUTPUT ${GEN_PINS_SRC} ${GEN_PINS_HDR}
264 COMMAND ${Python3_EXECUTABLE} ${GEN_PINS_MKPINS} ${GEN_PINS_BOARD_CSV_ARG}
265 --prefix ${GEN_PINS_PREFIX} --output-source ${GEN_PINS_SRC} --output-header ${GEN_PINS_HDR}
266 DEPENDS
267 ${MICROPY_MPVERSION}
268 ${GEN_PINS_MKPINS}
269 ${GEN_PINS_BOARD_CSV}
270 ${GEN_PINS_PREFIX}
271 VERBATIM
272 COMMAND_EXPAND_LISTS
273)