| 1 | --- |
| 2 | title: Architecture |
| 3 | --- |
| 4 | |
| 5 | ## Object graph |
| 6 | |
| 7 | The diagram below shows the most interesting parts of the pyOCD object graph, i.e. those parts |
| 8 | that a user of the Python API will interact with. The connections in the diagram represent |
| 9 | composition, not inheritance. |
| 10 | |
| 11 |  |
| 12 | |
| 13 | |
| 14 | The root of the runtime object graph is a `Session` object. This object holds references to the debug |
| 15 | probe and the board. It is also responsible for managing per-session options that control |
| 16 | various features and settings. |
| 17 | |
| 18 | Attached to the board is a `CoreSightTarget` instance, which represents an MCU. This owns the |
| 19 | CoreSight related objects for communicating with the DP and APs and a `CortexM` object for each CPU |
| 20 | core on the device. Both `CoreSightTarget` and `CortexM` are subclasses of the abstract `Target` |
| 21 | class, which is referenced below, and share most of the same APIs. `CortexM` has a memory map |
| 22 | comprised of `MemoryRegion` objects. The flash memory regions have a `Flash` object to control flash |
| 23 | programming. |
| 24 | |
| 25 | ## Targets and boards |
| 26 | |
| 27 | Target and board support are two separate but related pieces of functionality. |
| 28 | |
| 29 | #### Target support |
| 30 | |
| 31 | Each supported target enables debugging and flash programming a given MCU. A single target can be |
| 32 | used for potentially multiple boards, or there may not be board with the target. Users can |
| 33 | override the target type on the command line or when creating the `Session`. |
| 34 | |
| 35 | Each supported target is defined as a `CoreSightTarget` subclass. Builtin targets are held in a |
| 36 | Python file in the `pyocd/target/builtin` directory. If the target has internal or connected flash, |
| 37 | then a flash algo dict and possibly a `Flash` subclass will be paired with it in the same source |
| 38 | file. The `Flash` subclass is only required if special flash programming semantics are needed, |
| 39 | otherwise the base `Flash` class is automatically used. The flash algo dict and/or `Flash` subclass |
| 40 | are set on flash memory regions when they are created in the memory map. Some device families have |
| 41 | family subclasses under `pyocd/target/family`. |
| 42 |