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.
mkit_dk_dongle_nrf5x.c
00001 /** 00002 * @file nrf5x.c 00003 * @brief board ID for the Nordic nRF5x developments boards 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 00022 #include "sam3u2c.h" 00023 #include "DAP_config.h" 00024 #include "target_config.h" 00025 #include "util.h" 00026 #include "flash_manager.h" 00027 #include "target_family.h" 00028 #include "target_board.h" 00029 00030 // BOARD_ID pointer will be set during run time to point to one of these 00031 const char *board_id_nrf51_mkit = "1070"; 00032 const char *board_id_nrf51_dk = "1100"; 00033 const char *board_id_nrf51_dongle = "1120"; 00034 const char *board_id_nrf52_dk = "1101"; 00035 const char *board_id_nrf52840_dk = "1102"; 00036 00037 extern target_cfg_t target_device_nrf52; 00038 extern target_cfg_t target_device_nrf52840; 00039 static uint8_t device_type; 00040 00041 static void set_target_device(uint32_t device) 00042 { 00043 device_type = device; 00044 if (device == 0) { 00045 // Target device already set to nRF51 00046 } 00047 else if (device == 1) { 00048 target_device = target_device_nrf52; 00049 } 00050 else if (device == 2) { 00051 target_device = target_device_nrf52840; 00052 } 00053 } 00054 00055 00056 static void nrf_prerun_board_config(void) 00057 { 00058 // Work around for setting the correct board id based on GPIOs 00059 uint8_t bit1; 00060 uint8_t bit2; 00061 uint8_t bit3; 00062 00063 PIOB->PIO_PER = (1 << 1); // Enable PIO pin PB1 00064 PIOB->PIO_PER = (1 << 2); // Enable PIO pin PB2 00065 PIOB->PIO_PER = (1 << 3); // Enable PIO pin PB3 00066 PIOB->PIO_ODR = (1 << 1); // Disabe output 00067 PIOB->PIO_ODR = (1 << 2); // Disabe output 00068 PIOB->PIO_ODR = (1 << 3); // Disabe output 00069 PIOB->PIO_PUER = (1 << 1); // Enable pull-up 00070 PIOB->PIO_PUER = (1 << 2); // Enable pull-up 00071 PIOB->PIO_PUER = (1 << 3); // Enable pull-up 00072 00073 bit1 = (PIOB->PIO_PDSR >> 1) & 1; // Read PB1 00074 bit2 = (PIOB->PIO_PDSR >> 2) & 1; // Read PB2 00075 bit3 = (PIOB->PIO_PDSR >> 3) & 1; // Read PB3 00076 00077 /* pins translate to board-ids as follow 00078 * 00079 * PB3|PB2|PB1|BOARD ID| BOARD 00080 * ---------------------------------- 00081 * 0 | 0 | 0 | 1120 | nRF51-Dongle 00082 * 0 | 0 | 1 | 1100 | nRF51-DK 00083 * 0 | 1 | 0 | 1101 | nRF52-DK 00084 * 0 | 1 | 1 | 1102 | nRF52840-DK 00085 * 1 | 1 | 1 | 1070 | older nRF51 (mkit) 00086 * 1 | 0 | 0 | undefined 00087 * 1 | 0 | 1 | undefined 00088 * 1 | 1 | 0 | undefined 00089 */ 00090 00091 00092 if (bit3) { 00093 set_target_device(0); 00094 target_device.rt_family_id = kNordic_Nrf51_FamilyID; 00095 target_device.rt_board_id = board_id_nrf51_mkit; // 1070 00096 //Note only a setting of 111 is defined 00097 util_assert(bit2 && bit1); 00098 } else { 00099 if (!bit2 && bit1) { 00100 set_target_device(0); 00101 target_device.rt_family_id = kNordic_Nrf51_FamilyID; 00102 target_device.rt_board_id = board_id_nrf51_dk; // 1100 00103 } 00104 else if (!bit2 && !bit1) { 00105 set_target_device(0); 00106 target_device.rt_family_id = kNordic_Nrf51_FamilyID; 00107 target_device.rt_board_id = board_id_nrf51_dongle; // 1120 00108 } 00109 else if (bit2 && !bit1) { 00110 set_target_device(1); 00111 target_device.rt_family_id = kNordic_Nrf52_FamilyID; 00112 target_device.rt_board_id = board_id_nrf52_dk; // 1101 00113 } else { //(bit2 && bit1) 00114 set_target_device(2); 00115 target_device.rt_family_id = kNordic_Nrf52_FamilyID; 00116 target_device.rt_board_id = board_id_nrf52840_dk; // 1102 00117 } 00118 } 00119 00120 PIOB->PIO_PUDR = (1 << 1); // Disable pull-up 00121 PIOB->PIO_PUDR = (1 << 2); // Disable pull-up 00122 PIOB->PIO_PUDR = (1 << 3); // Disable pull-up 00123 } 00124 00125 static void nrf_swd_set_target_reset(uint8_t asserted){ 00126 if (asserted && device_type == 0) { 00127 PIOA->PIO_OER = PIN_SWDIO; 00128 PIOA->PIO_OER = PIN_SWCLK; 00129 }else if(!asserted) { 00130 PIOA->PIO_MDER = PIN_SWDIO | PIN_SWCLK | PIN_nRESET; 00131 } 00132 } 00133 00134 const board_info_t g_board_info = { 00135 .info_version = kBoardInfoVersion, 00136 .flags = kEnablePageErase , 00137 .prerun_board_config = nrf_prerun_board_config, 00138 .swd_set_target_reset = nrf_swd_set_target_reset, 00139 .target_cfg = &target_device, 00140 };
Generated on Tue Jul 12 2022 15:37:21 by
1.7.2