| 1 | --- |
| 2 | title: Target support |
| 3 | --- |
| 4 | |
| 5 | Through both built-in support and CMSIS-Packs, pyOCD supports nearly every Cortex-M MCU that is |
| 6 | available on the market. |
| 7 | |
| 8 | In addition, because pyOCD dynamically inspects the target's debug infrastructure, basic |
| 9 | debug functionality is enabled for any target that correctly implement the CoreSight architecture. |
| 10 | |
| 11 | |
| 12 | ## Target types |
| 13 | |
| 14 | When pyOCD connects to a device, it needs to know what type of device (target) it is controlling. |
| 15 | The type of device is known as the "target type". The target type defines the flash programming |
| 16 | algorithm and determine the device's memory map and other important information. Each target type is |
| 17 | identified by a short string that is either the full or partial part number for the device. For |
| 18 | example, "k64f" or "stm32l072". |
| 19 | |
| 20 | Target types are either built-in to pyOCD or come from CMSIS-Packs. The sections below describe more |
| 21 | about the sources of target support. |
| 22 | |
| 23 | To see the available target types you can run `pyocd list --targets`. This command will print a |
| 24 | table of supported target types, including the target name, vendor, and part number. In addition, it |
| 25 | prints whether each target target is built-in or comes from a CMSIS-Pack. |
| 26 | |
| 27 | |
| 28 | ### Generic target type |
| 29 | |
| 30 | PyOCD furnishes a generic target type named "cortex_m". This target type will be able to connect to |
| 31 | and debug almost any Cortex-M device that correctly implements the CoreSight architecture. However, |
| 32 | flash memory cannot be programmed, and a memory map is not provided. In addition, it may not work |
| 33 | for certain devices that require special handling of operations such as reset and halt. |
| 34 | |
| 35 | Because of the limitations of the generic "cortex_m" target, the warning shown below will be logged |
| 36 | if the target type is "cortex_m". |
| 37 | |
| 38 | 0000183:WARNING:board:Generic cortex_m target type is selected; is this intentional? You will be |
| 39 | able to debug but not program flash. To set the target type use the '--target' argument or |
| 40 | 'target_override' option. Use 'pyocd list --targets' to see available targets. |
| 41 | |
| 42 | |
| 43 | ### Setting the target type |
| 44 | |
| 45 | There are two ways to specify the target type. |
| 46 | |
| 47 | The first is to pass the `--target` command line argument to the `pyocd` tool and pass the target |
| 48 | type name. This argument must be passed every time you run `pyocd` with a subcommand that connects |
| 49 | to the target. |
| 50 | |
| 51 | Another method is to set the `target_override` session option in a `pyocd.yaml` configuration file. The |
| 52 | [configuration file documentation]({% link _docs/configuration.md %}) describes how to do this for a specific debug |
| 53 | probe instead of globally. |
| 54 | |
| 55 | |
| 56 | ### Target type auto-detection |
| 57 | |
| 58 | Certain on-board debug probes know the type of target with which they are connected. The Arm DAPLink |
| 59 | and STLinkV2-1 firmwares both support this feature. When using a probe with target type |
| 60 | auto-detection, you do not need to tell pyOCD |
| 61 | |
| 62 | To check whether your debug probe supports auto-detection, run `pyocd list`. This command prints |
| 63 | a list of all connected debug probes. If a probe does not support auto-detection, the name of the |
| 64 | probe firmware is printed. Whereas probes that do support auto-detection will show up with the |
| 65 | name of the board plus the target type in brackets. |
| 66 | |
| 67 | Example probe listing: |
| 68 | |
| 69 | # Probe/Board Unique ID Target |
| 70 | -------------------------------------------------------------------------------------------------------------------- |
| 71 | 0 Arm DAPLink CMSIS-DAP 02400b0129164e4500440012706e0007f301000097969900 ✔︎ k64f |
| 72 | NXP FRDM-K64F |
| 73 | |
| 74 | 1 STLINK-V3 002500074741500420383733 ✖︎ stm32u585aiix |
| 75 | B-U585I-IOT02A |
| 76 | |
| 77 | 2 STM32 STLink 066EFF555051897267233656 ✔︎ stm32l475xg |
| 78 | DISCO-L475VG-IOT01A |
| 79 | |
| 80 | 3 Segger J-Link OB-K22-NordicSemi 960177309 n/a |
| 81 | |
| 82 | |
| 83 | This example shows several connected debug probes. The first supports extended auto-detection with automatic target type reporting. The second and third support board type detection using pyOCD's built-in table of board types, and show both an installed and uninstalled target type. Finally, the fourth probe does not support auto-detection. |
| 84 | Note how the descriptions of all but the last probe show the name of the board and the target type, for instance |
| 85 | "stm32l475xg" in the "Target" column. |
| 86 | |
| 87 | If the target type is *not* auto-detected, it will default to "cortex_m" unless specified as |
| 88 | described above (see [Generic target type](#generic_target_type) above). In this case, the "Target" column will show "n/a". |
| 89 | |
| 90 | |
| 91 | ## Target configuration |
| 92 | |
| 93 | PyOCD can be configured using several methods. The [configuration]({% link _docs/configuration.md %}) documentation describes how this is done. |
| 94 | |
| 95 | Target types sourced from CMSIS-Packs can define debug variables that the user can configure as needed. See the [debug variables documentation]({% link _docs/open_cmsis_pack_support.md %}#debug_variables) for details. |
| 96 | |
| 97 | |
| 98 | ## Target support sources |
| 99 | |
| 100 | ### Built-in |
| 101 | |
| 102 | PyOCD has built-in support for over 70 popular MCUs from various vendors. |
| 103 | |
| 104 | The best way to see the available built-in targets is |
| 105 | by running `pyocd list --targets`. This command will print a table of supported target types. |
| 106 | Built-in targets will be identified as such in the "SOURCE" column. |
| 107 | New built-in targets are added relatively infrequently since the addition of CMSIS-Pack based targets. |
| 108 | |
| 109 | |
| 110 | ### CMSIS-Packs |
| 111 | |
| 112 | The [Open-CMSIS-Pack](https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec) specification defines the |
| 113 | Device Family Pack (DFP) standard for |
| 114 | distributing device support files. PyOCD uses DFPs as a means to add support for devices that do |
| 115 | not have support built in. This allows pyOCD to support nearly every Cortex-M MCU on the market. It |
| 116 | also means that pyOCD can immediately support newly released devices as soon as the silicon vendor |
| 117 | makes a DFP available. |
| 118 | |
| 119 | The [CMSIS-Pack list](http://www.keil.com/dd2/pack/) web page is the official list of all available |
| 120 | packs. You can choose to download individual packs. |
| 121 | |
| 122 | There are two methods to use a DFP within pyOCD. First, you can let pyOCD fully manage packs for |
| 123 | you, where all you have to do is tell it the part number(s) for which you wish to install support. |
| 124 | Alternatively, you can manually download packs and tell pyOCD which pack files to use. |
| 125 | |
| 126 | *Note:* As with any software release, CMSIS-Packs may be buggy and have incorrect or missing |
| 127 | information about a device. Sometimes memory regions will be missing, attributes of a memory region |
| 128 | or flash algorithm might be wrong, or the flash algorithm itself might be buggy. If you encounter an |
| 129 | issue with a pack, you can report the issue on the [pyOCD GitHub |
| 130 | site](https://www.github.com/pyocd/pyOCD/issues) to let other users know about the problem. You |
| 131 | should also report the issue to the pack vendor so it can be fixed. |
| 132 | |
| 133 | |
| 134 | #### Managed packs |
| 135 | |
| 136 | The `pyocd` tool's `pack` subcommand provides completely automated management of CMSIS-Packs. It |
| 137 | allows you to install new device support with a single command line invocation. |
| 138 | |
| 139 | As part of the pack management, pyOCD keeps an index of all available DFPs. The pack index is a two- |
| 140 | level hierarchy of pack lists, with the top level pointing to individual vendor indexes. Once the |
| 141 | index is downloaded, pyOCD can very quickly locate the DFP that provides support for a given |
| 142 | MCU part number. To learn more about the index, see the [Open-CMSIS-Pack index |
| 143 | files](https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/packIndexFile.html) documentation. |
| 144 | |
| 145 | The two most useful subcommands of the `pack` subcommand are `find` and `install`. The options accept a glob-style |
| 146 | pattern that is matched against MCU part numbers in the index. If the index has not been downloaded yet, that will be |
| 147 | done first, or you can run `pyocd pack update` yourself. The `find` subcommand will print out a list of matching part |
| 148 | numbers and the names of the containing DFPs. `install` performs the same match, but downloads and installs the matching |
| 149 | DFPs. The part number patterns are matched case-insensitively and as a contains comparison. |
| 150 | |
| 151 | For instance, if you know the specific part number of the device you are using, say STM32L073, you |
| 152 | can run this command to install support: |
| 153 | |
| 154 | $ pyocd pack install stm32l073 |
| 155 | |
| 156 | This will download the index if required, then download the STM32L0xx_DFP pack. The |
| 157 | |
| 158 | As another example, to find which pack(s) support the NXP MK26F family, you could run: |
| 159 | |
| 160 | $ pyocd pack find k26 |
| 161 | |
| 162 | This will print a table similar to: |
| 163 | |
| 164 | Part Vendor Pack Version |
| 165 | --------------------------------------------------- |
| 166 | MK26FN2M0CAC18 NXP MK26F18_DFP 11.0.1 |
| 167 | MK26FN2M0VLQ18 NXP MK26F18_DFP 11.0.1 |
| 168 | MK26FN2M0VMD18 NXP MK26F18_DFP 11.0.1 |
| 169 | MK26FN2M0VMI18 NXP MK26F18_DFP 11.0.1 |
| 170 | |
| 171 | Once a DFP is installed, the `pyocd list --targets` command will show the new targets in its output, |
| 172 | and you can immediately begin using the target support with the other `pyocd` subcommands. |
| 173 | |
| 174 | To get a list of all installed packs, use the `pack show` subcommand. |
| 175 | |
| 176 | |
| 177 | #### Manual pack usage |
| 178 | |
| 179 | If you prefer to manually manage packs, or if the managed pack system cannot access online packs |
| 180 | from your network, you can download them yourself from the [official CMSIS-Pack |
| 181 | list](http://www.keil.com/dd2/pack/). The downloaded pack files can be stored wherever you like. |
| 182 | Typically you would group them in a single common directory. Another good option is to place the |
| 183 | pack file used with a project in a project-relative location. |
| 184 | |
| 185 | There are two ways to use a manually downloaded pack. |
| 186 | |
| 187 | The simplest option is to pass the `--pack` option to the `pyocd` tool, specifying the path to the |
| 188 | .pack file. PyOCD does not cache any information about packs used this way, so this argument must be |
| 189 | passed for every invocation in addition to the other arguments. For instance, to run the GDB server, |
| 190 | you might execute `pyocd gdbserver --pack=Keil.STM32L4xx_DFP.2.2.0.pack`. Note that you can pass |
| 191 | multiple `--pack` arguments to pyOCD, which might be useful in a scripted execution of pyOCD. |
| 192 | |
| 193 | For a more permanent solution, use a [`pyocd.yaml` configuration file]({% link _docs/configuration.md %}). In the |
| 194 | config file, set the `pack` session option to either a single .pack file path or a list of paths. Now |
| 195 | when you run the `pyocd` tool, it will automatically pick up the pack file(s) to use. |
| 196 | |
| 197 | Here is an example config file that lists two packs. |
| 198 | ```yaml |
| 199 | pack: |
| 200 | - /Users/admin/CMSIS-Packs/Keil.STM32L0xx_DFP.2.0.0.pack |
| 201 | - /Users/admin/CMSIS-Packs/NXP.MKV58F24_DFP.11.0.0.pack |
| 202 | ``` |
| 203 | |
| 204 | To see the targets provided by a .pack file, run `pyocd list --targets` and pass the approprate |
| 205 | `--pack` option or use a config file, as described above. |
| 206 | |
| 207 | _Note:_ .pack files are simply zip archives with a different extension. To examine the contents of |
| 208 | a pack, change the extension to .zip and extract. |
| 209 | |
| 210 | _Note:_ PyOCD can work with expanded packs just like zipped .pack files. Pass the path to the root directory |
| 211 | of the pack using the `--pack` argument, as above. This is very useful for cases such as development or |
| 212 | debugging of a pack, or for working with other CMSIS-Pack managers that store packs in decompressed form. |
| 213 | |
| 214 | #### CMSIS-Toolbox Run and Debug Management |
| 215 | |
| 216 | Run and Debug Management is a part of the [CMSIS-Toolbox](https://github.com/Open-CMSIS-Pack/cmsis-toolbox) build |
| 217 | information files when working with CSolution projects. Each `*.cbuild-run.yml` file contains relevant run and |
| 218 | debug information for a single `target-type` defined in a CSolution project. The tool gathers and filters the |
| 219 | target information from the BSP and DFP. |
| 220 | |
| 221 | To use the `cbuild-run` target information in PyOCD, pass the `--cbuild-run` option followed by the path to |
| 222 | desired `*.cbuild-run.yml` file. The target information is not cached in PyOCD, which means the command-line |
| 223 | option should always be passed when launching the debugger. |
| 224 | |
| 225 | Because a single `target-type` is described in the YAML file, the `--target` |
| 226 | command-line argument is not needed, as the target is automatically selected. |
| 227 | |
| 228 | More information on CMSIS-Toolbox and the CSolution project format for Run and Debug Management can be found in the |
| 229 | [CMSIS-Toolbox Documentation](https://open-cmsis-pack.github.io/cmsis-toolbox/YML-CBuild-Format/#run-and-debug-management). |