From cbbf23ce03f1d43e2f52f53e6adc0af0320b9984 Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Tue, 28 Oct 2025 14:53:06 +0100 Subject: [PATCH 1/6] psoc6/Makefile: Adapted for mpy makefile target compliance. Signed-off-by: jaenrig-ifx --- ports/psoc6/Makefile | 146 ++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 100 deletions(-) diff --git a/ports/psoc6/Makefile b/ports/psoc6/Makefile index 96efd44c407d9..330ee87388833 100644 --- a/ports/psoc6/Makefile +++ b/ports/psoc6/Makefile @@ -1,44 +1,24 @@ -BOARD ?= - -# Check if the ModusToolbox setup has been initialized -# If that is the case, get active board -MTB_LIB_DIR = ../../lib/mtb-psoc6-libs -MTB_LIBS_APP_INFO = $(MTB_LIB_DIR)/build/get_app_info.txt - -ifneq ($(wildcard $(MTB_LIBS_APP_INFO)),) - ACTIVE_BOARD = $(shell egrep '^ *MTB_TARGET' $(MTB_LIBS_APP_INFO) | sed 's/^.*= *//g' | sed 's/APP_//') -endif +MTB_LIBS_DIR = ../../lib/mtb-psoc6-libs +include mpconfigport.mk +-include $(MTB_LIBS_DIR)/mtb-bsp-setup.mk -# Get active board from mtb-lib previous runs -# The board is set only after make mtb_init -# has been run. +# The only target allowed to run without BOARD defined is 'submodules' or 'help' ifeq ($(BOARD),) - ifeq ($(ACTIVE_BOARD),) - ifneq ($(MAKECMDGOALS), submodules) - $(error ModusToolbox not initialized. Run "make mtb_init BOARD=" to configure the environment. ) - endif - else - BOARD = $(ACTIVE_BOARD) - endif + ifneq ($(filter $(MAKECMDGOALS),submodules help),$(MAKECMDGOALS)) + $(error No active board is set. Run "make BOARD=" to initialize the ModusToolbox libraries and set the active board. ) + endif endif -BOARD_DIR = boards/$(BOARD) - -$(info PSoC6 board : $(BOARD)) - -ifeq ($(wildcard $(BOARD_DIR)/.),) - $(error Invalid BOARD specified) -endif +BUILD ?= build-$(BOARD) # Files that are generated and needed before the QSTR build. -QSTR_GENERATED_HEADERS = build/pins_qstr.h +QSTR_GENERATED_HEADERS =$(BUILD)/pins_qstr.h # qstr definitions (must come before including py.mk) QSTR_DEFS = qstrdefsport.h $(QSTR_GENERATED_HEADERS) QSTR_GLOBAL_DEPENDENCIES += $(BOARD_DIR)/mpconfigboard.h $(QSTR_GENERATED_HEADERS) -MICROPY_FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py -FROZEN_MANIFEST ?= $(MICROPY_FROZEN_MANIFEST) - +MICROPY_FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py +FROZEN_MANIFEST = $(MICROPY_FROZEN_MANIFEST) ifneq ($(FROZEN_MANIFEST),) CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool @@ -52,7 +32,6 @@ CONFIG ?= Debug # include py core make definitions include ../../py/mkenv.mk -include mpconfigport.mk -include $(BOARD_DIR)/mpconfigboard.mk include $(TOP)/py/py.mk include $(TOP)/extmod/extmod.mk @@ -204,31 +183,33 @@ ifeq ($(MP_LOGGER_DEBUG), 1) CFLAGS += -DMICROPY_LOGGER_DEBUG=1 endif -$(BUILD)/firmware.elf: $(OBJ) $(MPY_MTB_LIBRARIES) $(LIBS) - $(info ) +-include $(TOP)/lib/mtb-psoc6-libs/mtb-makefile.mk + +$(BUILD)/firmware.elf: $(OBJ) $(LIBS) $(info Linking $@ $^ $(LIBS) ...) $(Q) $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) $(info Linking $@ done.) $(Q) $(SIZE) $@ -A $(info ) - $(BUILD)/firmware.hex: $(BUILD)/firmware.elf $(Q) $(OBJCOPY) -O ihex $^ $@ - -# include adapter makefile --include $(TOP)/lib/mtb-psoc6-libs/makefile_mtb.mk +mpy_build: $(BUILD)/firmware.hex MPY_CROSS_FLAGS += -march=armv7m -build: mtb_get_build_flags $(GENERATED_PINS) $(BUILD)/firmware.hex +all: mtb_init mtb_get_build_flags mpy_build + +clean: mtb_clean -all: build +rebuild: clean all -#clean: mtb_clean +qdeploy: mtb_program +deploy: all mtb_program -rebuild: clean mtb_clean all +qdeploy_multi: mtb_program_multi +deploy_multi: all mtb_program_multi TESTS ?=-d psoc6 DEV0 ?= /dev/ttyACM0 @@ -240,7 +221,6 @@ test: $(info Running PSoC6 tests) $(Q) cd ../../tests ; ./run-tests.py --target psoc6 --device $(DEV0) $(TESTS) - MULTI_TESTS ?= $(shell cd ../../tests; find ./psoc6/multi/ -type f -name "*.py") test_multi: @@ -250,70 +230,36 @@ test_multi: $(Q) cd ../../tests ; ./run-multitests.py -i pyb:$(DEV0) -i pyb:$(DEV1) $(MULTI_TESTS) -help: +port_help: @: $(info ) - $(info ----------) - $(info Basic flow) - $(info ----------) - $(info ) - $(info Prior working on a specific board, it is required to initialise ONCE the) - $(info ModusToolbox setup and retrieve all necessary assets for the specified) - $(info board:) - $(info ) - $(info $$ make mtb_init BOARD=) - $(info ) - $(info Then repeatedly build the firmware:) - $(info ) - $(info $$ make ) - $(info ) - $(info and flash the firmware on the device with:) - $(info ) - $(info $$ make program) + $(info Available commands:) + $(info ) + $(info make submodules Initialize port required submodules.) + $(info make BOARD= Build the project for the specified board.) + $(info .. The board name needs to be specified only the first time.) + $(info .. Then simply run "make" to build for the same board.) + $(info make rebuild Build the project after cleaning previous build.) + $(info make deploy Build and deploy the project to the specified board.) + $(info make qdeploy Deploy the project to the specified board without rebuilding.) + $(info make deploy_multi Deploy the project to multiple boards.) + $(info make qdeploy_multi Deploy the project to multiple boards without rebuilding.) + $(info make clean Clean the build files.) + $(info make test Run the on-target test in tests/psoc6 folder. Uses /dev/ttyACM0.) + $(info .. Optionally, pass TESTS variable for change the tests set. ) + $(info make test_multi Run multi-instance tests on-target test in tests/psoc6/multi folder.) + $(info .. Uses /dev/ttyACM0 and /dev/ttyACM1.) + $(info .. Optionally, pass MULTI_TESTS variable for change the tests set. ) + $(info make help Show this help.) $(info ) - $(info 'make program' will also build the .hex file if any changes occurred in the code.) - $(info ) - $(info -------------) - $(info Build targets) - $(info -------------) - $(info ) - $(info The default 'make' target is 'build' when called without arguments.) - $(info - build Compile the MicroPython program binary file. ) - $(info - clean Remove the '/build' folders with all object files and intermediate build support files.) - $(info - rebuild Clean before build.) - $(info ) - $(info ---------------) - $(info Program targets) - $(info ---------------) - $(info ) - $(info - program Flash the board device with the built micropython firmware. ) - $(info - program_multi Flash multiple board deviced. ) $(info Options: ) - $(info - EXT_HEX_FILE An external .hex file can be provided to the program targets, instead of building from the sources.) - $(info ) - $(info ------------) - $(info Test targets) - $(info ------------) - $(info ) - $(info - test Run the on-target test in tests/psoc6 folder. Uses /dev/ttyACM0.) - $(info .. Optionally, pass TESTS variable for change the tests set. ) - $(info - test_multi Run multi-instance tests on-target test in tests/psoc6/multi folder.) - $(info .. Uses /dev/ttyACM0 and /dev/ttyACM1.) - $(info .. Optionally, pass MULTI_TESTS variable for change the tests set. ) - $(info ) - $(info --------------------) - $(info ModusToolbox targets) - $(info --------------------) + $(info EXT_HEX_FILE An external .hex file can be provided to the deploy targets, instead of building from the sources.) $(info ) - $(info - mtb_init BOARD= Add the board support package required firmware assets, set the bsp ) - $(info .. as active in the ModusToolbox project, and retrieves all required additional ) - $(info .. middleware assets for MicroPython. ) - $(info - mtb_deinit Clean all ModusToolbox shared and board support package dependencies assets.) - $(info - mtb_add_bsp Add a board support package. Only the ones integrated in MicroPython are supported. ) - $(info - mtb_set_bsp Set the board as active in the ModusToolbox project. ) +help: port_help mtb_bsp_help mtb_build_help +.DEFAULT_GOAL := all -.PHONY: build test test_multi program_multi help +.PHONY: all clean rebuild deploy qdeploy deploy_multi qdeploy_multi test test_multi help # include py core make definitions include $(TOP)/py/mkrules.mk \ No newline at end of file From 116d247a51fdf3be57f856e22559b110d27146b9 Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Tue, 28 Oct 2025 14:53:51 +0100 Subject: [PATCH 2/6] tools/ci.sh: Renamed as per new target names. Signed-off-by: jaenrig-ifx --- tools/ci.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/ci.sh b/tools/ci.sh index 24a99d24aabb5..c49dc4fe17f1f 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -376,12 +376,11 @@ function ci_psoc6_setup { function ci_psoc6_build { board=$1 - docker exec mtb-ci make mtb_init BOARD=${board} - docker exec mtb-ci make + docker exec mtb-ci make BOARD=${board} } function ci_psoc6_deploy { - docker exec mtb-ci make program + docker exec mtb-ci make deploy } function ci_psoc6_flash_multiple_devices { @@ -390,7 +389,7 @@ function ci_psoc6_flash_multiple_devices { hex_file=$2 devs_file=$3 - docker exec mtb-ci make program_multi BOARD=${board} EXT_HEX_FILE=../../${hex_file} DEVS_FILE=../../${devs_file} + docker exec mtb-ci make qdeploy_multi BOARD=${board} EXT_HEX_FILE=../../${hex_file} DEVS_FILE=../../${devs_file} } function ci_psoc6_run_tests { From c4b4747feb6e76dc231d0a6c12dbbec152048ffa Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Tue, 28 Oct 2025 14:54:36 +0100 Subject: [PATCH 3/6] lib/mtb-psoc6-libs: Updated makefile integration changes. Signed-off-by: jaenrig-ifx --- lib/mtb-psoc6-libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mtb-psoc6-libs b/lib/mtb-psoc6-libs index ed96f14b4c6de..f0f68fa4a9136 160000 --- a/lib/mtb-psoc6-libs +++ b/lib/mtb-psoc6-libs @@ -1 +1 @@ -Subproject commit ed96f14b4c6de314ad0de4f6bc5c2ec8d652d90f +Subproject commit f0f68fa4a91362bb1b88dc1c22d34ba14713fc59 From 1041a04db3e5629d77d423815852c630d1186b4c Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Tue, 28 Oct 2025 15:07:22 +0100 Subject: [PATCH 4/6] github/workflows/ports_psoc6.yml: Updated mpy bin build dir. Signed-off-by: jaenrig-ifx --- .github/workflows/ports_psoc6.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ports_psoc6.yml b/.github/workflows/ports_psoc6.yml index 01adc188b3bff..87b6c1210247a 100644 --- a/.github/workflows/ports_psoc6.yml +++ b/.github/workflows/ports_psoc6.yml @@ -42,7 +42,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: mpy-psoc6_${{ matrix.board }}_${{ steps.commit_sha.outputs.sha_short }} - path: ports/psoc6/build/firmware.hex + path: ports/psoc6/build-${{ matrix.board }}/firmware.hex # Jobs only relevant for Infineon fork on-target-test: From 128db68dcbb4a2adfc47304cc6ae5ac13f12396a Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Tue, 28 Oct 2025 15:21:20 +0100 Subject: [PATCH 5/6] psoc6/README: Updated make targets. Signed-off-by: jaenrig-ifx --- ports/psoc6/README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ports/psoc6/README.md b/ports/psoc6/README.md index a9a712308d10f..9f5bfad57b5ad 100644 --- a/ports/psoc6/README.md +++ b/ports/psoc6/README.md @@ -31,23 +31,29 @@ Retrieve submodules: make submodules -Then initialize the ModusToolbox™ environment: - - make mtb_init BOARD= - Build the firmware: - make + make BOARD=CY8CKIT_062S2_AI + +> [!NOTE] +> The first time we call `make` the board needs to be specified with +> `BOARD=`. This is required as the ModusToolbox libraries need to be +> initialized for the selected board. +> This board will then be set as the default board for subsequent builds, you +> can just call `make` without the `BOARD=` argument. -To build and program the device: +And flash it to the board: - make program + make deploy + +> [!NOTE] +> This will also build the firmware if it has not been built yet. +> Use `deploy` target to avoid rebuilding the firmware. Find more information about the available makefile targets: make help - # Run micropython Use any serial terminal (putty, minicom..) and establish a session with your device with 115200 bauds and 8-N-1 configuration. From 16c0814bd0e26fb1cf382d65c3060f24b8669116 Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Tue, 28 Oct 2025 16:02:01 +0100 Subject: [PATCH 6/6] lib/mtb-psoc6-libs: Updated mtb psoc6 libs. Signed-off-by: jaenrig-ifx --- lib/mtb-psoc6-libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mtb-psoc6-libs b/lib/mtb-psoc6-libs index f0f68fa4a9136..35906e6a7c3be 160000 --- a/lib/mtb-psoc6-libs +++ b/lib/mtb-psoc6-libs @@ -1 +1 @@ -Subproject commit f0f68fa4a91362bb1b88dc1c22d34ba14713fc59 +Subproject commit 35906e6a7c3be8175b0d29009ed00f8a8bc370b8