Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/target/target_family.h@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * @file target_family.h |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2018-2019, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 20 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #ifndef TARGET_FAMILY_H |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #define TARGET_FAMILY_H |
Pawel Zarembski |
0:01f31e923fe2 | 24 | |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include <stdint.h> |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #include <string.h> |
Pawel Zarembski |
0:01f31e923fe2 | 27 | |
Pawel Zarembski |
0:01f31e923fe2 | 28 | //! @brief Creates a family ID from a vendor ID and family index within that vendor. |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #define VENDOR_TO_FAMILY(vendor, family) ((vendor) << 8 | (family)) |
Pawel Zarembski |
0:01f31e923fe2 | 30 | |
Pawel Zarembski |
0:01f31e923fe2 | 31 | //! @brief States into which the target can be placed. |
Pawel Zarembski |
0:01f31e923fe2 | 32 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 33 | //! These enums are passed to target_set_state() and indicate the desired state into which |
Pawel Zarembski |
0:01f31e923fe2 | 34 | //! the target should be reset. |
Pawel Zarembski |
0:01f31e923fe2 | 35 | typedef enum _target_state { |
Pawel Zarembski |
0:01f31e923fe2 | 36 | RESET_HOLD, //!< Hold target in reset |
Pawel Zarembski |
0:01f31e923fe2 | 37 | RESET_PROGRAM, //!< Reset target and setup for flash programming |
Pawel Zarembski |
0:01f31e923fe2 | 38 | RESET_RUN, //!< Reset target and run normally |
Pawel Zarembski |
0:01f31e923fe2 | 39 | NO_DEBUG, //!< Disable debug on running target |
Pawel Zarembski |
0:01f31e923fe2 | 40 | DEBUG, //!< Enable debug on running target |
Pawel Zarembski |
0:01f31e923fe2 | 41 | HALT, //!< Halt the target without resetting it |
Pawel Zarembski |
0:01f31e923fe2 | 42 | RUN, //!< Resume the target without resetting it |
Pawel Zarembski |
0:01f31e923fe2 | 43 | POST_FLASH_RESET, //!< Reset target after flash programming |
Pawel Zarembski |
0:01f31e923fe2 | 44 | POWER_ON, //!< Poweron the target |
Pawel Zarembski |
0:01f31e923fe2 | 45 | SHUTDOWN, //!< Poweroff the target |
Pawel Zarembski |
0:01f31e923fe2 | 46 | } target_state_t; |
Pawel Zarembski |
0:01f31e923fe2 | 47 | |
Pawel Zarembski |
0:01f31e923fe2 | 48 | //! @brief Options for reset. |
Pawel Zarembski |
0:01f31e923fe2 | 49 | typedef enum _reset_type { |
Pawel Zarembski |
0:01f31e923fe2 | 50 | kHardwareReset = 1, |
Pawel Zarembski |
0:01f31e923fe2 | 51 | kSoftwareReset, |
Pawel Zarembski |
0:01f31e923fe2 | 52 | } reset_type_t; |
Pawel Zarembski |
0:01f31e923fe2 | 53 | |
Pawel Zarembski |
0:01f31e923fe2 | 54 | //! @brief Unique IDs for vendors. |
Pawel Zarembski |
0:01f31e923fe2 | 55 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 56 | //! The vendor IDs are the same as those used for the _DeviceVendorEnum_ defined for the PDSC file |
Pawel Zarembski |
0:01f31e923fe2 | 57 | //! format from CMSIS-Packs. See the [DeviceVendorEnum |
Pawel Zarembski |
0:01f31e923fe2 | 58 | //! documentation](https://arm-software.github.io/CMSIS_5/Pack/html/pdsc_family_pg.html#DeviceVendorEnum) |
Pawel Zarembski |
0:01f31e923fe2 | 59 | //! for the list of ID values. |
Pawel Zarembski |
0:01f31e923fe2 | 60 | enum _vendor_ids { |
Pawel Zarembski |
0:01f31e923fe2 | 61 | kStub_VendorID = 0, |
Pawel Zarembski |
0:01f31e923fe2 | 62 | kNXP_VendorID = 11, |
Pawel Zarembski |
0:01f31e923fe2 | 63 | kTI_VendorID = 16, |
Pawel Zarembski |
0:01f31e923fe2 | 64 | kNordic_VendorID = 54, |
Pawel Zarembski |
0:01f31e923fe2 | 65 | kToshiba_VendorID = 92, |
Pawel Zarembski |
0:01f31e923fe2 | 66 | kRenesas_VendorID = 117, |
Pawel Zarembski |
0:01f31e923fe2 | 67 | kWiznet_VendorID = 122, |
Pawel Zarembski |
0:01f31e923fe2 | 68 | kRealtek_VendorID = 124, |
Pawel Zarembski |
0:01f31e923fe2 | 69 | }; |
Pawel Zarembski |
0:01f31e923fe2 | 70 | |
Pawel Zarembski |
0:01f31e923fe2 | 71 | //! @brief Unique IDs for device families supported by DAPLink. |
Pawel Zarembski |
0:01f31e923fe2 | 72 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 73 | //! The values of these enums are created with the VENDOR_TO_FAMILY() macro. Vendor IDs come from |
Pawel Zarembski |
0:01f31e923fe2 | 74 | //! the #_vendor_ids enumeration. The family index for each ID is simply an integer that is unique |
Pawel Zarembski |
0:01f31e923fe2 | 75 | //! within the family. |
Pawel Zarembski |
0:01f31e923fe2 | 76 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 77 | //! There are several "stub" families defined with a stub vendor. These families are meant to be |
Pawel Zarembski |
0:01f31e923fe2 | 78 | //! used for devices that do not require any customized behaviour in order to be successfully |
Pawel Zarembski |
0:01f31e923fe2 | 79 | //! controlled by DAPLink. The individual stub families provide some options for what reset type |
Pawel Zarembski |
0:01f31e923fe2 | 80 | //! should be used, either hardware or software. |
Pawel Zarembski |
0:01f31e923fe2 | 81 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 82 | //! To add a new family, first determine if you can simply use one of the stub families. For many |
Pawel Zarembski |
0:01f31e923fe2 | 83 | //! devices, the stub families are sufficient and using them reduces complexity. |
Pawel Zarembski |
0:01f31e923fe2 | 84 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 85 | //! If you do need a new family ID, first check if the vendor is present in #_vendor_ids. If not, |
Pawel Zarembski |
0:01f31e923fe2 | 86 | //! add the vendor ID to that enum (see its documentation for the source of vendor ID values). |
Pawel Zarembski |
0:01f31e923fe2 | 87 | //! Then pick a unique family index by adding 1 to the highest existing family index within that |
Pawel Zarembski |
0:01f31e923fe2 | 88 | //! vendor. For a family with a new vendor, the family index should be 1. |
Pawel Zarembski |
0:01f31e923fe2 | 89 | typedef enum _family_id { |
Pawel Zarembski |
0:01f31e923fe2 | 90 | kStub_HWReset_FamilyID = VENDOR_TO_FAMILY(kStub_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 91 | kStub_SWVectReset_FamilyID = VENDOR_TO_FAMILY(kStub_VendorID, 2), |
Pawel Zarembski |
0:01f31e923fe2 | 92 | kStub_SWSysReset_FamilyID = VENDOR_TO_FAMILY(kStub_VendorID, 3), |
Pawel Zarembski |
0:01f31e923fe2 | 93 | kNXP_KinetisK_FamilyID = VENDOR_TO_FAMILY(kNXP_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 94 | kNXP_KinetisL_FamilyID = VENDOR_TO_FAMILY(kNXP_VendorID, 2), |
Pawel Zarembski |
0:01f31e923fe2 | 95 | kNXP_Mimxrt_FamilyID = VENDOR_TO_FAMILY(kNXP_VendorID, 3), |
Pawel Zarembski |
0:01f31e923fe2 | 96 | kNXP_RapidIot_FamilyID = VENDOR_TO_FAMILY(kNXP_VendorID, 4), |
Pawel Zarembski |
0:01f31e923fe2 | 97 | kNXP_KinetisK32W_FamilyID = VENDOR_TO_FAMILY(kNXP_VendorID, 5), |
Pawel Zarembski |
0:01f31e923fe2 | 98 | kNordic_Nrf51_FamilyID = VENDOR_TO_FAMILY(kNordic_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 99 | kNordic_Nrf52_FamilyID = VENDOR_TO_FAMILY(kNordic_VendorID, 2), |
Pawel Zarembski |
0:01f31e923fe2 | 100 | kRealtek_Rtl8195am_FamilyID = VENDOR_TO_FAMILY(kRealtek_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 101 | kTI_Cc3220sf_FamilyID = VENDOR_TO_FAMILY(kTI_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 102 | kToshiba_Tz_FamilyID = VENDOR_TO_FAMILY(kToshiba_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 103 | kWiznet_W7500_FamilyID = VENDOR_TO_FAMILY(kWiznet_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 104 | kRenesas_FamilyID = VENDOR_TO_FAMILY(kRenesas_VendorID, 1), |
Pawel Zarembski |
0:01f31e923fe2 | 105 | } family_id_t; |
Pawel Zarembski |
0:01f31e923fe2 | 106 | |
Pawel Zarembski |
0:01f31e923fe2 | 107 | //! @brief Defines all characteristics of a device family. |
Pawel Zarembski |
0:01f31e923fe2 | 108 | typedef struct target_family_descriptor { |
Pawel Zarembski |
0:01f31e923fe2 | 109 | uint16_t family_id; /*!< Use to select or identify target family from defined target family or custom ones */ |
Pawel Zarembski |
0:01f31e923fe2 | 110 | reset_type_t default_reset_type; /*!< Target family can select predefined reset from kHardwareReset and kSoftwareReset */ |
Pawel Zarembski |
0:01f31e923fe2 | 111 | uint32_t soft_reset_type; /*!< Families can override software reset type to VECTRESET or SYSRESETREQ */ |
Pawel Zarembski |
0:01f31e923fe2 | 112 | void (*target_before_init_debug)(void); /*!< Target dependant function before debug initialization */ |
Pawel Zarembski |
0:01f31e923fe2 | 113 | void (*prerun_target_config)(void); /*!< Target specific initialization */ |
Pawel Zarembski |
0:01f31e923fe2 | 114 | uint8_t (*target_unlock_sequence)(void); /*!< Unlock targets that can enter lock state */ |
Pawel Zarembski |
0:01f31e923fe2 | 115 | uint8_t (*security_bits_set)(uint32_t addr, uint8_t *data, uint32_t size); /*!< Check security bits in the programmable flash region */ |
Pawel Zarembski |
0:01f31e923fe2 | 116 | uint8_t (*target_set_state)(target_state_t state); /*!< Families can customize target debug states */ |
Pawel Zarembski |
0:01f31e923fe2 | 117 | void (*swd_set_target_reset)(uint8_t asserted); /*!< Families can customize how to send reset to the target */ |
Pawel Zarembski |
0:01f31e923fe2 | 118 | uint8_t (*validate_bin_nvic)(const uint8_t *buf); /*!< Validate a bin file to be flash by drag and drop */ |
Pawel Zarembski |
0:01f31e923fe2 | 119 | uint8_t (*validate_hexfile)(const uint8_t *buf); /*!< Validate a hex file to be flash by drag and drop */ |
Pawel Zarembski |
0:01f31e923fe2 | 120 | uint32_t apsel; /*!< APSEL for the family */ |
Pawel Zarembski |
0:01f31e923fe2 | 121 | } target_family_descriptor_t; |
Pawel Zarembski |
0:01f31e923fe2 | 122 | |
Pawel Zarembski |
0:01f31e923fe2 | 123 | //! @brief The active family used by the board. |
Pawel Zarembski |
0:01f31e923fe2 | 124 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 125 | //! This global is initialized by init_family() just after DAPLink boots. Normally it matches |
Pawel Zarembski |
0:01f31e923fe2 | 126 | //! the family specified by the #board_info_t::family_id field of #g_board_info. |
Pawel Zarembski |
0:01f31e923fe2 | 127 | extern const target_family_descriptor_t *g_target_family; |
Pawel Zarembski |
0:01f31e923fe2 | 128 | |
Pawel Zarembski |
0:01f31e923fe2 | 129 | #ifdef __cplusplus |
Pawel Zarembski |
0:01f31e923fe2 | 130 | extern "C" { |
Pawel Zarembski |
0:01f31e923fe2 | 131 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 132 | |
Pawel Zarembski |
0:01f31e923fe2 | 133 | //! @brief Initialize g_target_family. |
Pawel Zarembski |
0:01f31e923fe2 | 134 | void init_family(void); |
Pawel Zarembski |
0:01f31e923fe2 | 135 | |
Pawel Zarembski |
0:01f31e923fe2 | 136 | //! @brief Reset the target into a new state. |
Pawel Zarembski |
0:01f31e923fe2 | 137 | //! |
Pawel Zarembski |
0:01f31e923fe2 | 138 | //! Used to prepare the target for some operation, or release it for user control. |
Pawel Zarembski |
0:01f31e923fe2 | 139 | uint8_t target_set_state(target_state_t state); |
Pawel Zarembski |
0:01f31e923fe2 | 140 | |
Pawel Zarembski |
0:01f31e923fe2 | 141 | //! @brief Controls reset of the target. |
Pawel Zarembski |
0:01f31e923fe2 | 142 | void swd_set_target_reset(uint8_t asserted); |
Pawel Zarembski |
0:01f31e923fe2 | 143 | |
Pawel Zarembski |
0:01f31e923fe2 | 144 | //! @brief Get the APSEL for the AHB-AP to use for controlling the target. |
Pawel Zarembski |
0:01f31e923fe2 | 145 | uint32_t target_get_apsel(void); |
Pawel Zarembski |
0:01f31e923fe2 | 146 | |
Pawel Zarembski |
0:01f31e923fe2 | 147 | #ifdef __cplusplus |
Pawel Zarembski |
0:01f31e923fe2 | 148 | } |
Pawel Zarembski |
0:01f31e923fe2 | 149 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 150 | |
Pawel Zarembski |
0:01f31e923fe2 | 151 | #endif |