Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/hic_hal/freescale/kl26z/gpio.c@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 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 "gpio.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | |
Pawel Zarembski |
0:01f31e923fe2 | 24 | static void busy_wait(uint32_t cycles) |
Pawel Zarembski |
0:01f31e923fe2 | 25 | { |
Pawel Zarembski |
0:01f31e923fe2 | 26 | volatile uint32_t i; |
Pawel Zarembski |
0:01f31e923fe2 | 27 | i = cycles; |
Pawel Zarembski |
0:01f31e923fe2 | 28 | |
Pawel Zarembski |
0:01f31e923fe2 | 29 | while (i > 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 30 | i--; |
Pawel Zarembski |
0:01f31e923fe2 | 31 | } |
Pawel Zarembski |
0:01f31e923fe2 | 32 | } |
Pawel Zarembski |
0:01f31e923fe2 | 33 | |
Pawel Zarembski |
0:01f31e923fe2 | 34 | void gpio_init(void) |
Pawel Zarembski |
0:01f31e923fe2 | 35 | { |
Pawel Zarembski |
0:01f31e923fe2 | 36 | SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK; |
Pawel Zarembski |
0:01f31e923fe2 | 37 | // configure pin as GPIO |
Pawel Zarembski |
0:01f31e923fe2 | 38 | PIN_HID_LED_PORT->PCR[PIN_HID_LED_BIT] = PORT_PCR_MUX(1); |
Pawel Zarembski |
0:01f31e923fe2 | 39 | PIN_MSC_LED_PORT->PCR[PIN_MSC_LED_BIT] = PORT_PCR_MUX(1); |
Pawel Zarembski |
0:01f31e923fe2 | 40 | PIN_CDC_LED_PORT->PCR[PIN_CDC_LED_BIT] = PORT_PCR_MUX(1); |
Pawel Zarembski |
0:01f31e923fe2 | 41 | PIN_SW_RESET_PORT->PCR[PIN_SW_RESET_BIT] = PORT_PCR_MUX(1); |
Pawel Zarembski |
0:01f31e923fe2 | 42 | PIN_POWER_EN_PORT->PCR[PIN_POWER_EN_BIT] = PORT_PCR_MUX(1); |
Pawel Zarembski |
0:01f31e923fe2 | 43 | // led off |
Pawel Zarembski |
0:01f31e923fe2 | 44 | gpio_set_hid_led(GPIO_LED_OFF); |
Pawel Zarembski |
0:01f31e923fe2 | 45 | gpio_set_cdc_led(GPIO_LED_OFF); |
Pawel Zarembski |
0:01f31e923fe2 | 46 | gpio_set_msc_led(GPIO_LED_OFF); |
Pawel Zarembski |
0:01f31e923fe2 | 47 | // power regulator on |
Pawel Zarembski |
0:01f31e923fe2 | 48 | PIN_POWER_EN_GPIO->PDOR |= PIN_POWER_EN; |
Pawel Zarembski |
0:01f31e923fe2 | 49 | // set as output |
Pawel Zarembski |
0:01f31e923fe2 | 50 | PIN_HID_LED_GPIO->PDDR |= PIN_HID_LED; |
Pawel Zarembski |
0:01f31e923fe2 | 51 | PIN_MSC_LED_GPIO->PDDR |= PIN_MSC_LED; |
Pawel Zarembski |
0:01f31e923fe2 | 52 | PIN_CDC_LED_GPIO->PDDR |= PIN_CDC_LED; |
Pawel Zarembski |
0:01f31e923fe2 | 53 | PIN_POWER_EN_GPIO->PDDR |= PIN_POWER_EN; |
Pawel Zarembski |
0:01f31e923fe2 | 54 | // set as input |
Pawel Zarembski |
0:01f31e923fe2 | 55 | PIN_SW_RESET_GPIO->PDDR &= ~PIN_SW_RESET; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | // Let the voltage rails stabilize. This is especailly important |
Pawel Zarembski |
0:01f31e923fe2 | 58 | // during software resets, since the target's 3.3v rail can take |
Pawel Zarembski |
0:01f31e923fe2 | 59 | // 20-50ms to drain. During this time the target could be driving |
Pawel Zarembski |
0:01f31e923fe2 | 60 | // the reset pin low, causing the bootloader to think the reset |
Pawel Zarembski |
0:01f31e923fe2 | 61 | // button is pressed. |
Pawel Zarembski |
0:01f31e923fe2 | 62 | // Note: With optimization set to -O2 the value 1000000 delays for ~85ms |
Pawel Zarembski |
0:01f31e923fe2 | 63 | busy_wait(1000000); |
Pawel Zarembski |
0:01f31e923fe2 | 64 | } |
Pawel Zarembski |
0:01f31e923fe2 | 65 | |
Pawel Zarembski |
0:01f31e923fe2 | 66 | void gpio_set_hid_led(gpio_led_state_t state) |
Pawel Zarembski |
0:01f31e923fe2 | 67 | { |
Pawel Zarembski |
0:01f31e923fe2 | 68 | (GPIO_LED_ON == state) ? (PIN_HID_LED_GPIO->PCOR = PIN_HID_LED) : (PIN_HID_LED_GPIO->PSOR = PIN_HID_LED); |
Pawel Zarembski |
0:01f31e923fe2 | 69 | } |
Pawel Zarembski |
0:01f31e923fe2 | 70 | |
Pawel Zarembski |
0:01f31e923fe2 | 71 | void gpio_set_cdc_led(gpio_led_state_t state) |
Pawel Zarembski |
0:01f31e923fe2 | 72 | { |
Pawel Zarembski |
0:01f31e923fe2 | 73 | (GPIO_LED_ON == state) ? (PIN_CDC_LED_GPIO->PCOR = PIN_CDC_LED) : (PIN_CDC_LED_GPIO->PSOR = PIN_CDC_LED); |
Pawel Zarembski |
0:01f31e923fe2 | 74 | } |
Pawel Zarembski |
0:01f31e923fe2 | 75 | |
Pawel Zarembski |
0:01f31e923fe2 | 76 | void gpio_set_msc_led(gpio_led_state_t state) |
Pawel Zarembski |
0:01f31e923fe2 | 77 | { |
Pawel Zarembski |
0:01f31e923fe2 | 78 | (GPIO_LED_ON == state) ? (PIN_MSC_LED_GPIO->PCOR = PIN_MSC_LED) : (PIN_MSC_LED_GPIO->PSOR = PIN_MSC_LED); |
Pawel Zarembski |
0:01f31e923fe2 | 79 | } |
Pawel Zarembski |
0:01f31e923fe2 | 80 | |
Pawel Zarembski |
0:01f31e923fe2 | 81 | uint8_t gpio_get_reset_btn_no_fwrd(void) |
Pawel Zarembski |
0:01f31e923fe2 | 82 | { |
Pawel Zarembski |
0:01f31e923fe2 | 83 | return 0; |
Pawel Zarembski |
0:01f31e923fe2 | 84 | } |
Pawel Zarembski |
0:01f31e923fe2 | 85 | |
Pawel Zarembski |
0:01f31e923fe2 | 86 | uint8_t gpio_get_reset_btn_fwrd(void) |
Pawel Zarembski |
0:01f31e923fe2 | 87 | { |
Pawel Zarembski |
0:01f31e923fe2 | 88 | return (PIN_SW_RESET_GPIO->PDIR & PIN_SW_RESET) ? 0 : 1; |
Pawel Zarembski |
0:01f31e923fe2 | 89 | } |
Pawel Zarembski |
0:01f31e923fe2 | 90 | |
Pawel Zarembski |
0:01f31e923fe2 | 91 | void gpio_set_board_power(bool powerEnabled) |
Pawel Zarembski |
0:01f31e923fe2 | 92 | { |
Pawel Zarembski |
0:01f31e923fe2 | 93 | } |