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 gpio.c
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) 2009-2016, 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 "sam3u.h"
Pawel Zarembski 0:01f31e923fe2 23 #include "gpio.h"
Pawel Zarembski 0:01f31e923fe2 24 #include "uart.h"
Pawel Zarembski 0:01f31e923fe2 25 #include "compiler.h"
Pawel Zarembski 0:01f31e923fe2 26 #include "daplink.h"
Pawel Zarembski 0:01f31e923fe2 27
Pawel Zarembski 0:01f31e923fe2 28 // This GPIO configuration is only valid for the SAM3U2C
Pawel Zarembski 0:01f31e923fe2 29 COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_SAM3U2C);
Pawel Zarembski 0:01f31e923fe2 30
Pawel Zarembski 0:01f31e923fe2 31 void gpio_init(void)
Pawel Zarembski 0:01f31e923fe2 32 {
Pawel Zarembski 0:01f31e923fe2 33 volatile int Cnt;
Pawel Zarembski 0:01f31e923fe2 34 //
Pawel Zarembski 0:01f31e923fe2 35 // Initially enable clock for GPIO and initialize LED ports as output with LED == off
Pawel Zarembski 0:01f31e923fe2 36 //
Pawel Zarembski 0:01f31e923fe2 37 PMC->PMC_PCER0 = (1 << 10) | (1 << 11) | (1 << 12); // Enable clock for all PIOs
Pawel Zarembski 0:01f31e923fe2 38
Pawel Zarembski 0:01f31e923fe2 39 // DAP LED
Pawel Zarembski 0:01f31e923fe2 40 PIN_DAP_LED_PORT->PIO_PER = PIN_DAP_LED;
Pawel Zarembski 0:01f31e923fe2 41 PIN_DAP_LED_PORT->PIO_SODR = PIN_DAP_LED;
Pawel Zarembski 0:01f31e923fe2 42 PIN_DAP_LED_PORT->PIO_OER = PIN_DAP_LED;
Pawel Zarembski 0:01f31e923fe2 43
Pawel Zarembski 0:01f31e923fe2 44 // MSD LED
Pawel Zarembski 0:01f31e923fe2 45 PIN_MSD_LED_PORT->PIO_PER = PIN_MSD_LED;
Pawel Zarembski 0:01f31e923fe2 46 PIN_MSD_LED_PORT->PIO_SODR = PIN_MSD_LED;
Pawel Zarembski 0:01f31e923fe2 47 PIN_MSD_LED_PORT->PIO_OER = PIN_MSD_LED;
Pawel Zarembski 0:01f31e923fe2 48
Pawel Zarembski 0:01f31e923fe2 49 // CDC LED
Pawel Zarembski 0:01f31e923fe2 50 PIN_CDC_LED_PORT->PIO_PER = PIN_CDC_LED;
Pawel Zarembski 0:01f31e923fe2 51 PIN_CDC_LED_PORT->PIO_SODR = PIN_CDC_LED;
Pawel Zarembski 0:01f31e923fe2 52 PIN_CDC_LED_PORT->PIO_OER = PIN_CDC_LED;
Pawel Zarembski 0:01f31e923fe2 53
Pawel Zarembski 0:01f31e923fe2 54 // Forwarded reset
Pawel Zarembski 0:01f31e923fe2 55 PIN_RESET_IN_FWRD_PORT->PIO_PER = PIN_RESET_IN_FWRD; // Pin == GPIO control
Pawel Zarembski 0:01f31e923fe2 56 PIN_RESET_IN_FWRD_PORT->PIO_ODR = PIN_RESET_IN_FWRD; // Disable output
Pawel Zarembski 0:01f31e923fe2 57 PIN_RESET_IN_FWRD_PORT->PIO_PUER = PIN_RESET_IN_FWRD; // Enable pull-up
Pawel Zarembski 0:01f31e923fe2 58 Cnt = 1000000;
Pawel Zarembski 0:01f31e923fe2 59 do {} while (--Cnt); // Give pull-up some time to become active
Pawel Zarembski 0:01f31e923fe2 60
Pawel Zarembski 0:01f31e923fe2 61 // Enable port A interrupts in the NVIC
Pawel Zarembski 0:01f31e923fe2 62 NVIC_EnableIRQ(PIOA_IRQn);
Pawel Zarembski 0:01f31e923fe2 63 }
Pawel Zarembski 0:01f31e923fe2 64
Pawel Zarembski 0:01f31e923fe2 65 void gpio_set_hid_led(gpio_led_state_t state)
Pawel Zarembski 0:01f31e923fe2 66 {
Pawel Zarembski 0:01f31e923fe2 67 if (GPIO_LED_ON == state) {
Pawel Zarembski 0:01f31e923fe2 68 PIN_DAP_LED_PORT->PIO_CODR = PIN_DAP_LED; // LED == on
Pawel Zarembski 0:01f31e923fe2 69 } else {
Pawel Zarembski 0:01f31e923fe2 70 PIN_DAP_LED_PORT->PIO_SODR = PIN_DAP_LED; // LED == off
Pawel Zarembski 0:01f31e923fe2 71 }
Pawel Zarembski 0:01f31e923fe2 72 }
Pawel Zarembski 0:01f31e923fe2 73
Pawel Zarembski 0:01f31e923fe2 74 void gpio_set_cdc_led(gpio_led_state_t state)
Pawel Zarembski 0:01f31e923fe2 75 {
Pawel Zarembski 0:01f31e923fe2 76 if (GPIO_LED_ON == state) {
Pawel Zarembski 0:01f31e923fe2 77 PIN_CDC_LED_PORT->PIO_CODR = PIN_CDC_LED; // LED == on
Pawel Zarembski 0:01f31e923fe2 78 } else {
Pawel Zarembski 0:01f31e923fe2 79 PIN_CDC_LED_PORT->PIO_SODR = PIN_CDC_LED; // LED == off
Pawel Zarembski 0:01f31e923fe2 80 }
Pawel Zarembski 0:01f31e923fe2 81 }
Pawel Zarembski 0:01f31e923fe2 82
Pawel Zarembski 0:01f31e923fe2 83 void gpio_set_msc_led(gpio_led_state_t state)
Pawel Zarembski 0:01f31e923fe2 84 {
Pawel Zarembski 0:01f31e923fe2 85 if (GPIO_LED_ON == state) {
Pawel Zarembski 0:01f31e923fe2 86 PIN_MSD_LED_PORT->PIO_CODR = PIN_MSD_LED; // LED == on
Pawel Zarembski 0:01f31e923fe2 87 } else {
Pawel Zarembski 0:01f31e923fe2 88 PIN_MSD_LED_PORT->PIO_SODR = PIN_MSD_LED; // LED == off
Pawel Zarembski 0:01f31e923fe2 89 }
Pawel Zarembski 0:01f31e923fe2 90 }
Pawel Zarembski 0:01f31e923fe2 91
Pawel Zarembski 0:01f31e923fe2 92 void PIOA_IRQHandler(void)
Pawel Zarembski 0:01f31e923fe2 93 {
Pawel Zarembski 0:01f31e923fe2 94 //
Pawel Zarembski 0:01f31e923fe2 95 // ISR is called when flow control is de-asserted
Pawel Zarembski 0:01f31e923fe2 96 //
Pawel Zarembski 0:01f31e923fe2 97 uint32_t interrupts = PIOA->PIO_ISR;
Pawel Zarembski 0:01f31e923fe2 98
Pawel Zarembski 0:01f31e923fe2 99 if ((interrupts >> 9) & 1) { //CTS
Pawel Zarembski 0:01f31e923fe2 100 uart_software_flow_control();
Pawel Zarembski 0:01f31e923fe2 101 }
Pawel Zarembski 0:01f31e923fe2 102 }
Pawel Zarembski 0:01f31e923fe2 103
Pawel Zarembski 0:01f31e923fe2 104 uint8_t gpio_get_reset_btn_no_fwrd(void)
Pawel Zarembski 0:01f31e923fe2 105 {
Pawel Zarembski 0:01f31e923fe2 106 return 0;
Pawel Zarembski 0:01f31e923fe2 107 }
Pawel Zarembski 0:01f31e923fe2 108
Pawel Zarembski 0:01f31e923fe2 109 uint8_t gpio_get_reset_btn_fwrd()
Pawel Zarembski 0:01f31e923fe2 110 {
Pawel Zarembski 0:01f31e923fe2 111 return (PIN_RESET_IN_FWRD_PORT->PIO_PDSR & PIN_RESET_IN_FWRD) == 0;
Pawel Zarembski 0:01f31e923fe2 112 }
Pawel Zarembski 0:01f31e923fe2 113
Pawel Zarembski 0:01f31e923fe2 114 void gpio_set_board_power(bool powerEnabled)
Pawel Zarembski 0:01f31e923fe2 115 {
Pawel Zarembski 0:01f31e923fe2 116 }