1 /* 2 3 Copyright (c) 2009-2020 ARM Limited. All rights reserved. 4 5 SPDX-License-Identifier: Apache-2.0 6 7 Licensed under the Apache License, Version 2.0 (the License); you may 8 not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an AS IS BASIS, WITHOUT 15 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 NOTICE: This file has been modified by Nordic Semiconductor ASA. 20 21 */ 22 23 /* NOTE: Template files (including this one) are application specific and therefore expected to 24 be copied into the application project folder prior to its use! */ 25 26 #include <stdint.h> 27 #include <stdbool.h> 28 #include "nrf.h" 29 #include "nrf_erratas.h" 30 #include "system_nrf51.h" 31 32 /*lint ++flb "Enter library region" */ 33 34 35 #define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */ 36 37 #if defined ( __CC_ARM ) 38 uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK; 39 #elif defined ( __ICCARM__ ) 40 __root uint32_t SystemCoreClock = __SYSTEM_CLOCK; 41 #elif defined ( __GNUC__ ) 42 uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK; 43 #endif 44 SystemCoreClockUpdate(void)45void SystemCoreClockUpdate(void) 46 { 47 SystemCoreClock = __SYSTEM_CLOCK; 48 } 49 SystemInit(void)50void SystemInit(void) 51 { 52 /* If desired, switch off the unused RAM to lower consumption by the use of RAMON register. 53 It can also be done in the application main() function. */ 54 55 /* Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required 56 to enable the use of peripherals" found at Product Anomaly document for your device found at 57 https://infocenter.nordicsemi.com/index.jsp The side effect of executing these instructions in the devices 58 that do not need it is that the new peripherals in the second generation devices (LPCOMP for 59 example) will not be available. */ 60 if (nrf51_errata_26()) 61 { 62 *(uint32_t volatile *)0x40000504 = 0xC007FFDF; 63 *(uint32_t volatile *)0x40006C18 = 0x00008000; 64 } 65 66 /* Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG 67 register is incorrect" found at Product Anomaly document for your device found at 68 https://infocenter.nordicsemi.com/index.jsp There is no side effect of using these instruction if not needed. */ 69 if (nrf51_errata_59()) 70 { 71 NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos; 72 } 73 74 /* Execute the following code to eliminate excessive current in sleep mode with RAM retention in nRF51802 devices, 75 as indicated by PAN 76 "System: Excessive current in sleep mode with retention" found at Product Anomaly document 76 for your device found at https://infocenter.nordicsemi.com/index.jsp */ 77 if (nrf51_errata_76()){ 78 if (*(uint32_t volatile *)0x4006EC00 != 1){ 79 *(uint32_t volatile *)0x4006EC00 = 0x9375; 80 while (*(uint32_t volatile *)0x4006EC00 != 1){ 81 } 82 } 83 *(uint32_t volatile *)0x4006EC14 = 0xC0; 84 } 85 86 SystemCoreClockUpdate(); 87 } 88 89 /*lint --flb "Leave library region" */ 90