Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
microbit.c
00001 /** 00002 * @file microbit.c 00003 * @brief board ID for the BBC Microbit board 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 #include "fsl_device_registers.h" 00022 #include "IO_Config.h" 00023 #include "DAP.h" 00024 #include "target_family.h" 00025 #include "target_board.h" 00026 00027 const char * const board_id_mb_1_3 = "9900"; 00028 const char * const board_id_mb_1_5 = "9901"; 00029 00030 typedef enum { 00031 BOARD_VERSION_1_3 = 0, 00032 BOARD_VERSION_1_5 = 1, 00033 } mb_version_t; 00034 00035 // Enables Board Type Pin, reads it and disables it 00036 // Depends on gpio_init() to have been executed already 00037 static uint8_t read_board_type_pin(void) { 00038 uint8_t pin_state = 0; 00039 // GPIO mode, Pull enable, pull down, input 00040 PIN_BOARD_TYPE_PORT->PCR[PIN_BOARD_TYPE_BIT] = PORT_PCR_MUX(1) | PORT_PCR_PE(1) | PORT_PCR_PS(0); 00041 PIN_BOARD_TYPE_GPIO->PDDR &= ~PIN_BOARD_TYPE; 00042 // Wait to stabilise, based on gpio.c busy_wait(), at -O2 10000 iterations delay ~850us 00043 for (volatile uint32_t i = 10000; i > 0; i--); 00044 // Read pin 00045 pin_state = (PIN_BOARD_TYPE_GPIO->PDIR & PIN_BOARD_TYPE); 00046 // Revert and disable 00047 PIN_BOARD_TYPE_PORT->PCR[PIN_BOARD_TYPE_BIT] = PORT_PCR_MUX(0) | PORT_PCR_PE(0); 00048 return pin_state; 00049 } 00050 00051 static void set_board_id(mb_version_t board_version) { 00052 switch (board_version) { 00053 case BOARD_VERSION_1_3: 00054 target_device.rt_board_id = board_id_mb_1_3; 00055 break; 00056 case BOARD_VERSION_1_5: 00057 target_device.rt_board_id = board_id_mb_1_5; 00058 break; 00059 default: 00060 target_device.rt_board_id = board_id_mb_1_5; 00061 break; 00062 } 00063 } 00064 00065 // Called in main_task() to init before USB and files are configured 00066 static void prerun_board_config(void) { 00067 // With only two boards the digital pin read maps directly to the type 00068 mb_version_t board_version = (mb_version_t)read_board_type_pin(); 00069 set_board_id(board_version); 00070 } 00071 00072 // USB HID override function return 1 if the activity is trivial or response is null 00073 uint8_t usbd_hid_no_activity(uint8_t *buf) 00074 { 00075 if(buf[0] == ID_DAP_Vendor3 && buf[1] == 0) 00076 return 1; 00077 else 00078 return 0; 00079 } 00080 00081 const board_info_t g_board_info = { 00082 .info_version = kBoardInfoVersion, 00083 .family_id = kNordic_Nrf51_FamilyID, 00084 .daplink_url_name = "MICROBITHTM", 00085 .daplink_drive_name = "MICROBIT ", 00086 .daplink_target_url = "https://microbit.org/device/?id=@B&v=@V", 00087 .prerun_board_config = prerun_board_config, 00088 .target_cfg = &target_device, 00089 };
Generated on Tue Jul 12 2022 15:37:20 by
1.7.2