diff --git a/ports/psoc6/mtb-libs/makefile_mtb.mk b/ports/psoc6/mtb-libs/makefile_mtb.mk index b54df8ef52e2..ae57ba86c15f 100644 --- a/ports/psoc6/mtb-libs/makefile_mtb.mk +++ b/ports/psoc6/mtb-libs/makefile_mtb.mk @@ -17,9 +17,6 @@ MPY_MTB_BOARD_BUILD_OUTPUT_DIR := $(MPY_MTB_BOARD_BUILD_DIR)/$(MPY_MTB_TARGET)/$ MPY_MTB_LIB_NAME = $(file < $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)/artifact.rsp) -MTB_HOME ?= $(HOME)/ModusToolbox -OPENOCD_HOME ?= $(MTB_HOME)/tools_3.0/openocd - # $(info MPY_DIR_OF_MTB_ADAPTER_MAKEFILE : $(MPY_DIR_OF_MTB_ADAPTER_MAKEFILE)) # $(info MPY_MTB_MAIN_MAKEFILE : $(MPY_MTB_MAIN_MAKEFILE)) @@ -30,7 +27,7 @@ OPENOCD_HOME ?= $(MTB_HOME)/tools_3.0/openocd # $(info MPY_MTB_BOARD_BUILD_DIR : $(MPY_MTB_BOARD_BUILD_DIR)) # $(info MPY_MTB_BOARD_BUILD_OUTPUT_DIR : $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)) -mtb_init: mtb_add_bsp mtb_set_bsp mtb_get_libs +mtb_init: mtb_deinit mtb_add_bsp mtb_set_bsp mtb_get_libs $(info ) $(info Initializing ModusToolbox libs for board $(BOARD)) @@ -125,11 +122,23 @@ else HEX_FILE = $(EXT_HEX_FILE) endif +MTB_HOME ?= $(HOME)/ModusToolbox +OPENOCD_HOME ?= $(MTB_HOME)/tools_3.0/openocd + +# Selection of openocd cfg files based on board +OPENOCD_CFG_SEARCH = $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/bsps/TARGET_APP_$(BOARD)/config/GeneratedSource + +ifeq ($(BOARD),CY8CPROTO-062-4343W) +OPENOCD_TARGET_CFG=psoc6_2m.cfg +else ifeq ($(BOARD),CY8CPROTO-063-BLE) +OPENOCD_TARGET_CFG=psoc6.cfg +endif + program: $(PROG_DEPS) @: $(info ) $(info Programming using openocd ...) - openocd -s $(OPENOCD_HOME)/scripts -s $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/bsps/TARGET_APP_$(BOARD)/config/GeneratedSource -c "source [find interface/kitprog3.cfg]; $(SERIAL_ADAPTER_CMD) ; source [find target/psoc6_2m.cfg]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program $(HEX_FILE) verify reset exit;" + openocd -s $(OPENOCD_HOME)/scripts -s $(OPENOCD_CFG_SEARCH) -c "source [find interface/kitprog3.cfg]; $(SERIAL_ADAPTER_CMD) ; source [find target/$(OPENOCD_TARGET_CFG)]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program $(HEX_FILE) verify reset exit;" $(info Programming done.) program_multi: attached_devs diff --git a/tools/psoc6/mpy-psoc6.cmd b/tools/psoc6/mpy-psoc6.cmd index 53a6ee2137f3..b57227c78635 100644 --- a/tools/psoc6/mpy-psoc6.cmd +++ b/tools/psoc6/mpy-psoc6.cmd @@ -20,7 +20,7 @@ exit /b 0 exit /b 0 :cmd_firmware_deploy - call :mpy_firmware_deploy %2 %3 + call :mpy_firmware_deploy %2 %3 %4 exit /b 0 :cmd_device_erase @@ -79,12 +79,24 @@ exit /b 0 :mpy_firmware_deploy - Rem Board is yet unused. In future the suitable target .cfg selection needs to be based on the board. set board=%~1 set hex_file=%~2 + set serial_adapter_sn=%~3 + + if "%board%" == "CY8CPROTO-062-4343W" ( + call set target_cfg=psoc6_2m.cfg + ) else if "%board%" == "CY8CPROTO-063-BLE" ( + call set target_cfg=psoc6.cfg + ) + + if [%serial_adapter_sn%] == [] ( + call set serial_adapter_opt= + ) else ( + call set serial_adapter_opt="adapter serial %serial_adapter_sn%" + ) echo Deploying Micropython... - openocd.exe -s openocd\scripts -s openocd\board -c "source [find interface/kitprog3.cfg]; ; source [find target/psoc6_2m.cfg]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program %hex_file% verify reset exit;" + openocd.exe -s openocd\scripts -s openocd\board -c "source [find interface/kitprog3.cfg]; %serial_adapter_opt% ; source [find target/%target_cfg%]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program %hex_file% verify reset exit;" exit /b 0 @@ -151,19 +163,30 @@ exit /b 0 Rem Board selection set board=%~1 set board_list[0]=CY8CPROTO-062-4343W + set board_list[1]=CY8CPROTO-063-BLE if [%board%]==[] ( echo: echo Supported MicroPython PSoC6 boards echo +---------+-----------------------------------+ echo ^| ID ^| Board ^| echo +---------+-----------------------------------+ - echo ^| 0 ^| CY8CPROTO-062-4343W (default^) ^| + echo ^| 0 ^| CY8CPROTO-062-4343W ^| + echo +---------+-----------------------------------+ + echo ^| 1 ^| CY8CPROTO-063-BLE ^| echo +---------+-----------------------------------+ echo: - echo No user selection required. Only one choice. - set /a board_index=0 - echo: - Rem set /p/( "board_index=Please type the desired board ID. " --> Uncomment and remove preselection above when more options are available + set /P board_index=Please type the desired board ID: + + if !board_index! LSS 0 ( + echo error: board ID not valid + exit /b 1 + ) + + if !board_index! GTR 1 ( + echo error: board ID not valid + exit /b 1 + ) + call set board=%%board_list[!board_index!]%% ) echo MicroPython PSoC6 Board :: %board% @@ -212,19 +235,30 @@ exit /b 0 Rem Board selection set board=%~1 set board_list[0]=CY8CPROTO-062-4343W + set board_list[1]=CY8CPROTO-063-BLE if [%board%]==[] ( echo: echo Supported MicroPython PSoC6 boards echo +---------+-----------------------------------+ echo ^| ID ^| Board ^| echo +---------+-----------------------------------+ - echo ^| 0 ^| CY8CPROTO-062-4343W (default^) ^| + echo ^| 0 ^| CY8CPROTO-062-4343W ^| + echo +---------+-----------------------------------+ + echo ^| 1 ^| CY8CPROTO-063-BLE ^| echo +---------+-----------------------------------+ echo: - echo No user selection required. Only one choice. - set /a board_index=0 - echo: - Rem set /p/( "board_index=Please type the desired board ID. " --> Uncomment and remove preselection above when more options are available + set /P board_index=Please type the desired board ID: + + if !board_index! LSS 0 ( + echo error: board ID not valid + exit /b 1 + ) + + if !board_index! GTR 1 ( + echo error: board ID not valid + exit /b 1 + ) + call set board=%%board_list[!board_index!]%% ) echo MicroPython PSoC6 Board :: %board% diff --git a/tools/psoc6/mpy-psoc6.sh b/tools/psoc6/mpy-psoc6.sh index ffc267f922d7..b59d9d21d557 100755 --- a/tools/psoc6/mpy-psoc6.sh +++ b/tools/psoc6/mpy-psoc6.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + ################### # Script Functions ################### @@ -49,9 +51,22 @@ function help { function mpy_firmware_deploy { board=$1 hex_file=$2 + serial_adapter_sn=$3 + + if [ "$board" = "CY8CPROTO-062-4343W" ]; then + target_cfg=psoc6_2m.cfg + elif [ "$board" = "CY8CPROTO-063-BLE" ]; then + target_cfg=psoc6.cfg + fi + + if [ "$serial_adapter_sn" = "" ]; then + serial_adapter_opt= + else + serial_adapter_opt="adapter serial ${serial_adapter_sn}" + fi echo Deploying firmware... - openocd -s openocd\scripts -s openocd/board -c "source [find interface/kitprog3.cfg]; ; source [find target/psoc6_2m.cfg]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program ${hex_file} verify reset exit;" + openocd -s openocd/scripts -s openocd/board -c "source [find interface/kitprog3.cfg]; ${serial_adapter_opt} ; source [find target/${target_cfg}]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program ${hex_file} verify reset exit;" } function mpy_firmware_download { @@ -124,7 +139,8 @@ board="" function select_board { board=$1 - board_list=(CY8CPROTO-062-4343W) + board_list=(CY8CPROTO-062-4343W \ + CY8CPROTO-063-BLE) if [ "$board" = "" ]; then echo '' @@ -132,18 +148,22 @@ function select_board { echo '+---------+-----------------------------------+' echo '| ID | Board |' echo '+---------+-----------------------------------+' - echo '| 0 | CY8CPROTO-062-4343W (default) |' + echo '| 0 | CY8CPROTO-062-4343W |' + echo '+---------+-----------------------------------+' + echo '| 1 | CY8CPROTO-063-BLE |' echo '+---------+-----------------------------------+' echo '' - echo 'No user selection required. Only one choice.' board_index=0 echo '' # Uncomment and remove preselection above when more options are available - # echo Please type the desired board ID. - # read board_index - + echo Please type the desired board ID. + read board_index + if [ "$board_index" -lt 0 ] || [ "$board_index" -gt 1 ]; then + echo "error: board ID not valid" + exit 1 + fi board=${board_list[${board_index}]} fi @@ -259,7 +279,7 @@ case $1 in mpy_device_setup $2 $3 $4 ;; "firmware-deploy") - mpy_firmware_deploy $2 $3 + mpy_firmware_deploy $2 $3 $4 ;; "device-erase") mpy_device_erase $2 $3