1 /* 2 3 Copyright (c) 2009-2024 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 "nrf53_erratas.h" 30 #include "system_nrf53.h" 31 #include "system_nrf53_approtect.h" 32 33 /*lint ++flb "Enter library region" */ 34 35 36 #define __SYSTEM_CLOCK_DEFAULT (64000000UL) /*!< NRF5340 network core uses a fixed System Clock Frequency of 64MHz */ 37 38 #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 39 uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_DEFAULT; 40 #elif defined ( __ICCARM__ ) 41 __root uint32_t SystemCoreClock = __SYSTEM_CLOCK_DEFAULT; 42 #endif 43 SystemCoreClockUpdate(void)44void SystemCoreClockUpdate(void) 45 { 46 SystemCoreClock = __SYSTEM_CLOCK_DEFAULT; 47 } 48 SystemInit(void)49void SystemInit(void) 50 { 51 /* Trimming of the device. Copy all the trimming values from FICR into the target addresses. Trim 52 until one ADDR is not initialized. */ 53 uint32_t index = 0; 54 for (index = 0; index < 32ul && NRF_FICR_NS->TRIMCNF[index].ADDR != 0xFFFFFFFFul; index++){ 55 #if defined ( __ICCARM__ ) 56 /* IAR will complain about the order of volatile pointer accesses. */ 57 #pragma diag_suppress=Pa082 58 #endif 59 *((volatile uint32_t *)NRF_FICR_NS->TRIMCNF[index].ADDR) = NRF_FICR_NS->TRIMCNF[index].DATA; 60 #if defined ( __ICCARM__ ) 61 #pragma diag_default=Pa082 62 #endif 63 } 64 65 /* Workaround for Errata 49 "SLEEPENTER and SLEEPEXIT events asserted after pin reset" found at the Errata document 66 for your device located at https://infocenter.nordicsemi.com/index.jsp */ 67 if (nrf53_errata_49()) 68 { 69 if (NRF_RESET_NS->RESETREAS & RESET_RESETREAS_RESETPIN_Msk) 70 { 71 NRF_POWER_NS->EVENTS_SLEEPENTER = 0ul; 72 NRF_POWER_NS->EVENTS_SLEEPEXIT = 0ul; 73 } 74 } 75 76 /* Workaround for Errata 55 "Bits in RESETREAS are set when they should not be" found at the Errata document 77 for your device located at https://infocenter.nordicsemi.com/index.jsp */ 78 if (nrf53_errata_55()) 79 { 80 if (NRF_RESET_NS->RESETREAS & RESET_RESETREAS_RESETPIN_Msk){ 81 NRF_RESET_NS->RESETREAS = ~RESET_RESETREAS_RESETPIN_Msk; 82 } 83 } 84 85 if (nrf53_errata_160()) 86 { 87 *((volatile uint32_t *)0x41002118ul) = 0x7Ful; 88 *((volatile uint32_t *)0x41080E04ul) = 0x0ul; 89 *((volatile uint32_t *)0x41080E08ul) = 0x0ul; 90 *((volatile uint32_t *)0x41002124ul) = 0x0ul; 91 *((volatile uint32_t *)0x4100212Cul) = 0x0ul; 92 *((volatile uint32_t *)0x41101110ul) = 0x0ul; 93 } 94 95 /* Handle fw-branch APPROTECT setup. */ 96 nrf53_handle_approtect(); 97 } 98 99 /*lint --flb "Leave library region" */ 100