blob: dc29c4c43773c5e7818de3d2cc4dbdbd91a80efb [file] [log] [blame] [view]
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +00001## Blinking LED test application for MCUBootApp bootloader application
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +02002
3### Description
4
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +00005Implements a simple Blinky LED application to demonstrate the MCUBootApp bootloader application operation for the boot and upgrade processes.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +02006
Roman Okhrimenko977b3752022-03-31 14:40:48 +03007It is validated and started by MCUBootApp, which is running on the CM0p core of PSoC 6 devices, or CM33 core for the CYW20829 device.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +02008
9Functionality:
10
Roman Okhrimenko977b3752022-03-31 14:40:48 +030011* Blinks red LED with 2 different rates, depending on the image type - BOOT or UPGRADE.
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000012* Prints debug info and the application version to the terminal at baud rate 115200.
Roman Okhrimenko977b3752022-03-31 14:40:48 +030013* Manages the watchdog-timer start in MCUBootApp as one of the confirmation mechanisms.
14* Sets a special bit in flash to confirm that the image is operable (UPGRADE image).
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000015* Can be built for BOOT slot or UPGRADE slot of the bootloader.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020016* Can be used to evaluate `swap` and `overwrite only` upgrade modes.
17
Roman Okhrimenko977b3752022-03-31 14:40:48 +030018### Hardware limitations
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020019
Roman Okhrimenko977b3752022-03-31 14:40:48 +030020This application is created to demonstrate the MCUboot library features.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020021
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300221. Port/pin `P5_0` and `P5_1` are used to configure a serial port for debug prints. These pins are the most commonly used for serial port connection among available Cypress PSoC 6 kits. To use custom hardware with this application, change the definitions of `CY_DEBUG_UART_TX` and `CY_DEBUG_UART_RX` in `main.c` of BlinkyApp to port/pin pairs corresponding to your design.
232. Port `GPIO_PRT13` pin `7U` is used to define the user connection-LED. This pin is the most commonly used for USER_LED connection among available Cypress PSoC 6 kits. To use custom hardware with this application, change the definitions of `LED_PORT` and `LED_PIN` in `main.c` of BlinkyApp to port/pin pairs corresponding to your design.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020024
Roman Okhrimenko977b3752022-03-31 14:40:48 +030025### Pre-build action
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020026
Roman Okhrimenko977b3752022-03-31 14:40:48 +030027Pre-build action is implemented to define the start address and flash size, as well as the RAM start address and BlinkyApp size.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020028
Roman Okhrimenko977b3752022-03-31 14:40:48 +030029`FLASH_MAP` `make` parameter is used to provide an input file for pre-build action. Refer to `MCUBootApp.md` for details.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020030
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030031The result of the pre-build script is an auto-generated `memorymap.mk` file with a set of makefile flags:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020032
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000033`PRIMARY_IMG_START` - start address of the primary image in flash, this value is defined in the JSON flash map as the `"value"` field of the address section for `"application_#"`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020034
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000035`SECONDARY_IMG_START`- start address of the secondary image in flash, this value is defined in the JSON flash map as the `"upgrade_address"` field of the `"address"` section for `"application_#"`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020036
Roman Okhrimenko977b3752022-03-31 14:40:48 +030037`SLOT_SIZE` - slot size for the primary and the secondary images, this value is taken from `"value"` field of `"size"` section of `"application_#"` from JSON file.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020038
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000039`BOOTLOADER_SIZE` - size of the Bootloader application, this value is defined in the JSON flash map as the `"size"` field of the address section for `"bootloader"`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020040
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000041`USE_EXTERNAL_FLASH` - is set to 1 if a flash map with the `_smif` suffix is chosen.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020042
Roman Okhrimenko977b3752022-03-31 14:40:48 +030043`USE_XIP` - is set to 1 if the "external_flash" section with "mode": "XIP" is present in the flash map file.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020044
Roman Okhrimenko977b3752022-03-31 14:40:48 +030045These values are set by specifying the following macros (default values shown):
46`SLOT_SIZE ?= 0x10000` - for slot located in internal flash of PSoC 6 chips
47`SLOT_SIZE ?= 0x40200` - for slot located in external flash of PsoC 6 kits
48`SLOT_SIZE ?= 0x20000` - for slot located in external flash of CYW20829 kits
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020049
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000050During pre-build action, the GCC preprocessor is used to generate the target linker script from a template `BlinkyApp_template.ld`.
Roman Okhrimenko977b3752022-03-31 14:40:48 +030051
52**Important (PSoC 6)**: ensure that the RAM areas of CM4-based BlinkyApp and CM0p-based MCUBootApp bootloader do not overlap.
53
54Memory (stack) corruption of the CM0p application can cause a failure if SystemCall-served operations were invoked from CM4.
55
56### Building an application
57
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000058Toolchain is set by default in `toolchains.mk` file, depending on `COMPILER` makefile variable. MCUBoot is currently support only `GCC_ARM` as compiler. Toolchain path can be redefined, by setting `TOOLCHAIN_PATH` build flag to desired toolchain path. Below is an example on how to set toolchain path from **ModusToolbox IDE 3.0**:
59
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030060 make clean_boot app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M BUILDCFG=Debug FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_swap_single.json TOOLCHAIN_PATH=c:/Users/${USERNAME}/ModusToolbox/tools_3.0/gcc
61
62 make clean_boot app APP_NAME=BlinkyApp PLATFORM=XMC7200 BUILDCFG=Debug FLASH_MAP=platforms/memory/XMC7000/flashmap/xmc7000_overwrite_single.json PLATFORM_CONFIG=platforms/memory/XMC7000/flashmap/xmc7200_platform.json CORE=CM7 APP_CORE=CM7 CORE_ID=0 IMG_TYPE=BOOT IMG_ID=1 TOOLCHAIN_PATH=c:/Users/${USERNAME}/ModusToolbox/tools_3.0/gcc
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000063
Roman Okhrimenko977b3752022-03-31 14:40:48 +030064The supported platforms:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020065
66* PSOC_062_2M
67* PSOC_062_1M
68* PSOC_062_512K
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000069* PSOC_063_1M
Roman Okhrimenko977b3752022-03-31 14:40:48 +030070* CYW20829
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030071* XMC7200
72* XMC7100
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020073
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000074The root directory is boot/cypress.
75Since BlinkyApp built for BOOT or UPGRADE slot has its own folder BlinkyApp/out/boot or BlinkyApp/out/upgrade consider using following jobs to clear build folder before build.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020076
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000077The root directory for is **boot/cypress.**
78Since BlinkyApp built for BOOT or UPGRADE slot has its own folder `BlinkyApp/out/boot` or `BlinkyApp/out/upgrade` consider using following jobs to clear build folder before build:
79 - **clean_boot** - to clean the BOOT image directory
80 - **clean_upgrade** - to clean the UPGRADE image directory.
81
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030082These jobs also remove auto-generated files 'memorymap.mk' and 'memory.h', which is required to eliminate possible errors.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020083
84**Upgrade mode dependency**
85
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000086`MCUBootApp` can upgrade an image either by overwriting the image from a secondary slot to a primary slot or by swapping the two images.
87To build `BlinkyApp` for different upgrade modes choose flash map JSON file with the corresponding suffix - either `_swap_` or `_overwrite_`.
88But hold in the mind, that `MCUBootApp` and `BlinkyApp` should use the same flash map file!
89For example: to building `MCUBootApp` and `BlinkyApp` in the 'single overwride' mode use the flash map file:
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030090`FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_overwrite_single.json`
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020091
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000092**Single-image**
93
94The following command will build BlinkyApp as a regular HEX file for the primary (BOOT) slot to be used in a single image case with `swap` upgrade type of Bootloader:
95
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030096 make clean_boot app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=BOOT FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_swap_single.json IMG_ID=1
97
98 make clean_boot app APP_NAME=BlinkyApp PLATFORM=XMC7200 BUILDCFG=Debug FLASH_MAP=platforms/memory/XMC7000/flashmap/xmc7000_overwrite_single.json PLATFORM_CONFIG=platforms/memory/XMC7000/flashmap/xmc7200_platform.json CORE=CM7 APP_CORE=CM7 CORE_ID=0 IMG_TYPE=BOOT IMG_ID=1
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000099
100To build an image for the secondary (UPGRADE) slot to be used in a single image case with `swap` upgrade type of Bootloader:
101
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300102 make clean_upgrade app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_swap_single.json IMG_ID=1
103
104 make clean_upgrade app APP_NAME=BlinkyApp PLATFORM=XMC7200 BUILDCFG=Debug FLASH_MAP=platforms/memory/XMC7000/flashmap/xmc7000_overwrite_single.json PLATFORM_CONFIG=platforms/memory/XMC7000/flashmap/xmc7200_platform.json CORE=CM7 APP_CORE=CM7 CORE_ID=0 IMG_TYPE=UPGRADE IMG_ID=1
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000105
106To build an image for the secondary (UPGRADE) slot to be used in a single image case with `overwrite` upgrade type of Bootloader:
107
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300108 make clean_upgrade app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_overwrite_single.json IMG_ID=1
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000109
110**Multi-image**
111
112**NOTE!** `MCUBootApp` should be build with multi-image support as well. Refer to the appropriated section of [MCUBootApp.md](../MCUBootApp/MCUBootApp.md).
113
114`BlinkyApp` can be built in multi-image bootloader configuration for PSoC 6 chips only.
115
116To obtain the appropriate hex files to use with multi-image MCUBootApp, the makefile flag `IMG_ID` is used.
117
118`IMG_ID` flag value should correspond to the `application_#` number of JSON flash map file used for the build. For example, to build `BlinkyApp` for the UPGRADE slot of the second image following command is used:
119
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300120 make clean_upgrade app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_overwrite_single.json IMG_ID=2
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000121
122When this option is omitted, `IMG_ID=1` is assumed.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200123
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300124**Upgrade image for external memory (PSoC 6)**
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000125__NOTE__: Not supported with `PSoC™ 063` kits.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200126
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300127To prepare MCUBootApp for work with external memory, refer to [ExternalMemory.md](../MCUBootApp/ExternalMemory.md).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200128
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000129To build a `BlinkyApp` upgrade image for external memory to be used in a single image configuration with overwrite upgrade mode, use the command:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200130
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300131 make clean_upgrade app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_overwrite_single_smif.json IMG_ID=1
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200132
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300133`ERASED_VALUE` defines the memory cell contents in the erased state. It is `0x00` for PSoC 6 internal flash and `0xff` for S25FL512S. For `CYW20289` default value is `0xff` since it only uses an external flash.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200134
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000135In the multi-image configuration, an upgrade image for the second application is built using the command:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200136
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300137 make clean_upgrade app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_overwrite_multi_smif.json IMG_ID=2
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200138
139**Encrypted upgrade image**
140
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300141To prepare MCUBootApp for work with an encrypted upgrade image, refer to [MCUBootApp.md](../MCUBootApp/MCUBootApp.md).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200142
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300143To obtain an encrypted upgrade image of BlinkyApp, pass extra flag `ENC_IMG=1` in the command line, for example:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200144
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300145 make clean_upgrade app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_overwrite_single.json IMG_ID=1 ENC_IMG=1
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200146
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000147This also suggests that the user has already placed a corresponding *.pem key in the \keys folder. The key variables are defined in the root Makefile as SIGN_KEY_FILE and ENC_KEY_FILE
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200148
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000149Refer to [CYW20829.md](../platforms/CYW20829.md) for details of encrypted image build for the CYW20289 platfrom.
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300150
151### Complete build flags description
152- `BUILDCFG` - The configuration type
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200153 - Release
154 - Debug
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300155- `VERBOSE` - The build verbosity level
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200156 - 0 (default) - less build info
157 - 1 - verbose output of compilation
158- `PLATFORM`
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300159 - `PSOC_062_2M`
160 - `PSOC_062_1M`
161 - `PSOC_062_512K`
162 - `CYW20289`
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300163 - `XMC7200`
164 - `XMC7100`
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300165- `SLOT_SIZE` - The size of the primary/secondary slot of MCUBootApp. This app will be used with
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200166 - 0x%VALUE%
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300167- `IMG_TYPE` - The slot of MCUBootApp, for which the image is being built.
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000168 - `BOOT (default)` - to build an image for the primary (BOOT) slot.
169 - `UPGRADE` - to build an image for the secondary (UPGRADE) slot.
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300170- `ERASED_VALUE` - Define memory cell contents in the erased state.
171 - `0x0` - Internal memory.
172 - `0xff` - External memory.
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000173- `TOOLCHAIN_PATH` - The path to the GCC compiler to use for the build.
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300174 - Example: TOOLCHAIN_PATH=/home/user/ModusToolbox/tools_2.4/gcc
175 - Example: TOOLCHAIN_PATH=C:/ModusToolbox/tools_2.4/gcc
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200176
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300177Flags are set by pre-build action. Result of pre-build can be found in autogenerated file `BlinkyApp/memorymap.mk`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200178
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300179- `USE_OVERWRITE` - Define the Upgrade mode type of `MCUBootApp` to use with this app.
180 - `1` - For Overwrite mode.
181 - `0` - (default) For Swap Upgrade mode.
182- `USE_EXTERNAL_FLASH` - Define support of external flash.
183 - `1` - external flash is present.
184 - `0` - external flash is absent.
185- `USE_XIP` - Define support of eXecute in Place mode.
186 - `0` - Not used
187 - `1` - Used
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200188
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300189### Post-build
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200190
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300191The post-build action is executed at the compile time for `BlinkyApp`. For the `XMC7200` `XMC7100` `PSOC_062_2M`, `PSOC_062_1M`, `PSOC_062_512K` platforms, it calls `imgtool` from `MCUboot` scripts and adds a signature to the compiled image.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200192
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300193Flags passed to `imgtool` for a signature are defined in the `SIGN_ARGS` variable in BlinkyApp.mk.
194
195For `CYW20829`, `cysecuretools` is used for the image signing.
196
197### How to program an application
198
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000199BlinkyApp firmware can be programmed in different ways. The following instructions assume the usage of one of Cypress development kits, for example, `CY8CPROTO_062_4343W`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200200
2011. Direct usage of OpenOCD.
202
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300203Connect a board to your computer. Switch Kitprog3 to DAP-BULK mode by clicking the `SW3 MODE` button until `LED2 STATUS` constantly shines.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200204
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300205The OpenOCD package is supplied with ModusToolbox IDE and can be found in the ModusToolbox installation folder `ModusToolbox/tools_2.4/openocd`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200206
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000207Open the terminal application and execute the following command after substitution of the `PATH_TO_APPLICATION.hex` and `OPENOCD_PATH` paths:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200208
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000209 export OPENOCD_PATH=/Applications/ModusToolbox/tools_2.4/openocd
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200210
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000211 ${OPENOCD_PATH}/bin/openocd -s ${OPENOCD_PATH}/scripts \
212 -f ${OPENOCD_PATH}/scripts/interface/kitprog3.cfg \
213 -f ${OPENOCD_PATH}/scripts/target/psoc6_2m.cfg \
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200214 -c "init; reset init; program PATH_TO_APPLICATION.hex" \
215 -c "resume; reset; exit"
216
2172. Using GUI tool `Cypress Programmer`
218
219Follow [link](https://www.cypress.com/products/psoc-programming-solutions) to download.
220
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300221Connect the board to your computer. Switch Kitprog3 to DAP-BULK mode by clicking the `SW3 MODE` button until `LED2 STATUS` constantly shines. Open `Cypress Programmer` and click `Connect`, then choose the hex file `MCUBootApp.hex` or `BlinkyApp.hex`, and finally click `Program`. Check the log to ensure that the programming is successful. Reset the board.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200222
2233. Using `DAPLINK`.
224
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300225Connect the board to your computer. Switch embedded Kitprog3 to `DAPLINK` mode by clicking the `SW3 MODE` button until `LED2 STATUS` blinks fast and the USB mass storage device displays in the OS. Drag and drop the `hex` files to be programmed to the `DAPLINK` drive in your OS.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200226
227**Hex file names to use for programming**
228
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300229`BlinkyApp` always produces build artifacts in two separate folders: `BlinkyApp/out/PSOC_062_2M/Debug/boot` and `BlinkyApp/out/PSOC_062_2M/Debug/upgrade`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200230
231These files are ready to be flashed to the board:
232
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300233* **BlinkyApp.hex** from the `boot` folder
234* **BlinkyApp_upgrade.hex** from the `upgrade` folder
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200235
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300236The `BlinkyApp_unsigned.hex` hex file is also preserved in both cases for possible troubleshooting.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200237
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300238**Important: When Swap status Upgrade mode is used**
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200239
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300240 While using this application in a system with the `swap` type of upgrade, refer first to the [MCUBootApp.md](../MCUBootApp/MCUBootApp.md) section **SWAP/Expected lifecycle**.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200241
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300242**BlinkyApp.hex** can be programmed to a device once. All firmware upgrades are delivered using the secondary (UPGRADE) slot, thus a **BlinkyApp_upgrade.hex** image.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200243
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300244If the user tries to program **BlinkyApp.hex** to the primary slot directly for the second time - **system state should be reset**.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200245
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300246To reset the system state, erase at least the `swap status partition` area in flash - see the addresses in the [MCUBootApp.md](../MCUBootApp/MCUBootApp.md) paragraph **Memory maps**.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200247
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300248To erase the swap status partition area in MCUBootApp with single-image configuration with the default memory map, use the `OpenOCD` command:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200249
250 $OPENOCD_PATH/bin/openocd -s "$OPENOCD_PATH/scripts" -f "$OPENOCD_PATH/ scripts/interface/kitprog3.cfg" -f "$OPENOCD_PATH/scripts/target/psoc6_2m.cfg" -c "init; reset init" -c "flash erase_address 0x10038000 0x1000" -c "reset; shutdown"
251
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300252To erase the swap status partition area in MCUBootApp with multi-image configuration with the default memory map, use the `OpenOCD` command:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200253
254 $OPENOCD_PATH/bin/openocd -s "$OPENOCD_PATH/scripts" -f "$OPENOCD_PATH/ scripts/interface/kitprog3.cfg" -f "$OPENOCD_PATH/scripts/target/psoc6_2m.cfg" -c "init; reset init" -c "flash erase_address 0x10078000 0x2000" -c "reset; shutdown"
255
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300256In both cases, it is easier to erase the whole device flash or all flash after MCUBootApp. This command erases all flash after MCUBootApp, including the primary, secondary, and swap status partiton:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200257
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300258 $OPENOCD_PATH/bin/openocd -s "$OPENOCD_PATH/scripts" -f "$OPENOCD_PATH/ scripts/interface/kitprog3.cfg" -f "$OPENOCD_PATH/scripts/target/psoc6_2m.cfg" -c "init; reset init" -c "flash erase_address 0x10018000 0x1E8000" -c "reset; shutdown"
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200259
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300260### Example terminal output
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200261
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300262When the user application is programmed in the boot slot:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200263
264 ===========================
265 [BlinkyApp] BlinkyApp v1.0 [CM4]
266 ===========================
267 [BlinkyApp] GPIO initialized
268 [BlinkyApp] UART initialized
269 [BlinkyApp] Retarget I/O set to 115200 baudrate
270 [BlinkyApp] Red led blinks with 1 sec period
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000271 [BlinkyApp] Update watchdog timer started in MCUBootApp to mark the successful start of the user app
272 [BlinkyApp] Turn off the watchdog timer
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200273
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300274When the user application is programmed in the upgrade slot and the upgrade procedure was successful:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200275
276 ===========================
277 [BlinkyApp] BlinkyApp v2.0 [+]
278 ===========================
279 [BlinkyApp] GPIO initialized
280 [BlinkyApp] UART initialized
281 [BlinkyApp] Retarget I/O set to 115200 baudrate
282 [BlinkyApp] Red led blinks with 0.25 sec period
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000283 [BlinkyApp] Update watchdog timer started in MCUBootApp to mark the successful start of the user app
284 [BlinkyApp] Turn off the watchdog timer
285 [BlinkyApp] Try to set img_ok to confirm the upgrade image
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200286 [BlinkyApp] SWAP Status : Image OK was set at 0x10027fe8.