blob: 4311af801c0f35b3e7df6c8227cc8bc185f45816 [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)
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -07003 get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../.. ABSOLUTE)
4endif()
5
6if(NOT MICROPY_PORT_DIR)
7 get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE)
Damien George0009a7d2021-06-24 16:03:25 +10008endif()
Damien George9b908822020-09-23 15:55:55 +10009
10# Include core source components.
11include(${MICROPY_DIR}/py/py.cmake)
Damien George9b908822020-09-23 15:55:55 +100012
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040013if(NOT CMAKE_BUILD_EARLY_EXPANSION)
Damien Georgebd375df2022-06-08 12:21:51 +100014 # Enable extmod components that will be configured by extmod.cmake.
15 # A board may also have enabled additional components.
16 set(MICROPY_PY_BTREE ON)
17
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040018 include(${MICROPY_DIR}/py/usermod.cmake)
Damien George212fe7f2021-04-08 23:45:28 +100019 include(${MICROPY_DIR}/extmod/extmod.cmake)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040020endif()
21
Damien George75db0b92021-02-21 11:33:15 +110022set(MICROPY_QSTRDEFS_PORT
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070023 ${MICROPY_PORT_DIR}/qstrdefsport.h
Damien George75db0b92021-02-21 11:33:15 +110024)
25
Damien George136369d2021-07-09 14:19:15 +100026set(MICROPY_SOURCE_SHARED
27 ${MICROPY_DIR}/shared/readline/readline.c
28 ${MICROPY_DIR}/shared/netutils/netutils.c
29 ${MICROPY_DIR}/shared/timeutils/timeutils.c
30 ${MICROPY_DIR}/shared/runtime/interrupt_char.c
31 ${MICROPY_DIR}/shared/runtime/stdout_helpers.c
32 ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
33 ${MICROPY_DIR}/shared/runtime/pyexec.c
34)
35
Damien George9b908822020-09-23 15:55:55 +100036set(MICROPY_SOURCE_LIB
37 ${MICROPY_DIR}/lib/littlefs/lfs1.c
38 ${MICROPY_DIR}/lib/littlefs/lfs1_util.c
39 ${MICROPY_DIR}/lib/littlefs/lfs2.c
40 ${MICROPY_DIR}/lib/littlefs/lfs2_util.c
Carlosggb5f46112023-04-30 22:24:26 +010041 ${MICROPY_DIR}/lib/mbedtls_errors/esp32_mbedtls_errors.c
Damien George9b908822020-09-23 15:55:55 +100042 ${MICROPY_DIR}/lib/oofatfs/ff.c
43 ${MICROPY_DIR}/lib/oofatfs/ffunicode.c
Damien George9b908822020-09-23 15:55:55 +100044)
Damien George68235142021-07-18 12:11:21 +100045if(IDF_TARGET STREQUAL "esp32c3")
46 list(APPEND MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/runtime/gchelper_generic.c)
47endif()
Damien George9b908822020-09-23 15:55:55 +100048
49set(MICROPY_SOURCE_DRIVERS
50 ${MICROPY_DIR}/drivers/bus/softspi.c
51 ${MICROPY_DIR}/drivers/dht/dht.c
52)
53
54set(MICROPY_SOURCE_PORT
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070055 main.c
Damien George1db40ed2023-06-21 15:09:26 +100056 ppp_set_auth.c
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070057 uart.c
58 usb.c
59 usb_serial_jtag.c
60 gccollect.c
61 mphalport.c
62 fatfs_port.c
63 help.c
64 machine_bitstream.c
65 machine_timer.c
66 machine_pin.c
67 machine_touchpad.c
68 machine_adc.c
69 machine_adcblock.c
70 machine_dac.c
71 machine_i2c.c
72 machine_i2s.c
73 machine_uart.c
74 modmachine.c
75 network_common.c
76 network_lan.c
77 network_ppp.c
78 network_wlan.c
79 mpnimbleport.c
80 modsocket.c
81 modesp.c
82 esp32_nvs.c
83 esp32_partition.c
84 esp32_rmt.c
85 esp32_ulp.c
86 modesp32.c
87 machine_hw_spi.c
88 machine_wdt.c
89 mpthreadport.c
90 machine_rtc.c
91 machine_sdcard.c
92 modespnow.c
Damien George9b908822020-09-23 15:55:55 +100093)
Brian 'redbeard' Harrington5fe2a3f2023-06-12 13:02:10 -070094list(TRANSFORM MICROPY_SOURCE_PORT PREPEND ${MICROPY_PORT_DIR}/)
Damien George9b908822020-09-23 15:55:55 +100095
96set(MICROPY_SOURCE_QSTR
97 ${MICROPY_SOURCE_PY}
98 ${MICROPY_SOURCE_EXTMOD}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -040099 ${MICROPY_SOURCE_USERMOD}
Damien George136369d2021-07-09 14:19:15 +1000100 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000101 ${MICROPY_SOURCE_LIB}
102 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000103 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000104)
105
106set(IDF_COMPONENTS
107 app_update
108 bootloader_support
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100109 bt
Damien George9b908822020-09-23 15:55:55 +1000110 driver
Jonathan Hogg63438a32021-12-21 15:15:24 +0000111 esp_adc_cal
Damien George9b908822020-09-23 15:55:55 +1000112 esp_common
113 esp_eth
114 esp_event
115 esp_ringbuf
116 esp_rom
117 esp_wifi
118 freertos
119 heap
120 log
121 lwip
122 mbedtls
123 mdns
124 newlib
125 nvs_flash
126 sdmmc
127 soc
128 spi_flash
129 tcpip_adapter
130 ulp
131 vfs
132 xtensa
133)
134
Magnus von Wachenfeldt6d9da272021-11-04 14:50:39 +0100135if(IDF_VERSION_MINOR GREATER_EQUAL 1 OR IDF_VERSION_MAJOR GREATER_EQUAL 5)
Damien Georged191d882021-02-15 21:00:01 +1100136 list(APPEND IDF_COMPONENTS esp_netif)
137endif()
138
Magnus von Wachenfeldt6d9da272021-11-04 14:50:39 +0100139if(IDF_VERSION_MINOR GREATER_EQUAL 2 OR IDF_VERSION_MAJOR GREATER_EQUAL 5)
Damien Georgea9150022021-02-15 21:00:09 +1100140 list(APPEND IDF_COMPONENTS esp_system)
141 list(APPEND IDF_COMPONENTS esp_timer)
142endif()
143
Magnus von Wachenfeldt6d9da272021-11-04 14:50:39 +0100144if(IDF_VERSION_MINOR GREATER_EQUAL 3 OR IDF_VERSION_MAJOR GREATER_EQUAL 5)
Damien George143372a2021-02-19 10:38:01 +1100145 list(APPEND IDF_COMPONENTS esp_hw_support)
146 list(APPEND IDF_COMPONENTS esp_pm)
147 list(APPEND IDF_COMPONENTS hal)
148endif()
149
Damien George66a86a02021-02-18 21:24:34 +1100150if(IDF_TARGET STREQUAL "esp32")
151 list(APPEND IDF_COMPONENTS esp32)
Damien George68235142021-07-18 12:11:21 +1000152elseif(IDF_TARGET STREQUAL "esp32c3")
153 list(APPEND IDF_COMPONENTS esp32c3)
154 list(APPEND IDF_COMPONENTS riscv)
Damien George66a86a02021-02-18 21:24:34 +1100155elseif(IDF_TARGET STREQUAL "esp32s2")
156 list(APPEND IDF_COMPONENTS esp32s2)
Damien Georgec81d0482021-02-19 12:08:11 +1100157 list(APPEND IDF_COMPONENTS tinyusb)
Damien George5093d492021-05-06 10:58:12 +1000158elseif(IDF_TARGET STREQUAL "esp32s3")
159 list(APPEND IDF_COMPONENTS esp32s3)
160 list(APPEND IDF_COMPONENTS tinyusb)
Damien George66a86a02021-02-18 21:24:34 +1100161endif()
162
Damien George9b908822020-09-23 15:55:55 +1000163# Register the main IDF component.
164idf_component_register(
165 SRCS
166 ${MICROPY_SOURCE_PY}
167 ${MICROPY_SOURCE_EXTMOD}
Damien George136369d2021-07-09 14:19:15 +1000168 ${MICROPY_SOURCE_SHARED}
Damien George9b908822020-09-23 15:55:55 +1000169 ${MICROPY_SOURCE_LIB}
170 ${MICROPY_SOURCE_DRIVERS}
171 ${MICROPY_SOURCE_PORT}
Damien Georgef046b502021-09-22 00:00:26 +1000172 ${MICROPY_SOURCE_BOARD}
Damien George9b908822020-09-23 15:55:55 +1000173 INCLUDE_DIRS
Damien George5dcc9b32021-04-09 00:59:16 +1000174 ${MICROPY_INC_CORE}
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400175 ${MICROPY_INC_USERMOD}
Damien George9b908822020-09-23 15:55:55 +1000176 ${MICROPY_PORT_DIR}
177 ${MICROPY_BOARD_DIR}
178 ${CMAKE_BINARY_DIR}
179 REQUIRES
180 ${IDF_COMPONENTS}
181)
182
183# Set the MicroPython target as the current (main) IDF component target.
184set(MICROPY_TARGET ${COMPONENT_TARGET})
185
186# Define mpy-cross flags, for use with frozen code.
187set(MICROPY_CROSS_FLAGS -march=xtensawin)
188
189# Set compile options for this port.
190target_compile_definitions(${MICROPY_TARGET} PUBLIC
Damien Georgeab9d47e2021-04-08 23:56:28 +1000191 ${MICROPY_DEF_CORE}
Damien George9b908822020-09-23 15:55:55 +1000192 MICROPY_ESP_IDF_4=1
193 MICROPY_VFS_FAT=1
194 MICROPY_VFS_LFS2=1
195 FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
196 LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
197 LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
198)
199
200# Disable some warnings to keep the build output clean.
201target_compile_options(${MICROPY_TARGET} PUBLIC
202 -Wno-clobbered
203 -Wno-deprecated-declarations
204 -Wno-missing-field-initializers
205)
206
Damien George5dbb8222021-03-17 12:35:59 +1100207# Additional include directories needed for private NimBLE headers.
208target_include_directories(${MICROPY_TARGET} PUBLIC
209 ${IDF_PATH}/components/bt/host/nimble/nimble
210)
211
Damien Georgeab9d47e2021-04-08 23:56:28 +1000212# Add additional extmod and usermod components.
213target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
Michael O'Cleirigh0ccd9e02021-03-27 17:10:39 -0400214target_link_libraries(${MICROPY_TARGET} usermod)
215
Damien George9b908822020-09-23 15:55:55 +1000216# Collect all of the include directories and compile definitions for the IDF components.
217foreach(comp ${IDF_COMPONENTS})
Damien George0fabda32021-04-08 23:42:22 +1000218 micropy_gather_target_properties(__idf_${comp})
Damien George9b908822020-09-23 15:55:55 +1000219endforeach()
220
Magnus von Wachenfeldt6d9da272021-11-04 14:50:39 +0100221if(IDF_VERSION_MINOR GREATER_EQUAL 2 OR IDF_VERSION_MAJOR GREATER_EQUAL 5)
Damien Georgea9150022021-02-15 21:00:09 +1100222 # These paths cannot currently be found by the IDF_COMPONENTS search loop above,
223 # so add them explicitly.
224 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/soc/soc/${IDF_TARGET}/include)
225 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/soc/soc/include)
Damien Georgec81d0482021-02-19 12:08:11 +1100226 if(IDF_VERSION_MINOR GREATER_EQUAL 3)
227 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/tinyusb/additions/include)
228 list(APPEND MICROPY_CPP_INC_EXTRA ${IDF_PATH}/components/tinyusb/tinyusb/src)
229 endif()
Damien Georgea9150022021-02-15 21:00:09 +1100230endif()
231
Damien George9b908822020-09-23 15:55:55 +1000232# Include the main MicroPython cmake rules.
233include(${MICROPY_DIR}/py/mkrules.cmake)