blob: e85f23906329610a7e12ec39106eaf2d80d14170 [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 Okhrimenko883cb5b2024-03-28 17:22:33 +02007This demo supports PSoC 6 chips with the 1M-, 2M-, and 512K-flash on board; XMC7200, XMC7100; CYW20829/CYW89829 chips with no internal flash.
8The evaluation kits are:
9* `CY8CPROTO-062-4343W`
10* `CY8CKIT-062-WIFI-BT`
11* `CY8CPROTO-062S3-4343W`
12* `CYW920829M2EVB-01`
13* `CYW989829M2EVB-01`
14* `CYBLE-416045-EVAL`
15* `CY8CPROTO-063-BLE`
16* `CY8CKIT-062-BLE`
17* `KIT_XMC72_EVK`
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020018
19Functionality:
20
Roman Okhrimenko977b3752022-03-31 14:40:48 +030021* 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 +000022* Prints debug info and the application version to the terminal at baud rate 115200.
Roman Okhrimenko977b3752022-03-31 14:40:48 +030023* Manages the watchdog-timer start in MCUBootApp as one of the confirmation mechanisms.
24* 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 +000025* Can be built for BOOT slot or UPGRADE slot of the bootloader.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020026* Can be used to evaluate `swap` and `overwrite only` upgrade modes.
27
Roman Okhrimenko977b3752022-03-31 14:40:48 +030028### Hardware limitations
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020029
Roman Okhrimenko977b3752022-03-31 14:40:48 +030030This application is created to demonstrate the MCUboot library features.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020031
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300321. 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.
332. 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 +020034
Roman Okhrimenko977b3752022-03-31 14:40:48 +030035### Pre-build action
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020036
Roman Okhrimenko977b3752022-03-31 14:40:48 +030037Pre-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 +020038
Roman Okhrimenko977b3752022-03-31 14:40:48 +030039`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 +020040
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030041The 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 +020042
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000043`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 +020044
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000045`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 +020046
Roman Okhrimenko977b3752022-03-31 14:40:48 +030047`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 +020048
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000049`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 +020050
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000051`USE_EXTERNAL_FLASH` - is set to 1 if a flash map with the `_smif` suffix is chosen.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020052
Roman Okhrimenko977b3752022-03-31 14:40:48 +030053`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 +020054
Roman Okhrimenko977b3752022-03-31 14:40:48 +030055These values are set by specifying the following macros (default values shown):
56`SLOT_SIZE ?= 0x10000` - for slot located in internal flash of PSoC 6 chips
57`SLOT_SIZE ?= 0x40200` - for slot located in external flash of PsoC 6 kits
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +020058`SLOT_SIZE ?= 0x20000` - for slot located in external flash of CYW20829/CYW89829 kits
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020059
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000060During 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 +030061
62**Important (PSoC 6)**: ensure that the RAM areas of CM4-based BlinkyApp and CM0p-based MCUBootApp bootloader do not overlap.
63
64Memory (stack) corruption of the CM0p application can cause a failure if SystemCall-served operations were invoked from CM4.
65
66### Building an application
67
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +020068Toolchain 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**:
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000069
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +020070 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.2/gcc
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030071
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +020072 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.2/gcc
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000073
Roman Okhrimenko977b3752022-03-31 14:40:48 +030074The supported platforms:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020075
76* PSOC_062_2M
77* PSOC_062_1M
78* PSOC_062_512K
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000079* PSOC_063_1M
Roman Okhrimenko977b3752022-03-31 14:40:48 +030080* CYW20829
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +020081* CYW89829
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030082* XMC7200
83* XMC7100
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020084
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000085The root directory is boot/cypress.
86Since 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 +020087
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000088The root directory for is **boot/cypress.**
89Since 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:
90 - **clean_boot** - to clean the BOOT image directory
91 - **clean_upgrade** - to clean the UPGRADE image directory.
92
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030093These 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 +020094
95**Upgrade mode dependency**
96
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +000097`MCUBootApp` can upgrade an image either by overwriting the image from a secondary slot to a primary slot or by swapping the two images.
98To build `BlinkyApp` for different upgrade modes choose flash map JSON file with the corresponding suffix - either `_swap_` or `_overwrite_`.
99But hold in the mind, that `MCUBootApp` and `BlinkyApp` should use the same flash map file!
100For example: to building `MCUBootApp` and `BlinkyApp` in the 'single overwride' mode use the flash map file:
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300101`FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_overwrite_single.json`
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200102
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000103**Single-image**
104
105The 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:
106
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300107 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
108
109 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 +0000110
111To build an image for the secondary (UPGRADE) slot to be used in a single image case with `swap` upgrade type of Bootloader:
112
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300113 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
114
115 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 +0000116
117To build an image for the secondary (UPGRADE) slot to be used in a single image case with `overwrite` upgrade type of Bootloader:
118
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300119 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 +0000120
121**Multi-image**
122
123**NOTE!** `MCUBootApp` should be build with multi-image support as well. Refer to the appropriated section of [MCUBootApp.md](../MCUBootApp/MCUBootApp.md).
124
125`BlinkyApp` can be built in multi-image bootloader configuration for PSoC 6 chips only.
126
127To obtain the appropriate hex files to use with multi-image MCUBootApp, the makefile flag `IMG_ID` is used.
128
129`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:
130
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.json IMG_ID=2
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000132
133When this option is omitted, `IMG_ID=1` is assumed.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200134
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300135**Upgrade image for external memory (PSoC 6)**
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000136__NOTE__: Not supported with `PSoC™ 063` kits.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200137
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300138To prepare MCUBootApp for work with external memory, refer to [ExternalMemory.md](../MCUBootApp/ExternalMemory.md).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200139
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000140To 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 +0200141
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300142 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 +0200143
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200144`ERASED_VALUE` defines the memory cell contents in the erased state. It is `0x00` for PSoC 6 internal flash and `0xff` for S25FL512S. For `CYW20829` default value is `0xff` since it only uses an external flash.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200145
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000146In the multi-image configuration, an upgrade image for the second application is built using the command:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200147
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300148 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 +0200149
150**Encrypted upgrade image**
151
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300152To prepare MCUBootApp for work with an encrypted upgrade image, refer to [MCUBootApp.md](../MCUBootApp/MCUBootApp.md).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200153
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300154To 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 +0200155
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300156 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 +0200157
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000158This 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 +0200159
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200160Refer to [CYW20829.md](../platforms/CYW20829.md) for details of encrypted image build for the CYW20829/CYW89829 platforms.
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300161
162### Complete build flags description
163- `BUILDCFG` - The configuration type
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200164 - Release
165 - Debug
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300166- `VERBOSE` - The build verbosity level
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200167 - 0 (default) - less build info
168 - 1 - verbose output of compilation
169- `PLATFORM`
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300170 - `PSOC_062_2M`
171 - `PSOC_062_1M`
172 - `PSOC_062_512K`
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200173 - `CYW20829`
174 - `CYW89829`
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300175 - `XMC7200`
176 - `XMC7100`
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300177- `SLOT_SIZE` - The size of the primary/secondary slot of MCUBootApp. This app will be used with
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200178 - 0x%VALUE%
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300179- `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 +0000180 - `BOOT (default)` - to build an image for the primary (BOOT) slot.
181 - `UPGRADE` - to build an image for the secondary (UPGRADE) slot.
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300182- `ERASED_VALUE` - Define memory cell contents in the erased state.
183 - `0x0` - Internal memory.
184 - `0xff` - External memory.
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000185- `TOOLCHAIN_PATH` - The path to the GCC compiler to use for the build.
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200186 - Example: TOOLCHAIN_PATH=/home/user/ModusToolbox/tools_3.2/gcc
187 - Example: TOOLCHAIN_PATH=C:/ModusToolbox/tools_3.2/gcc
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200188
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300189Flags 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 +0200190
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300191- `USE_OVERWRITE` - Define the Upgrade mode type of `MCUBootApp` to use with this app.
192 - `1` - For Overwrite mode.
193 - `0` - (default) For Swap Upgrade mode.
194- `USE_EXTERNAL_FLASH` - Define support of external flash.
195 - `1` - external flash is present.
196 - `0` - external flash is absent.
197- `USE_XIP` - Define support of eXecute in Place mode.
198 - `0` - Not used
199 - `1` - Used
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200200
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300201### Post-build
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200202
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +0300203The 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 +0200204
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300205Flags passed to `imgtool` for a signature are defined in the `SIGN_ARGS` variable in BlinkyApp.mk.
206
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200207For `CYWxx829` and `XMC7x00` platforms, `cysecuretools` is used for the image signing.
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300208
209### How to program an application
210
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000211BlinkyApp 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 +0200212
2131. Direct usage of OpenOCD.
214
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300215Connect 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 +0200216
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200217The OpenOCD package is supplied with ModusToolbox IDE and can be found in the ModusToolbox installation folder `ModusToolbox/tools_3.2/openocd`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200218
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000219Open 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 +0200220
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200221 export OPENOCD_PATH=/Applications/ModusToolbox/tools_3.2/openocd
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200222
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000223 ${OPENOCD_PATH}/bin/openocd -s ${OPENOCD_PATH}/scripts \
224 -f ${OPENOCD_PATH}/scripts/interface/kitprog3.cfg \
225 -f ${OPENOCD_PATH}/scripts/target/psoc6_2m.cfg \
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200226 -c "init; reset init; program PATH_TO_APPLICATION.hex" \
227 -c "resume; reset; exit"
228
2292. Using GUI tool `Cypress Programmer`
230
231Follow [link](https://www.cypress.com/products/psoc-programming-solutions) to download.
232
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300233Connect 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 +0200234
2353. Using `DAPLINK`.
236
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300237Connect 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 +0200238
239**Hex file names to use for programming**
240
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300241`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 +0200242
243These files are ready to be flashed to the board:
244
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300245* **BlinkyApp.hex** from the `boot` folder
246* **BlinkyApp_upgrade.hex** from the `upgrade` folder
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200247
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300248The `BlinkyApp_unsigned.hex` hex file is also preserved in both cases for possible troubleshooting.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200249
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300250**Important: When Swap status Upgrade mode is used**
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200251
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300252 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 +0200253
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300254**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 +0200255
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300256If 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 +0200257
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300258To 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 +0200259
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300260To 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 +0200261
262 $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"
263
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300264To 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 +0200265
266 $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"
267
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300268In 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 +0200269
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300270 $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 +0200271
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300272### Example terminal output
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200273
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300274When the user application is programmed in the boot slot:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200275
276 ===========================
277 [BlinkyApp] BlinkyApp v1.0 [CM4]
278 ===========================
279 [BlinkyApp] GPIO initialized
280 [BlinkyApp] UART initialized
281 [BlinkyApp] Retarget I/O set to 115200 baudrate
282 [BlinkyApp] Red led blinks with 1 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
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200285
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300286When the user application is programmed in the upgrade slot and the upgrade procedure was successful:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200287
288 ===========================
289 [BlinkyApp] BlinkyApp v2.0 [+]
290 ===========================
291 [BlinkyApp] GPIO initialized
292 [BlinkyApp] UART initialized
293 [BlinkyApp] Retarget I/O set to 115200 baudrate
294 [BlinkyApp] Red led blinks with 0.25 sec period
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +0000295 [BlinkyApp] Update watchdog timer started in MCUBootApp to mark the successful start of the user app
296 [BlinkyApp] Turn off the watchdog timer
297 [BlinkyApp] Try to set img_ok to confirm the upgrade image
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200298 [BlinkyApp] SWAP Status : Image OK was set at 0x10027fe8.