blob: 89e46f9cfb3df26d18919cc2db911d52357c52e6 [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
35 ${MICROPY_DIR}/shared/runtime/stdout_helpers.c
36 ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
37 ${MICROPY_DIR}/shared/runtime/pyexec.c
38)
39
Damien Georgee4650122023-05-09 09:52:54 +100040list(APPEND MICROPY_SOURCE_LIB
Damien George9b908822020-09-23 15:55:55 +100041 ${MICROPY_DIR}/lib/littlefs/lfs1.c
42 ${MICROPY_DIR}/lib/littlefs/lfs1_util.c
43 ${MICROPY_DIR}/lib/littlefs/lfs2.c
44 ${MICROPY_DIR}/lib/littlefs/lfs2_util.c
Damien Georgec9eb6bc2023-12-12 16:05:03 +110045 ${MICROPY_DIR}/lib/mbedtls_errors/esp32_mbedtls_errors.c
Damien George9b908822020-09-23 15:55:55 +100046 ${MICROPY_DIR}/lib/oofatfs/ff.c
47 ${MICROPY_DIR}/lib/oofatfs/ffunicode.c
Damien George9b908822020-09-23 15:55:55 +100048)
49
Damien Georgee4650122023-05-09 09:52:54 +100050list(APPEND MICROPY_SOURCE_DRIVERS
Damien George9b908822020-09-23 15:55:55 +100051 ${MICROPY_DIR}/drivers/bus/softspi.c
52 ${MICROPY_DIR}/drivers/dht/dht.c
53)
54
Damien Georgee4650122023-05-09 09:52:54 +100055list(APPEND MICROPY_SOURCE_PORT
Damien George03eae482023-10-25 19:13:11 +110056 adc.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070057 main.c
Damien George1db40ed2023-06-21 15:09:26 +100058 ppp_set_auth.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070059 uart.c
60 usb.c
61 usb_serial_jtag.c
62 gccollect.c
63 mphalport.c
64 fatfs_port.c
65 help.c
66 machine_bitstream.c
67 machine_timer.c
68 machine_pin.c
69 machine_touchpad.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070070 machine_dac.c
71 machine_i2c.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070072 network_common.c
73 network_lan.c
74 network_ppp.c
75 network_wlan.c
76 mpnimbleport.c
77 modsocket.c
78 modesp.c
79 esp32_nvs.c
80 esp32_partition.c
81 esp32_rmt.c
82 esp32_ulp.c
83 modesp32.c
84 machine_hw_spi.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070085 mpthreadport.c
86 machine_rtc.c
87 machine_sdcard.c
88 modespnow.c
Damien George9b908822020-09-23 15:55:55 +100089)
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070090list(TRANSFORM MICROPY_SOURCE_PORT PREPEND ${MICROPY_PORT_DIR}/)
Damien Georgecb31c0a2023-07-15 00:03:59 +100091list(APPEND MICROPY_SOURCE_PORT ${CMAKE_BINARY_DIR}/pins.c)
Damien George9b908822020-09-23 15:55:55 +100092
Damien Georgee4650122023-05-09 09:52:54 +100093list(APPEND MICROPY_SOURCE_QSTR
Damien George9b908822020-09-23 15:55:55 +100094 ${MICROPY_SOURCE_PY}
95 ${MICROPY_SOURCE_EXTMOD}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040096 ${MICROPY_SOURCE_USERMOD}
Damien George136369d2021-07-09 14:19:15 +100097 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +100098 ${MICROPY_SOURCE_LIB}
99 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000100 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000101)
102
Damien Georgee4650122023-05-09 09:52:54 +1000103list(APPEND IDF_COMPONENTS
Damien George9b908822020-09-23 15:55:55 +1000104 app_update
105 bootloader_support
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100106 bt
Damien George9b908822020-09-23 15:55:55 +1000107 driver
Damien Georgee4650122023-05-09 09:52:54 +1000108 esp_adc
109 esp_app_format
Damien George9b908822020-09-23 15:55:55 +1000110 esp_common
111 esp_eth
112 esp_event
Damien Georgee4650122023-05-09 09:52:54 +1000113 esp_hw_support
114 esp_netif
115 esp_partition
116 esp_pm
117 esp_psram
Damien George9b908822020-09-23 15:55:55 +1000118 esp_ringbuf
119 esp_rom
Damien Georgee4650122023-05-09 09:52:54 +1000120 esp_system
121 esp_timer
Damien George9b908822020-09-23 15:55:55 +1000122 esp_wifi
123 freertos
Damien Georgee4650122023-05-09 09:52:54 +1000124 hal
Damien George9b908822020-09-23 15:55:55 +1000125 heap
126 log
127 lwip
128 mbedtls
Damien George9b908822020-09-23 15:55:55 +1000129 newlib
130 nvs_flash
131 sdmmc
132 soc
133 spi_flash
Damien George9b908822020-09-23 15:55:55 +1000134 ulp
135 vfs
Damien George9b908822020-09-23 15:55:55 +1000136)
137
Damien George9b908822020-09-23 15:55:55 +1000138# Register the main IDF component.
139idf_component_register(
140 SRCS
141 ${MICROPY_SOURCE_PY}
142 ${MICROPY_SOURCE_EXTMOD}
Damien George136369d2021-07-09 14:19:15 +1000143 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000144 ${MICROPY_SOURCE_LIB}
145 ${MICROPY_SOURCE_DRIVERS}
146 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000147 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000148 INCLUDE_DIRS
Damien George5dcc9b32021-04-09 00:59:16 +1000149 ${MICROPY_INC_CORE}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400150 ${MICROPY_INC_USERMOD}
Damien George9b908822020-09-23 15:55:55 +1000151 ${MICROPY_PORT_DIR}
152 ${MICROPY_BOARD_DIR}
153 ${CMAKE_BINARY_DIR}
Jim Mussaredacbdbcd2024-03-21 15:46:41 +1100154 LDFRAGMENTS
155 linker.lf
Damien George9b908822020-09-23 15:55:55 +1000156 REQUIRES
157 ${IDF_COMPONENTS}
158)
159
160# Set the MicroPython target as the current (main) IDF component target.
161set(MICROPY_TARGET ${COMPONENT_TARGET})
162
163# Define mpy-cross flags, for use with frozen code.
Alessandro Gatti95ce61d2023-10-31 13:28:25 +0100164if(NOT IDF_TARGET STREQUAL "esp32c3")
Damien George9b908822020-09-23 15:55:55 +1000165set(MICROPY_CROSS_FLAGS -march=xtensawin)
Alessandro Gatti95ce61d2023-10-31 13:28:25 +0100166endif()
Damien George9b908822020-09-23 15:55:55 +1000167
168# Set compile options for this port.
169target_compile_definitions(${MICROPY_TARGET} PUBLIC
Damien Georgeab9d47e2021-04-08 23:56:28 +1000170 ${MICROPY_DEF_CORE}
Jim Mussared2fbf42d2023-07-25 15:03:30 +1000171 ${MICROPY_DEF_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000172 MICROPY_ESP_IDF_4=1
173 MICROPY_VFS_FAT=1
174 MICROPY_VFS_LFS2=1
175 FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
176 LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
177 LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
178)
179
180# Disable some warnings to keep the build output clean.
181target_compile_options(${MICROPY_TARGET} PUBLIC
182 -Wno-clobbered
183 -Wno-deprecated-declarations
184 -Wno-missing-field-initializers
185)
186
Damien George5dbb8222021-03-17 12:35:59 +1100187# Additional include directories needed for private NimBLE headers.
188target_include_directories(${MICROPY_TARGET} PUBLIC
189 ${IDF_PATH}/components/bt/host/nimble/nimble
190)
191
Damien Georgeab9d47e2021-04-08 23:56:28 +1000192# Add additional extmod and usermod components.
193target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400194target_link_libraries(${MICROPY_TARGET} usermod)
195
Luca Burelli31ef7c12023-07-05 18:03:11 +0200196# Collect all of the include directories and compile definitions for the IDF components,
197# including those added by the IDF Component Manager via idf_components.yaml.
198foreach(comp ${__COMPONENT_NAMES_RESOLVED})
Damien George0fabda32021-04-08 23:42:22 +1000199 micropy_gather_target_properties(__idf_${comp})
Damien Georgee4650122023-05-09 09:52:54 +1000200 micropy_gather_target_properties(${comp})
Damien George9b908822020-09-23 15:55:55 +1000201endforeach()
202
Damien George9b908822020-09-23 15:55:55 +1000203# Include the main MicroPython cmake rules.
204include(${MICROPY_DIR}/py/mkrules.cmake)
Damien Georgecb31c0a2023-07-15 00:03:59 +1000205
206# Generate source files for named pins (requires mkrules.cmake for MICROPY_GENHDR_DIR).
207
208set(GEN_PINS_PREFIX "${MICROPY_PORT_DIR}/boards/pins_prefix.c")
209set(GEN_PINS_MKPINS "${MICROPY_PORT_DIR}/boards/make-pins.py")
210set(GEN_PINS_SRC "${CMAKE_BINARY_DIR}/pins.c")
211set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h")
212
213if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv")
214 set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/pins.csv")
215 set(GEN_PINS_BOARD_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}")
216endif()
217
218target_sources(${MICROPY_TARGET} PRIVATE ${GEN_PINS_HDR})
219
220add_custom_command(
221 OUTPUT ${GEN_PINS_SRC} ${GEN_PINS_HDR}
222 COMMAND ${Python3_EXECUTABLE} ${GEN_PINS_MKPINS} ${GEN_PINS_BOARD_CSV_ARG}
223 --prefix ${GEN_PINS_PREFIX} --output-source ${GEN_PINS_SRC} --output-header ${GEN_PINS_HDR}
224 DEPENDS
225 ${MICROPY_MPVERSION}
226 ${GEN_PINS_MKPINS}
227 ${GEN_PINS_BOARD_CSV}
228 ${GEN_PINS_PREFIX}
229 VERBATIM
230 COMMAND_EXPAND_LISTS
231)