Skip to content

Commit d8c9a4e

Browse files
committed
all: Updated MicroPython version to 1.25.0.
1. support esp32-p4. 2. still using i2c-driver. Signed-off-by: lbuque <[email protected]>
1 parent e986468 commit d8c9a4e

38 files changed

+1476
-970
lines changed

m5stack/CMakeLists.txt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# SPDX-License-Identifier: MIT
44

55
# Top-level cmake file for building MicroPython on ESP32.
6-
6+
#
7+
# Note for maintainers: Where possible, functionality should be put into
8+
# esp32_common.cmake not this file. This is because this CMakeLists.txt file
9+
# needs to be duplicated for out-of-tree builds, and can easily get out of date.
710
cmake_minimum_required(VERSION 3.12)
811

912
set(CMAKE_C_FLAGS "-Wno-unused-variable -Wno-unused-but-set-variable")
@@ -42,12 +45,6 @@ set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
4245
# Save the manifest file set from the cmake command line.
4346
set(MICROPY_USER_FROZEN_MANIFEST ${MICROPY_FROZEN_MANIFEST})
4447

45-
# Specific options for IDF v5.2 and later
46-
set(SDKCONFIG_IDF_VERSION_SPECIFIC "")
47-
if (IDF_VERSION VERSION_GREATER_EQUAL "5.2.0")
48-
set(SDKCONFIG_IDF_VERSION_SPECIFIC boards/sdkconfig.idf52)
49-
endif()
50-
5148
# Include board config; this is expected to set (among other options):
5249
# - SDKCONFIG_DEFAULTS
5350
# - IDF_TARGET
@@ -88,11 +85,6 @@ endif()
8885
# Include main IDF cmake file.
8986
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
9087

91-
# Set the location of the main component for the project (one per target).
92-
list(APPEND EXTRA_COMPONENT_DIRS
93-
main_${IDF_TARGET}
94-
)
95-
9688
if (M5_CAMERA_MODULE_ENABLE AND BOARD_TYPE STREQUAL "cores3")
9789
list(APPEND EXTRA_COMPONENT_DIRS
9890
components/esp_dl/esp-dl
@@ -102,12 +94,5 @@ list(APPEND EXTRA_COMPONENT_DIRS
10294
)
10395
endif()
10496

105-
# Enable the panic handler wrapper
106-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
107-
108-
# Patch LWIP memory pool allocators (see lwip_patch.c)
109-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_malloc" APPEND)
110-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_free" APPEND)
111-
11297
# Define the project.
11398
project(micropython)

m5stack/CMakeListsDefault.cmake

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ if(NOT MICROPY_PORT_DIR)
1212
get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE)
1313
endif()
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.
1630
include(${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)
6175
if(MICROPY_PY_TINYUSB)
6276
set(TINYUSB_SRC "${MICROPY_DIR}/lib/tinyusb/src")
6377
string(TOUPPER OPT_MCU_${IDF_TARGET} tusb_mcu)
@@ -166,7 +180,6 @@ if (M5_CAMERA_MODULE_ENABLE)
166180
)
167181
endif()
168182

169-
170183
set(MICROPY_SOURCE_QSTR
171184
${MICROPY_SOURCE_PY}
172185
${MICROPY_SOURCE_EXTMOD}
@@ -214,7 +227,6 @@ list(APPEND IDF_COMPONENTS
214227
ulp
215228
usb
216229
vfs
217-
xtensa
218230
esp_http_client
219231
esp-tls
220232
libffi
@@ -226,6 +238,10 @@ list(APPEND IDF_COMPONENTS
226238
esp_mm
227239
)
228240

241+
if(CONFIG_IDF_TARGET_ESP32 OR CONFIG_IDF_TARGET_ESP32S2 OR CONFIG_IDF_TARGET_ESP32S3)
242+
list(APPEND IDF_COMPONENTS xtensa)
243+
endif()
244+
229245
if (M5_CAMERA_MODULE_ENABLE AND BOARD_TYPE STREQUAL "cores3")
230246
list(APPEND IDF_COMPONENTS
231247
esp-dl
@@ -251,6 +267,22 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s3")
251267
list(APPEND IDF_COMPONENTS esp_codec_dev)
252268
endif()
253269

270+
# Provide the default LD fragment if not set
271+
if (MICROPY_USER_LDFRAGMENTS)
272+
set(MICROPY_LDFRAGMENTS ${MICROPY_USER_LDFRAGMENTS})
273+
endif()
274+
275+
if (UPDATE_SUBMODULES)
276+
# ESP-IDF checks if some paths exist before CMake does. Some paths don't
277+
# yet exist if this is an UPDATE_SUBMODULES pass on a brand new checkout, so remove
278+
# any path which might not exist yet. A "real" build will not set UPDATE_SUBMODULES.
279+
unset(MICROPY_SOURCE_TINYUSB)
280+
unset(MICROPY_SOURCE_EXTMOD)
281+
unset(MICROPY_SOURCE_LIB)
282+
unset(MICROPY_INC_TINYUSB)
283+
unset(MICROPY_INC_CORE)
284+
endif()
285+
254286
# Register the main IDF component.
255287
idf_component_register(
256288
SRCS
@@ -271,7 +303,7 @@ idf_component_register(
271303
${CMAKE_BINARY_DIR}
272304
${CMAKE_CURRENT_LIST_DIR}
273305
LDFRAGMENTS
274-
linker.lf
306+
${MICROPY_LDFRAGMENTS}
275307
REQUIRES
276308
${IDF_COMPONENTS}
277309
)
@@ -280,8 +312,10 @@ idf_component_register(
280312
set(MICROPY_TARGET ${COMPONENT_TARGET})
281313

282314
# Define mpy-cross flags, for use with frozen code.
283-
if(CONFIG_IDF_TARGET_ARCH STREQUAL "xtensa")
284-
set(MICROPY_CROSS_FLAGS -march=xtensawin)
315+
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
316+
set(MICROPY_CROSS_FLAGS -march=xtensawin)
317+
elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
318+
set(MICROPY_CROSS_FLAGS -march=rv32imc)
285319
endif()
286320

287321
if (M5_CAMERA_MODULE_ENABLE AND BOARD_TYPE STREQUAL "cores3")
@@ -326,6 +360,20 @@ target_include_directories(${MICROPY_TARGET} PUBLIC
326360
target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
327361
target_link_libraries(${MICROPY_TARGET} usermod)
328362

363+
# Extra linker options
364+
# (when wrap symbols are in standalone files, --undefined ensures
365+
# the linker doesn't skip that file.)
366+
target_link_options(${MICROPY_TARGET} PUBLIC
367+
# Patch LWIP memory pool allocators (see lwip_patch.c)
368+
-Wl,--undefined=memp_malloc
369+
-Wl,--wrap=memp_malloc
370+
-Wl,--wrap=memp_free
371+
372+
# Enable the panic handler wrapper
373+
-Wl,--undefined=esp_panic_handler
374+
-Wl,--wrap=esp_panic_handler
375+
)
376+
329377
# Collect all of the include directories and compile definitions for the IDF components,
330378
# including those added by the IDF Component Manager via idf_components.yaml.
331379
foreach(comp ${__COMPONENT_NAMES_RESOLVED})

m5stack/Makefile

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,39 @@ submodules:
299299
# Apply patches
300300
patch:
301301
$(call Package/patche,$(abspath ./cmodules/lv_binding_micropython),$(abspath ./patches/0003-avoid-lv_bindings-compile-error.patch))
302-
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0004-micropython-1.24-machine-adc-v5.x.diff))
303-
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0005-micropython-fix-SDCard-16223.patch))
304302
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0006-modtime-add-timezone-method.patch))
305303
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0007-Add-set-default-netif-method.patch))
306-
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0008-machine_uart-add-uart-mode.patch))
307-
$(call Package/patche,$(abspath $(IDF_PATH)),$(abspath ./patches/1003-WIP-Compatible-with-esp-adf-v2.7.diff))
304+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0009-micropython-1.25.0-add-esp32p4-pins.patch))
305+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0010-micropython-1.25.0-machine-adc-v5.x.patch))
306+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0011-micropython-1.25.0-fix-esp32-p4-pwm.patch))
307+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0012-micropython-1.25.0-fix-esp32-p4-modesp32.patch))
308+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0013-micropython-1.25.0-fix-touchpad.patch))
309+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0014-micropython-1.25.0-fix-timer.patch))
310+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0015-micropython-1.25.0-fix-hostname.patch))
311+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0016-micropython-1.25.0-fix-mpnimbleport.patch))
312+
$(call Package/patche,$(abspath ./../micropython),$(abspath ./patches/0017-micropython-1.25.0-add-uart-mode.patch))
313+
$(call Package/patche,$(abspath $(IDF_PATH)),$(abspath ./patches/1004-idf_v5.4_freertos.patch))
308314
$(call Package/patche,$(abspath ./components/M5Unified/M5Unified),$(abspath ./patches/2005-Support-LTR553.patch))
309315
$(call Package/patche,$(abspath $(ADF_PATH)),$(abspath ./patches/3002-Modify-i2s_stream_idf5.patch))
316+
$(call Package/patche,$(abspath ./components/M5Unified/M5GFX),$(abspath ./patches/4002-M5GFX-use-i2c-driver.patch))
310317
$(call Package/patche,$(abspath ./components/esp32-camera),$(abspath ./patches/5001-Add-software-i2c-support.patch))
311318

312319
# Unapply patches
313320
unpatch:
314321
$(call Package/unpatche,$(abspath ./cmodules/lv_binding_micropython),$(abspath ./patches/0003-avoid-lv_bindings-compile-error.patch))
315-
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0008-machine_uart-add-uart-mode.patch))
322+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0017-micropython-1.25.0-add-uart-mode.patch))
323+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0016-micropython-1.25.0-fix-mpnimbleport.patch))
324+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0015-micropython-1.25.0-fix-hostname.patch))
325+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0014-micropython-1.25.0-fix-timer.patch))
326+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0013-micropython-1.25.0-fix-touchpad.patch))
327+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0012-micropython-1.25.0-fix-esp32-p4-modesp32.patch))
328+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0011-micropython-1.25.0-fix-esp32-p4-pwm.patch))
329+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0010-micropython-1.25.0-machine-adc-v5.x.patch))
330+
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0009-micropython-1.25.0-add-esp32p4-pins.patch))
316331
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0007-Add-set-default-netif-method.patch))
317332
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0006-modtime-add-timezone-method.patch))
318-
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0005-micropython-fix-SDCard-16223.patch))
319-
$(call Package/unpatche,$(abspath ./../micropython),$(abspath ./patches/0004-micropython-1.24-machine-adc-v5.x.diff))
320-
$(call Package/unpatche,$(abspath $(IDF_PATH)),$(abspath ./patches/1003-WIP-Compatible-with-esp-adf-v2.7.diff))
333+
$(call Package/unpatche,$(abspath $(IDF_PATH)),$(abspath ./patches/1004-idf_v5.4_freertos.patch))
321334
$(call Package/unpatche,$(abspath ./components/M5Unified/M5Unified),$(abspath ./patches/2005-Support-LTR553.patch))
322335
$(call Package/unpatche,$(abspath $(ADF_PATH)),$(abspath ./patches/3002-Modify-i2s_stream_idf5.patch))
336+
$(call Package/unpatche,$(abspath ./components/M5Unified/M5GFX),$(abspath ./patches/4002-M5GFX-use-i2c-driver.patch))
323337
$(call Package/unpatche,$(abspath ./components/esp32-camera),$(abspath ./patches/5001-Add-software-i2c-support.patch))

m5stack/board.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ extern "C" {
4848
auto cfg = M5.config();
4949
cfg.output_power = false;
5050
M5.begin(cfg);
51-
in_i2c_init();
5251
M5.In_I2C.release();
52+
in_i2c_init();
5353
}
5454

5555
void power_init()

m5stack/boards/M5STACK_CoreS3/board_init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "esp_codec_dev.h"
2424
#include "esp_codec_dev_defaults.h"
2525

26-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
26+
#if 0 //ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
2727
#include "driver/i2c_master.h"
2828
#define USE_IDF_I2C_MASTER
2929
#else
@@ -177,8 +177,8 @@ static int ut_i2c_init(uint8_t port)
177177
i2c_master_bus_config_t i2c_bus_config = {0};
178178
i2c_bus_config.clk_source = I2C_CLK_SRC_DEFAULT;
179179
i2c_bus_config.i2c_port = port;
180-
i2c_bus_config.scl_io_num = TEST_BOARD_I2C_SCL_PIN;
181-
i2c_bus_config.sda_io_num = TEST_BOARD_I2C_SDA_PIN;
180+
i2c_bus_config.scl_io_num = 12;
181+
i2c_bus_config.sda_io_num = 11;
182182
i2c_bus_config.glitch_ignore_cnt = 7;
183183
i2c_bus_config.flags.enable_internal_pullup = true;
184184
return i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);

m5stack/boards/sdkconfig.base

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n
4949
# FreeRTOS
5050
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
5151
CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION=y
52-
CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP=y
52+
CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP=n
53+
CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK=y
5354

5455
# UDP
5556
CONFIG_LWIP_PPP_SUPPORT=y
@@ -63,6 +64,9 @@ CONFIG_MBEDTLS_HAVE_TIME_DATE=y
6364
CONFIG_MBEDTLS_PLATFORM_TIME_ALT=y
6465
CONFIG_MBEDTLS_HAVE_TIME=y
6566

67+
# Enable DTLS
68+
CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
69+
6670
# Disable ALPN support as it's not implemented in MicroPython
6771
CONFIG_MBEDTLS_SSL_ALPN=n
6872

m5stack/cmodules/m5unified/m5unified_lvgl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mp_obj_t mp_lv_task_handler(mp_obj_t self_in) {
2121
static MP_DEFINE_CONST_FUN_OBJ_1(mp_lv_task_handler_obj, mp_lv_task_handler);
2222

2323
static void vTimerCallback(TimerHandle_t plvgl_timer) {
24-
lv_tick_inc(portTICK_RATE_MS * 10);
24+
lv_tick_inc(portTICK_PERIOD_MS * 10);
2525
mp_sched_schedule((mp_obj_t)&mp_lv_task_handler_obj, mp_const_none);
2626
}
2727

m5stack/cmodules/omv/modules/py_jpg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static mp_obj_t py_jpg_encode(size_t n_args, const mp_obj_t *args) {
4242
if (img_jpg.data) {
4343
free(img_jpg.data);
4444
}
45-
fmt2jpg(img->data, img->size, img->w, img->h, PIXFORMAT_RGB565, quality, &img_jpg.data, &img_jpg.size);
45+
fmt2jpg(img->data, img->size, img->w, img->h, PIXFORMAT_RGB565, quality, &img_jpg.data, (size_t *)&img_jpg.size);
4646

4747
return py_image_from_struct(&img_jpg);
4848
}

m5stack/components/M5Unified/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ file(GLOB SRCS
1818
M5GFX/src/lgfx/v1/panel/*.cpp
1919
M5GFX/src/lgfx/v1/platforms/esp32/*.cpp
2020
M5GFX/src/lgfx/v1/platforms/esp32c3/*.cpp
21+
# M5GFX/src/lgfx/v1/platforms/esp32s3/*.cpp
22+
M5GFX/src/lgfx/v1/platforms/esp32p4/*.cpp
2123
M5GFX/src/lgfx/v1/touch/*.cpp
2224
M5Unified/src/*.cpp
2325
M5Unified/src/utility/*.cpp
@@ -27,9 +29,9 @@ file(GLOB SRCS
2729

2830
set(COMPONENT_SRCS ${SRCS})
2931
if (IDF_VERSION_MAJOR GREATER_EQUAL 5)
30-
set(COMPONENT_REQUIRES esp_adc nvs_flash efuse driver esp_timer main_${IDF_TARGET})
32+
set(COMPONENT_REQUIRES esp_adc nvs_flash efuse driver esp_timer esp_lcd main)
3133
else()
32-
set(COMPONENT_REQUIRES esp_adc_cal nvs_flash efuse main)
34+
set(COMPONENT_REQUIRES esp_adc_cal nvs_flash efuse esp_lcd main)
3335
endif()
3436

3537
register_component()

0 commit comments

Comments
 (0)