Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/board/microbit.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 microbit.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief board ID for the BBC Microbit board |
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 | #include "fsl_device_registers.h" |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #include "IO_Config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #include "DAP.h" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | #include "target_family.h" |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include "target_board.h" |
Pawel Zarembski |
0:01f31e923fe2 | 26 | |
Pawel Zarembski |
0:01f31e923fe2 | 27 | const char * const board_id_mb_1_3 = "9900"; |
Pawel Zarembski |
0:01f31e923fe2 | 28 | const char * const board_id_mb_1_5 = "9901"; |
Pawel Zarembski |
0:01f31e923fe2 | 29 | |
Pawel Zarembski |
0:01f31e923fe2 | 30 | typedef enum { |
Pawel Zarembski |
0:01f31e923fe2 | 31 | BOARD_VERSION_1_3 = 0, |
Pawel Zarembski |
0:01f31e923fe2 | 32 | BOARD_VERSION_1_5 = 1, |
Pawel Zarembski |
0:01f31e923fe2 | 33 | } mb_version_t; |
Pawel Zarembski |
0:01f31e923fe2 | 34 | |
Pawel Zarembski |
0:01f31e923fe2 | 35 | // Enables Board Type Pin, reads it and disables it |
Pawel Zarembski |
0:01f31e923fe2 | 36 | // Depends on gpio_init() to have been executed already |
Pawel Zarembski |
0:01f31e923fe2 | 37 | static uint8_t read_board_type_pin(void) { |
Pawel Zarembski |
0:01f31e923fe2 | 38 | uint8_t pin_state = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 39 | // GPIO mode, Pull enable, pull down, input |
Pawel Zarembski |
0:01f31e923fe2 | 40 | PIN_BOARD_TYPE_PORT->PCR[PIN_BOARD_TYPE_BIT] = PORT_PCR_MUX(1) | PORT_PCR_PE(1) | PORT_PCR_PS(0); |
Pawel Zarembski |
0:01f31e923fe2 | 41 | PIN_BOARD_TYPE_GPIO->PDDR &= ~PIN_BOARD_TYPE; |
Pawel Zarembski |
0:01f31e923fe2 | 42 | // Wait to stabilise, based on gpio.c busy_wait(), at -O2 10000 iterations delay ~850us |
Pawel Zarembski |
0:01f31e923fe2 | 43 | for (volatile uint32_t i = 10000; i > 0; i--); |
Pawel Zarembski |
0:01f31e923fe2 | 44 | // Read pin |
Pawel Zarembski |
0:01f31e923fe2 | 45 | pin_state = (PIN_BOARD_TYPE_GPIO->PDIR & PIN_BOARD_TYPE); |
Pawel Zarembski |
0:01f31e923fe2 | 46 | // Revert and disable |
Pawel Zarembski |
0:01f31e923fe2 | 47 | PIN_BOARD_TYPE_PORT->PCR[PIN_BOARD_TYPE_BIT] = PORT_PCR_MUX(0) | PORT_PCR_PE(0); |
Pawel Zarembski |
0:01f31e923fe2 | 48 | return pin_state; |
Pawel Zarembski |
0:01f31e923fe2 | 49 | } |
Pawel Zarembski |
0:01f31e923fe2 | 50 | |
Pawel Zarembski |
0:01f31e923fe2 | 51 | static void set_board_id(mb_version_t board_version) { |
Pawel Zarembski |
0:01f31e923fe2 | 52 | switch (board_version) { |
Pawel Zarembski |
0:01f31e923fe2 | 53 | case BOARD_VERSION_1_3: |
Pawel Zarembski |
0:01f31e923fe2 | 54 | target_device.rt_board_id = board_id_mb_1_3; |
Pawel Zarembski |
0:01f31e923fe2 | 55 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | case BOARD_VERSION_1_5: |
Pawel Zarembski |
0:01f31e923fe2 | 57 | target_device.rt_board_id = board_id_mb_1_5; |
Pawel Zarembski |
0:01f31e923fe2 | 58 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 59 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 60 | target_device.rt_board_id = board_id_mb_1_5; |
Pawel Zarembski |
0:01f31e923fe2 | 61 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 62 | } |
Pawel Zarembski |
0:01f31e923fe2 | 63 | } |
Pawel Zarembski |
0:01f31e923fe2 | 64 | |
Pawel Zarembski |
0:01f31e923fe2 | 65 | // Called in main_task() to init before USB and files are configured |
Pawel Zarembski |
0:01f31e923fe2 | 66 | static void prerun_board_config(void) { |
Pawel Zarembski |
0:01f31e923fe2 | 67 | // With only two boards the digital pin read maps directly to the type |
Pawel Zarembski |
0:01f31e923fe2 | 68 | mb_version_t board_version = (mb_version_t)read_board_type_pin(); |
Pawel Zarembski |
0:01f31e923fe2 | 69 | set_board_id(board_version); |
Pawel Zarembski |
0:01f31e923fe2 | 70 | } |
Pawel Zarembski |
0:01f31e923fe2 | 71 | |
Pawel Zarembski |
0:01f31e923fe2 | 72 | // USB HID override function return 1 if the activity is trivial or response is null |
Pawel Zarembski |
0:01f31e923fe2 | 73 | uint8_t usbd_hid_no_activity(uint8_t *buf) |
Pawel Zarembski |
0:01f31e923fe2 | 74 | { |
Pawel Zarembski |
0:01f31e923fe2 | 75 | if(buf[0] == ID_DAP_Vendor3 && buf[1] == 0) |
Pawel Zarembski |
0:01f31e923fe2 | 76 | return 1; |
Pawel Zarembski |
0:01f31e923fe2 | 77 | else |
Pawel Zarembski |
0:01f31e923fe2 | 78 | return 0; |
Pawel Zarembski |
0:01f31e923fe2 | 79 | } |
Pawel Zarembski |
0:01f31e923fe2 | 80 | |
Pawel Zarembski |
0:01f31e923fe2 | 81 | const board_info_t g_board_info = { |
Pawel Zarembski |
0:01f31e923fe2 | 82 | .info_version = kBoardInfoVersion, |
Pawel Zarembski |
0:01f31e923fe2 | 83 | .family_id = kNordic_Nrf51_FamilyID, |
Pawel Zarembski |
0:01f31e923fe2 | 84 | .daplink_url_name = "MICROBITHTM", |
Pawel Zarembski |
0:01f31e923fe2 | 85 | .daplink_drive_name = "MICROBIT ", |
Pawel Zarembski |
0:01f31e923fe2 | 86 | .daplink_target_url = "https://microbit.org/device/?id=@B&v=@V", |
Pawel Zarembski |
0:01f31e923fe2 | 87 | .prerun_board_config = prerun_board_config, |
Pawel Zarembski |
0:01f31e923fe2 | 88 | .target_cfg = &target_device, |
Pawel Zarembski |
0:01f31e923fe2 | 89 | }; |