Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

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?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 /**
Pawel Zarembski 0:01f31e923fe2 2 * @file target_family.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief Implementation of target_family.h
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2009-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 #include "daplink.h"
Pawel Zarembski 0:01f31e923fe2 23 #include "DAP_config.h"
Pawel Zarembski 0:01f31e923fe2 24 #include "swd_host.h"
Pawel Zarembski 0:01f31e923fe2 25 #include "target_family.h"
Pawel Zarembski 0:01f31e923fe2 26 #include "target_board.h"
Pawel Zarembski 0:01f31e923fe2 27
Pawel Zarembski 0:01f31e923fe2 28 // Stub families
Pawel Zarembski 0:01f31e923fe2 29 const target_family_descriptor_t g_hw_reset_family = {
Pawel Zarembski 0:01f31e923fe2 30 .family_id = kStub_HWReset_FamilyID,
Pawel Zarembski 0:01f31e923fe2 31 .default_reset_type = kHardwareReset,
Pawel Zarembski 0:01f31e923fe2 32 };
Pawel Zarembski 0:01f31e923fe2 33
Pawel Zarembski 0:01f31e923fe2 34 const target_family_descriptor_t g_sw_vectreset_family = {
Pawel Zarembski 0:01f31e923fe2 35 .family_id = kStub_SWVectReset_FamilyID,
Pawel Zarembski 0:01f31e923fe2 36 .default_reset_type = kSoftwareReset,
Pawel Zarembski 0:01f31e923fe2 37 .soft_reset_type = VECTRESET,
Pawel Zarembski 0:01f31e923fe2 38 };
Pawel Zarembski 0:01f31e923fe2 39
Pawel Zarembski 0:01f31e923fe2 40 const target_family_descriptor_t g_sw_sysresetreq_family = {
Pawel Zarembski 0:01f31e923fe2 41 .family_id = kStub_SWSysReset_FamilyID,
Pawel Zarembski 0:01f31e923fe2 42 .default_reset_type = kSoftwareReset,
Pawel Zarembski 0:01f31e923fe2 43 .soft_reset_type = SYSRESETREQ,
Pawel Zarembski 0:01f31e923fe2 44 };
Pawel Zarembski 0:01f31e923fe2 45
Pawel Zarembski 0:01f31e923fe2 46 //Weakly define family
Pawel Zarembski 0:01f31e923fe2 47 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 48 const target_family_descriptor_t g_nxp_kinetis_kseries = {0};
Pawel Zarembski 0:01f31e923fe2 49 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 50 const target_family_descriptor_t g_nxp_kinetis_lseries = {0};
Pawel Zarembski 0:01f31e923fe2 51 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 52 const target_family_descriptor_t g_nxp_kinetis_k32w_series = {0};
Pawel Zarembski 0:01f31e923fe2 53 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 54 const target_family_descriptor_t g_nxp_mimxrt = {0};
Pawel Zarembski 0:01f31e923fe2 55 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 56 const target_family_descriptor_t g_nxp_rapid_iot = {0};
Pawel Zarembski 0:01f31e923fe2 57 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 58 const target_family_descriptor_t g_nordic_nrf51 = {0};
Pawel Zarembski 0:01f31e923fe2 59 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 60 const target_family_descriptor_t g_nordic_nrf52 = {0};
Pawel Zarembski 0:01f31e923fe2 61 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 62 const target_family_descriptor_t g_realtek_rtl8195am = {0};
Pawel Zarembski 0:01f31e923fe2 63 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 64 const target_family_descriptor_t g_ti_family = {0};
Pawel Zarembski 0:01f31e923fe2 65 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 66 const target_family_descriptor_t g_wiznet_family = {0};
Pawel Zarembski 0:01f31e923fe2 67 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 68 const target_family_descriptor_t g_renesas_family = {0};
Pawel Zarembski 0:01f31e923fe2 69 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 70 const target_family_descriptor_t g_toshiba_tz_family = {0};
Pawel Zarembski 0:01f31e923fe2 71
Pawel Zarembski 0:01f31e923fe2 72 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 73 const target_family_descriptor_t *g_families[] = {
Pawel Zarembski 0:01f31e923fe2 74 &g_hw_reset_family,
Pawel Zarembski 0:01f31e923fe2 75 &g_sw_vectreset_family,
Pawel Zarembski 0:01f31e923fe2 76 &g_sw_sysresetreq_family,
Pawel Zarembski 0:01f31e923fe2 77 &g_nxp_kinetis_kseries,
Pawel Zarembski 0:01f31e923fe2 78 &g_nxp_kinetis_lseries,
Pawel Zarembski 0:01f31e923fe2 79 &g_nxp_kinetis_k32w_series,
Pawel Zarembski 0:01f31e923fe2 80 &g_nxp_mimxrt,
Pawel Zarembski 0:01f31e923fe2 81 &g_nxp_rapid_iot,
Pawel Zarembski 0:01f31e923fe2 82 &g_nordic_nrf51,
Pawel Zarembski 0:01f31e923fe2 83 &g_nordic_nrf52,
Pawel Zarembski 0:01f31e923fe2 84 &g_realtek_rtl8195am,
Pawel Zarembski 0:01f31e923fe2 85 &g_ti_family,
Pawel Zarembski 0:01f31e923fe2 86 &g_wiznet_family,
Pawel Zarembski 0:01f31e923fe2 87 &g_renesas_family,
Pawel Zarembski 0:01f31e923fe2 88 &g_toshiba_tz_family,
Pawel Zarembski 0:01f31e923fe2 89 0 // list terminator
Pawel Zarembski 0:01f31e923fe2 90 };
Pawel Zarembski 0:01f31e923fe2 91
Pawel Zarembski 0:01f31e923fe2 92 __attribute__((weak))
Pawel Zarembski 0:01f31e923fe2 93 const target_family_descriptor_t *g_target_family = NULL;
Pawel Zarembski 0:01f31e923fe2 94
Pawel Zarembski 0:01f31e923fe2 95
Pawel Zarembski 0:01f31e923fe2 96 void init_family(void)
Pawel Zarembski 0:01f31e923fe2 97 {
Pawel Zarembski 0:01f31e923fe2 98 uint8_t index = 0;
Pawel Zarembski 0:01f31e923fe2 99 uint16_t family_id = get_family_id();
Pawel Zarembski 0:01f31e923fe2 100 if (g_target_family != NULL){ //already set
Pawel Zarembski 0:01f31e923fe2 101 return;
Pawel Zarembski 0:01f31e923fe2 102 }
Pawel Zarembski 0:01f31e923fe2 103
Pawel Zarembski 0:01f31e923fe2 104 while (g_families[index]!=0) {
Pawel Zarembski 0:01f31e923fe2 105 if (g_families[index]->family_id && (g_families[index]->family_id == family_id)) {
Pawel Zarembski 0:01f31e923fe2 106 g_target_family = g_families[index];
Pawel Zarembski 0:01f31e923fe2 107 break;
Pawel Zarembski 0:01f31e923fe2 108 }
Pawel Zarembski 0:01f31e923fe2 109 index++;
Pawel Zarembski 0:01f31e923fe2 110 }
Pawel Zarembski 0:01f31e923fe2 111
Pawel Zarembski 0:01f31e923fe2 112 if(g_target_family == NULL){ //default family
Pawel Zarembski 0:01f31e923fe2 113 g_target_family = &g_hw_reset_family;
Pawel Zarembski 0:01f31e923fe2 114 }
Pawel Zarembski 0:01f31e923fe2 115 }
Pawel Zarembski 0:01f31e923fe2 116
Pawel Zarembski 0:01f31e923fe2 117 uint8_t target_set_state(target_state_t state)
Pawel Zarembski 0:01f31e923fe2 118 {
Pawel Zarembski 0:01f31e923fe2 119 if (g_board_info.target_set_state) { //target specific
Pawel Zarembski 0:01f31e923fe2 120 g_board_info.target_set_state(state);
Pawel Zarembski 0:01f31e923fe2 121 }
Pawel Zarembski 0:01f31e923fe2 122 if (g_target_family) {
Pawel Zarembski 0:01f31e923fe2 123 if (g_target_family->target_set_state) {
Pawel Zarembski 0:01f31e923fe2 124 //customize target state
Pawel Zarembski 0:01f31e923fe2 125 return g_target_family->target_set_state(state);
Pawel Zarembski 0:01f31e923fe2 126 } else {
Pawel Zarembski 0:01f31e923fe2 127 if (g_target_family->default_reset_type == kHardwareReset) {
Pawel Zarembski 0:01f31e923fe2 128 return swd_set_target_state_hw(state);
Pawel Zarembski 0:01f31e923fe2 129 } else if (g_target_family->default_reset_type == kSoftwareReset) {
Pawel Zarembski 0:01f31e923fe2 130 if (g_board_info.soft_reset_type) { //board has precedence
Pawel Zarembski 0:01f31e923fe2 131 swd_set_soft_reset(g_board_info.soft_reset_type);
Pawel Zarembski 0:01f31e923fe2 132 } else if (g_target_family->soft_reset_type) {
Pawel Zarembski 0:01f31e923fe2 133 swd_set_soft_reset(g_target_family->soft_reset_type);
Pawel Zarembski 0:01f31e923fe2 134 }
Pawel Zarembski 0:01f31e923fe2 135 return swd_set_target_state_sw(state);
Pawel Zarembski 0:01f31e923fe2 136 }else {
Pawel Zarembski 0:01f31e923fe2 137 return 1;
Pawel Zarembski 0:01f31e923fe2 138 }
Pawel Zarembski 0:01f31e923fe2 139 }
Pawel Zarembski 0:01f31e923fe2 140 }else{
Pawel Zarembski 0:01f31e923fe2 141 return 0;
Pawel Zarembski 0:01f31e923fe2 142 }
Pawel Zarembski 0:01f31e923fe2 143 }
Pawel Zarembski 0:01f31e923fe2 144
Pawel Zarembski 0:01f31e923fe2 145 void swd_set_target_reset(uint8_t asserted)
Pawel Zarembski 0:01f31e923fe2 146 {
Pawel Zarembski 0:01f31e923fe2 147 if (g_target_family && g_target_family->swd_set_target_reset) {
Pawel Zarembski 0:01f31e923fe2 148 g_target_family->swd_set_target_reset(asserted);
Pawel Zarembski 0:01f31e923fe2 149 }else {
Pawel Zarembski 0:01f31e923fe2 150 (asserted) ? PIN_nRESET_OUT(0) : PIN_nRESET_OUT(1);
Pawel Zarembski 0:01f31e923fe2 151 }
Pawel Zarembski 0:01f31e923fe2 152 }
Pawel Zarembski 0:01f31e923fe2 153
Pawel Zarembski 0:01f31e923fe2 154 uint32_t target_get_apsel()
Pawel Zarembski 0:01f31e923fe2 155 {
Pawel Zarembski 0:01f31e923fe2 156 if (g_target_family && g_target_family->apsel) {
Pawel Zarembski 0:01f31e923fe2 157 return g_target_family->apsel;
Pawel Zarembski 0:01f31e923fe2 158 } else {
Pawel Zarembski 0:01f31e923fe2 159 return 0;
Pawel Zarembski 0:01f31e923fe2 160 }
Pawel Zarembski 0:01f31e923fe2 161 }