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 the lpc4088
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 "swd_host.h"
Pawel Zarembski 0:01f31e923fe2 23 #include "gpio.h"
Pawel Zarembski 0:01f31e923fe2 24 #include "target_family.h"
Pawel Zarembski 0:01f31e923fe2 25
Pawel Zarembski 0:01f31e923fe2 26 #define PIN_ISPCTRL1 (1<<12)
Pawel Zarembski 0:01f31e923fe2 27 #define PIN_ISPCTRL2 (1<<15)
Pawel Zarembski 0:01f31e923fe2 28
Pawel Zarembski 0:01f31e923fe2 29 static void gpio_set_isp_pin(uint8_t state) {
Pawel Zarembski 0:01f31e923fe2 30 if (state) {
Pawel Zarembski 0:01f31e923fe2 31 // High => Both pins are inputs
Pawel Zarembski 0:01f31e923fe2 32 LPC_GPIO->DIR[0] &= ~(PIN_ISPCTRL1);
Pawel Zarembski 0:01f31e923fe2 33 LPC_GPIO->DIR[1] &= ~(PIN_ISPCTRL2);
Pawel Zarembski 0:01f31e923fe2 34 } else {
Pawel Zarembski 0:01f31e923fe2 35 // Low => Both pins are outputs with 0
Pawel Zarembski 0:01f31e923fe2 36 LPC_GPIO->CLR[0] = (PIN_ISPCTRL1);
Pawel Zarembski 0:01f31e923fe2 37 LPC_GPIO->CLR[1] = (PIN_ISPCTRL2);
Pawel Zarembski 0:01f31e923fe2 38 LPC_GPIO->DIR[0] |= (PIN_ISPCTRL1);
Pawel Zarembski 0:01f31e923fe2 39 LPC_GPIO->DIR[1] |= (PIN_ISPCTRL2);
Pawel Zarembski 0:01f31e923fe2 40 }
Pawel Zarembski 0:01f31e923fe2 41 }
Pawel Zarembski 0:01f31e923fe2 42
Pawel Zarembski 0:01f31e923fe2 43 static void prerun_target_config(void)
Pawel Zarembski 0:01f31e923fe2 44 {
Pawel Zarembski 0:01f31e923fe2 45 // Configure ISPCTRL as output and high
Pawel Zarembski 0:01f31e923fe2 46 // We use two ISP pins to cover different hardware versions
Pawel Zarembski 0:01f31e923fe2 47 LPC_IOCON->TMS_PIO0_12 |= 0x01;
Pawel Zarembski 0:01f31e923fe2 48 LPC_IOCON->PIO1_15 &= ~0x07;
Pawel Zarembski 0:01f31e923fe2 49 gpio_set_isp_pin(1);
Pawel Zarembski 0:01f31e923fe2 50 }
Pawel Zarembski 0:01f31e923fe2 51
Pawel Zarembski 0:01f31e923fe2 52
Pawel Zarembski 0:01f31e923fe2 53 static uint8_t lpc4088_target_set_state(target_state_t state)
Pawel Zarembski 0:01f31e923fe2 54 {
Pawel Zarembski 0:01f31e923fe2 55 //return swd_set_target_state_hw(state);
Pawel Zarembski 0:01f31e923fe2 56 uint8_t res;
Pawel Zarembski 0:01f31e923fe2 57 if (state == RESET_PROGRAM)
Pawel Zarembski 0:01f31e923fe2 58 {
Pawel Zarembski 0:01f31e923fe2 59 gpio_set_isp_pin(0);
Pawel Zarembski 0:01f31e923fe2 60 res = swd_set_target_state_hw(state);
Pawel Zarembski 0:01f31e923fe2 61 gpio_set_isp_pin(1);
Pawel Zarembski 0:01f31e923fe2 62 }
Pawel Zarembski 0:01f31e923fe2 63 else
Pawel Zarembski 0:01f31e923fe2 64 {
Pawel Zarembski 0:01f31e923fe2 65 gpio_set_isp_pin(1);
Pawel Zarembski 0:01f31e923fe2 66 res = swd_set_target_state_hw(state);
Pawel Zarembski 0:01f31e923fe2 67 }
Pawel Zarembski 0:01f31e923fe2 68 return res;
Pawel Zarembski 0:01f31e923fe2 69 }
Pawel Zarembski 0:01f31e923fe2 70
Pawel Zarembski 0:01f31e923fe2 71 const target_family_descriptor_t g_nxp_lpc4088 = {
Pawel Zarembski 0:01f31e923fe2 72 .family_id = VENDOR_TO_FAMILY(kNXP_VendorID, 0), //ID not maching the predefined family ids
Pawel Zarembski 0:01f31e923fe2 73 .prerun_target_config = prerun_target_config,
Pawel Zarembski 0:01f31e923fe2 74 .target_set_state = lpc4088_target_set_state,
Pawel Zarembski 0:01f31e923fe2 75 };
Pawel Zarembski 0:01f31e923fe2 76
Pawel Zarembski 0:01f31e923fe2 77 const target_family_descriptor_t *g_target_family = &g_nxp_lpc4088;
Pawel Zarembski 0:01f31e923fe2 78