Skip to content

Commit 8e4acc1

Browse files
committed
Docs: improve adding_new_targets.md.
1 parent 7e5cb9e commit 8e4acc1

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

docs/adding_new_targets.md

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,59 @@ This guide describes how to manually add support for a new target and/or board t
55
cases you do not need to add a builtin target anymore, and can use pyOCD's support for CMSIS
66
Device Family Packs.
77

8-
For background information, review the [architecture overview](architecture.md) document first.
8+
For background information, review the [architecture overview](architecture.md) document first. The
9+
[CMSIS Pack documentation](https://arm-software.github.io/CMSIS_5/Pack/html/index.html) may also be helpful.
10+
11+
12+
### Device Family Pack intro
13+
14+
The instructions below assume you have a CMSIS Device Family Pack (DFP) available for your target. See the
15+
[list of all publicly available Packs](https://www.keil.com/dd2/pack/) to find and download the DFP for your
16+
target.
17+
18+
A DFP is simply a zip file with a .pack extension. To extract the contents you can change the extension to
19+
.zip and extract with your favourite archive utility.
20+
21+
For this context, the most important thing inside the DFP are .FLM files that contain the flash programming
22+
algorithms used in step 5 below. The .pdsc file can also be useful. It is an XML file that contains details
23+
such as the memory map for the target devices described by the DFP.
24+
925

1026
### Steps to add a new target
1127

1228
1. Create a new `CoreSightTarget` subclass in a file under `pyocd/target/builtin/`. You can copy one of the
1329
existing target files like `pyocd/target/builtin/target_ncs36510.py` and rename the class.
1430

15-
The target source file name must follow
16-
the pattern "target\_\<device>.py", where "\<device>" is the device's `Dname` or `Dvariant` part
17-
number value from the appropriate CMSIS Device Family Pack (DFP). For instance,
18-
`target_LPC54608J512ET180.py`. You may substitute an "x" for certain fields in the part number,
19-
such as a package or pin count code, temperature code, or memory size (if multiple memory sizes
20-
are supported via classes within the one source file). For instance, `target_STM32F412xx.py`.
21-
If the device doesn't have a DFP, then use a similar, complete part number.
31+
The target source file name must follow the pattern "target\_\<device>.py", where "\<device>" is the
32+
device's `Dname` or `Dvariant` part number value from the appropriate CMSIS Device Family Pack (DFP). For
33+
instance, `target_LPC54608J512ET180.py`. You may substitute an "x" for certain fields in the part number,
34+
such as a package or pin count code, temperature code, or memory size (if multiple memory sizes are
35+
supported via classes within the one source file). For instance, `target_STM32F412xx.py`. If the device
36+
doesn't have a DFP, then use a similar, complete part number.
2237

2338
2. Set the `VENDOR` class attribute on the `CoreSightTarget` subclass. The vendor name must be one
2439
of the standard values defined by the
2540
[`DeviceVendorEnum`](http://arm-software.github.io/CMSIS_5/Pack/html/pdsc_family_pg.html#DeviceVendorEnum)
26-
type for CMSIS Packs.
41+
type for CMSIS Packs. (If the vendor is not listed, please contact Arm.)
42+
43+
3. You may optionally add `PART_NUMBER` and/or `PART_FAMILIES` class attributes to your target class. T
2744

28-
3. Create the target's memory map from information in the device's reference manual. The memory map
29-
should be a `memoryMap` class attribute of the target class. Modifying an existing memory map is
45+
4. Create the target's memory map from information in the device's reference manual. The memory map
46+
should be a `MEMORY_MAP` class attribute of the target class. Modifying an existing memory map is
3047
easiest, and there are many examples in the other targets.
3148

32-
4. To create the flash algo, the recommended method is to use the [`tools/generate_blobs.py`](https://github.com/mbedmicro/FlashAlgo/blob/master/scripts/generate_blobs.py) script from the [FlashAlgo](https://github.com/mbedmicro/FlashAlgo) project. This script will
33-
generate output files in several forms, including Python for pyOCD, from an .FLM file that is
34-
included as part of a CMSIS DFP.
49+
5. To create the flash algo, the recommended method is to use the
50+
[`scripts/generate_flash_algo_.py`](https://github.com/pyocd/pyocd/scripts/generate_flash_algo_.py) script
51+
included in the pyocd repo. This script will generate an output file in the form required for pyocd from
52+
an .FLM file that is included as part of a CMSIS DFP.
3553

3654
1. Locate the correct .FLM file from the DFP for your target.
3755

38-
2. Run `generate_blobs.py \<path to FLM>`. It will write the output files to the same directory
39-
containing the source .FLM file.
56+
2. Run `scripts/generate_flash_algo_.py \<path to FLM>`. It will write the output files to the working directory
57+
from where you called the script.
4058

41-
3. The `py_blob_orig.py` output file contains the flash algo for pyOCD. Copy the `flash_algo`
42-
dictionary into the target source file.
59+
3. The `pyocd_blob.py` output file contains the Python code for the flash algo. Copy the `FLASH_ALGO_*`
60+
dictionary (the name will have a suffix based on the FLM name) into the target source file.
4361

4462
4. Review the addresses in the `flash_algo` dictionary to make sure they are valid. The memory
4563
layout should look like:
@@ -58,13 +76,19 @@ For background information, review the [architecture overview](architecture.md)
5876
`analyzer_supported` key to True and the `analyzer_address` to the start address for an
5977
unused range of (1224 + 4 * number-of-flash-pages) bytes of RAM.
6078

61-
6. Pass the `flash_algo` dict for the `algo` parameter to the `FlashRegion` constructor in
79+
6. Pass the `FLASH_ALGO_*` dict for the `algo` parameter to the `FlashRegion` constructor in
6280
your memory map. This binds the flash algo to that flash memory region.
6381

64-
5. Edit `pyocd/target/builtin/__init__.py` to import your target source file and add your new target
82+
6. If the target has multiple flash algos for different flash types, repeat step 5 as necessary.
83+
84+
7. Edit `pyocd/target/builtin/__init__.py` to import your target source file and add your new target
6585
to the `BUILTIN_TARGETS` dict.
6686

67-
Now your new target is available for use via the `--target` command line option!
87+
8. You or your employer own the copyright on the new code, so make sure you set the copyright on the new target file.
88+
You should also add a copyright to any existing files you modified.
89+
90+
Now your new target is available for use via the `--target` command line option! You can test its availability
91+
by running `pyocd list --targets --name <target-name>`.
6892

6993

7094
### Steps to add a new board
@@ -73,11 +97,11 @@ This section only applies if your board has an on-board debug probe that either:
7397

7498
- Uses the [Arm DAPLink](https://github.com/ARMmbed/DAPLink) firmware. DAPLink presents the board ID
7599
as the first 4 characters of the USB serial number.
76-
- Uses the STLinkV2-1 firmware and the board is Mbed-enabled. STLinkV2-1 presents the board ID
100+
- Uses the STLinkV2-1 or STLinkV3 firmware and the board is Mbed-enabled. STLink presents the board ID
77101
as the first 4 characters of the code in the HTML file on the USB mass storage volume.
78102

79103
If neither applies, then pyOCD will be unable to automatically detect the board type. However, you
80-
can still use the target.
104+
can still use the target by passing the `--target` argument to pyOCD.
81105

82106
Follow these steps:
83107

@@ -90,9 +114,9 @@ Follow these steps:
90114

91115
"0205": BoardInfo( "FRDM-KL28Z", "kl28z", "l1_kl28z.bin", ),
92116

93-
Be sure to insert the row in sorted order by board ID.
117+
Be sure to insert the row in sorted order by board ID, and please align columns.
94118

95-
3. Place a test firmware binary file listed in the board info into the top-level `binaries/`
96-
directory. The test firmware can be nothing more than an LED blinky demo. It must not require
119+
3. Place a test firmware binary file listed in the board info into the `test/data/binaries/`
120+
directory. The test firmware can be nothing more than a tiny LED blinky demo. It must not require
97121
any user input, and should provide immediate visual feedback that the code is successfully
98122
running, assuming there are LEDs on the board.

0 commit comments

Comments
 (0)