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_reset.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief Target reset for Musca A target
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 "target_family.h"
Pawel Zarembski 0:01f31e923fe2 23 #include "target_config.h" // for target_device
Pawel Zarembski 0:01f31e923fe2 24 #include "swd_host.h"
Pawel Zarembski 0:01f31e923fe2 25 #include "gpio.h"
Pawel Zarembski 0:01f31e923fe2 26 #include "debug_cm.h"
Pawel Zarembski 0:01f31e923fe2 27 #include "utils.h"
Pawel Zarembski 0:01f31e923fe2 28 #include "power_ctrl.h"
Pawel Zarembski 0:01f31e923fe2 29 #include "uart.h"
Pawel Zarembski 0:01f31e923fe2 30
Pawel Zarembski 0:01f31e923fe2 31 static void musca_a_target_before_init_debug(void)
Pawel Zarembski 0:01f31e923fe2 32 {
Pawel Zarembski 0:01f31e923fe2 33 uint8_t buf[12];
Pawel Zarembski 0:01f31e923fe2 34
Pawel Zarembski 0:01f31e923fe2 35 // go into controlled shutdown
Pawel Zarembski 0:01f31e923fe2 36 power_off_sequence();
Pawel Zarembski 0:01f31e923fe2 37
Pawel Zarembski 0:01f31e923fe2 38 // Drive SCC signals
Pawel Zarembski 0:01f31e923fe2 39 LPC_GPIO->DIR[PIN_SCC_CLK_PORT] |= PIN_SCC_CLK;
Pawel Zarembski 0:01f31e923fe2 40 LPC_GPIO->DIR[PIN_SCC_DATAIN_PORT] |= PIN_SCC_DATAIN;
Pawel Zarembski 0:01f31e923fe2 41 LPC_GPIO->DIR[PIN_SCC_DATAOUT_PORT] &= ~PIN_SCC_DATAOUT;
Pawel Zarembski 0:01f31e923fe2 42 LPC_GPIO->DIR[PIN_SCC_WNR_PORT] |= PIN_SCC_WNR;
Pawel Zarembski 0:01f31e923fe2 43 LPC_GPIO->DIR[PIN_SCC_LOAD_PORT] |= PIN_SCC_LOAD;
Pawel Zarembski 0:01f31e923fe2 44
Pawel Zarembski 0:01f31e923fe2 45 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 46 delay(10);
Pawel Zarembski 0:01f31e923fe2 47
Pawel Zarembski 0:01f31e923fe2 48 // Release CFG_nRST to allow SCC config
Pawel Zarembski 0:01f31e923fe2 49 LPC_GPIO->SET[PIN_CFG_nRST_PORT] = PIN_CFG_nRST;
Pawel Zarembski 0:01f31e923fe2 50
Pawel Zarembski 0:01f31e923fe2 51 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 52 delay(10);
Pawel Zarembski 0:01f31e923fe2 53
Pawel Zarembski 0:01f31e923fe2 54 // Configure SCC
Pawel Zarembski 0:01f31e923fe2 55 configure_syscon(0x10000000);
Pawel Zarembski 0:01f31e923fe2 56
Pawel Zarembski 0:01f31e923fe2 57 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 58 delay(10);
Pawel Zarembski 0:01f31e923fe2 59
Pawel Zarembski 0:01f31e923fe2 60 // Creating branch to self in SRAM
Pawel Zarembski 0:01f31e923fe2 61 buf[0] = 0x00;
Pawel Zarembski 0:01f31e923fe2 62 buf[1] = 0x00;
Pawel Zarembski 0:01f31e923fe2 63 buf[2] = 0x08;
Pawel Zarembski 0:01f31e923fe2 64 buf[3] = 0x30;
Pawel Zarembski 0:01f31e923fe2 65 buf[4] = 0x09;
Pawel Zarembski 0:01f31e923fe2 66 buf[5] = 0x00;
Pawel Zarembski 0:01f31e923fe2 67 buf[6] = 0x00;
Pawel Zarembski 0:01f31e923fe2 68 buf[7] = 0x10;
Pawel Zarembski 0:01f31e923fe2 69 buf[8] = 0xFE;
Pawel Zarembski 0:01f31e923fe2 70 buf[9] = 0xE7;
Pawel Zarembski 0:01f31e923fe2 71 buf[10] = 0xFE;
Pawel Zarembski 0:01f31e923fe2 72 buf[11] = 0xE7;
Pawel Zarembski 0:01f31e923fe2 73
Pawel Zarembski 0:01f31e923fe2 74 swd_write_memory(0x10000000, (uint8_t *)buf, 12);
Pawel Zarembski 0:01f31e923fe2 75
Pawel Zarembski 0:01f31e923fe2 76 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 77 delay(10);
Pawel Zarembski 0:01f31e923fe2 78
Pawel Zarembski 0:01f31e923fe2 79 // Release SCC signals
Pawel Zarembski 0:01f31e923fe2 80 LPC_GPIO->DIR[PIN_SCC_CLK_PORT] &= ~PIN_SCC_CLK;
Pawel Zarembski 0:01f31e923fe2 81 LPC_GPIO->DIR[PIN_SCC_DATAIN_PORT] &= ~PIN_SCC_DATAIN;
Pawel Zarembski 0:01f31e923fe2 82 LPC_GPIO->DIR[PIN_SCC_DATAOUT_PORT] &= ~PIN_SCC_DATAOUT;
Pawel Zarembski 0:01f31e923fe2 83 LPC_GPIO->DIR[PIN_SCC_WNR_PORT] &= ~PIN_SCC_WNR;
Pawel Zarembski 0:01f31e923fe2 84 LPC_GPIO->DIR[PIN_SCC_LOAD_PORT] &= ~PIN_SCC_LOAD;
Pawel Zarembski 0:01f31e923fe2 85
Pawel Zarembski 0:01f31e923fe2 86 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 87 delay(10);
Pawel Zarembski 0:01f31e923fe2 88
Pawel Zarembski 0:01f31e923fe2 89 // Release CB_nRST (nPORESET)
Pawel Zarembski 0:01f31e923fe2 90 LPC_GPIO->SET[PIN_CB_nRST_PORT] = PIN_CB_nRST;
Pawel Zarembski 0:01f31e923fe2 91
Pawel Zarembski 0:01f31e923fe2 92 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 93 delay(10);
Pawel Zarembski 0:01f31e923fe2 94
Pawel Zarembski 0:01f31e923fe2 95 // Release CS_nSRST
Pawel Zarembski 0:01f31e923fe2 96 LPC_GPIO->SET[PIN_nRESET_PORT] = PIN_nRESET;
Pawel Zarembski 0:01f31e923fe2 97
Pawel Zarembski 0:01f31e923fe2 98 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 99 delay(10);
Pawel Zarembski 0:01f31e923fe2 100
Pawel Zarembski 0:01f31e923fe2 101 return;
Pawel Zarembski 0:01f31e923fe2 102 }
Pawel Zarembski 0:01f31e923fe2 103
Pawel Zarembski 0:01f31e923fe2 104 static uint8_t musca_a_target_set_state(target_state_t state)
Pawel Zarembski 0:01f31e923fe2 105 {
Pawel Zarembski 0:01f31e923fe2 106 if(state == RESET_RUN)
Pawel Zarembski 0:01f31e923fe2 107 {
Pawel Zarembski 0:01f31e923fe2 108 // go through controlled reset
Pawel Zarembski 0:01f31e923fe2 109 power_off_sequence();
Pawel Zarembski 0:01f31e923fe2 110
Pawel Zarembski 0:01f31e923fe2 111 power_on_sequence();
Pawel Zarembski 0:01f31e923fe2 112
Pawel Zarembski 0:01f31e923fe2 113 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 114 delay(10);
Pawel Zarembski 0:01f31e923fe2 115
Pawel Zarembski 0:01f31e923fe2 116 swd_off();
Pawel Zarembski 0:01f31e923fe2 117
Pawel Zarembski 0:01f31e923fe2 118 return 1;
Pawel Zarembski 0:01f31e923fe2 119 }
Pawel Zarembski 0:01f31e923fe2 120 if(state == SHUTDOWN)
Pawel Zarembski 0:01f31e923fe2 121 {
Pawel Zarembski 0:01f31e923fe2 122 // go through controlled shutdown
Pawel Zarembski 0:01f31e923fe2 123 power_off_sequence();
Pawel Zarembski 0:01f31e923fe2 124
Pawel Zarembski 0:01f31e923fe2 125 // Remove PSUON
Pawel Zarembski 0:01f31e923fe2 126 LPC_GPIO->CLR[PIN_PSUON_PORT] = PIN_PSUON;
Pawel Zarembski 0:01f31e923fe2 127
Pawel Zarembski 0:01f31e923fe2 128 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 129 delay(10);
Pawel Zarembski 0:01f31e923fe2 130
Pawel Zarembski 0:01f31e923fe2 131 uart_reset();
Pawel Zarembski 0:01f31e923fe2 132
Pawel Zarembski 0:01f31e923fe2 133 return 1;
Pawel Zarembski 0:01f31e923fe2 134 }
Pawel Zarembski 0:01f31e923fe2 135 if(state == POWER_ON)
Pawel Zarembski 0:01f31e923fe2 136 {
Pawel Zarembski 0:01f31e923fe2 137 // Switch on power supply - PSUON
Pawel Zarembski 0:01f31e923fe2 138 LPC_GPIO->SET[PIN_PSUON_PORT] = PIN_PSUON;
Pawel Zarembski 0:01f31e923fe2 139
Pawel Zarembski 0:01f31e923fe2 140 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 141 delay(10);
Pawel Zarembski 0:01f31e923fe2 142
Pawel Zarembski 0:01f31e923fe2 143 // power on the target
Pawel Zarembski 0:01f31e923fe2 144 power_on_sequence();
Pawel Zarembski 0:01f31e923fe2 145
Pawel Zarembski 0:01f31e923fe2 146 // Wait 10ms
Pawel Zarembski 0:01f31e923fe2 147 delay(10);
Pawel Zarembski 0:01f31e923fe2 148
Pawel Zarembski 0:01f31e923fe2 149 swd_off();
Pawel Zarembski 0:01f31e923fe2 150 return 1;
Pawel Zarembski 0:01f31e923fe2 151 }
Pawel Zarembski 0:01f31e923fe2 152
Pawel Zarembski 0:01f31e923fe2 153 return swd_set_target_state_sw(state);
Pawel Zarembski 0:01f31e923fe2 154 }
Pawel Zarembski 0:01f31e923fe2 155
Pawel Zarembski 0:01f31e923fe2 156 const target_family_descriptor_t g_target_family_musca_a = {
Pawel Zarembski 0:01f31e923fe2 157 .target_before_init_debug = musca_a_target_before_init_debug,
Pawel Zarembski 0:01f31e923fe2 158 .target_set_state = musca_a_target_set_state,
Pawel Zarembski 0:01f31e923fe2 159 .apsel = 0x01000000,
Pawel Zarembski 0:01f31e923fe2 160 };
Pawel Zarembski 0:01f31e923fe2 161
Pawel Zarembski 0:01f31e923fe2 162 const target_family_descriptor_t *g_target_family = &g_target_family_musca_a;