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_nrf5340_network.h"
31 
32 /*lint ++flb "Enter library region" */
33 
34 
35 #define __SYSTEM_CLOCK      (64000000UL)     /*!< NRF5340 network core uses a fixed System Clock Frequency of 32MHz */
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)45 void SystemCoreClockUpdate(void)
46 {
47     SystemCoreClock = __SYSTEM_CLOCK;
48 }
49 
SystemInit(void)50 void SystemInit(void)
51 {
52     /* Trimming of the device. Copy all the trimming values from FICR into the target addresses. Trim
53      until one ADDR is not initialized. */
54     uint32_t index = 0;
55     for (index = 0; index < 32ul && NRF_FICR_NS->TRIMCNF[index].ADDR != (uint32_t *)0xFFFFFFFFul; index++){
56         #if defined ( __ICCARM__ )
57             /* IAR will complain about the order of volatile pointer accesses. */
58             #pragma diag_suppress=Pa082
59         #endif
60         *NRF_FICR_NS->TRIMCNF[index].ADDR = NRF_FICR_NS->TRIMCNF[index].DATA;
61         #if defined ( __ICCARM__ )
62             #pragma diag_default=Pa082
63         #endif
64     }
65 
66     /* Workaround for Errata 49 "SLEEPENTER and SLEEPEXIT events asserted after pin reset" found at the Errata document
67        for your device located at https://infocenter.nordicsemi.com/index.jsp  */
68     if (nrf53_errata_49())
69     {
70         if (NRF_RESET_NS->RESETREAS & RESET_RESETREAS_RESETPIN_Msk)
71         {
72             NRF_POWER_NS->EVENTS_SLEEPENTER = 0;
73             NRF_POWER_NS->EVENTS_SLEEPEXIT = 0;
74         }
75     }
76 
77     /* Workaround for Errata 55 "Bits in RESETREAS are set when they should not be" found at the Errata document
78        for your device located at https://infocenter.nordicsemi.com/index.jsp  */
79     if (nrf53_errata_55())
80     {
81         if (NRF_RESET_NS->RESETREAS & RESET_RESETREAS_RESETPIN_Msk){
82             NRF_RESET_NS->RESETREAS = ~RESET_RESETREAS_RESETPIN_Msk;
83         }
84     }
85 
86     SystemCoreClockUpdate();
87 }
88 
89 /*lint --flb "Leave library region" */
90