|
| 1 | +/* |
| 2 | +
|
| 3 | +Copyright (c) 2009-2018 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 | +#ifdef NRF52833_XXAA |
| 27 | + |
| 28 | +#include <stdint.h> |
| 29 | +#include <stdbool.h> |
| 30 | +#include "nrf.h" |
| 31 | +#include "nrf_erratas.h" |
| 32 | +#include "system_nrf52833.h" |
| 33 | + |
| 34 | +/*lint ++flb "Enter library region" */ |
| 35 | + |
| 36 | +#define __SYSTEM_CLOCK_64M (64000000UL) |
| 37 | + |
| 38 | +#if defined ( __CC_ARM ) |
| 39 | + uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M; |
| 40 | +#elif defined ( __ICCARM__ ) |
| 41 | + __root uint32_t SystemCoreClock = __SYSTEM_CLOCK_64M; |
| 42 | +#elif defined ( __GNUC__ ) |
| 43 | + uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M; |
| 44 | +#endif |
| 45 | + |
| 46 | +void SystemCoreClockUpdate(void) |
| 47 | +{ |
| 48 | + SystemCoreClock = __SYSTEM_CLOCK_64M; |
| 49 | +} |
| 50 | + |
| 51 | +void SystemInit(void) |
| 52 | +{ |
| 53 | + /* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product |
| 54 | + Specification to see which one). */ |
| 55 | + #if defined (ENABLE_SWO) |
| 56 | + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; |
| 57 | + NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos; |
| 58 | + NRF_P1->PIN_CNF[0] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
| 59 | + #endif |
| 60 | + |
| 61 | + /* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product |
| 62 | + Specification to see which ones). */ |
| 63 | + #if defined (ENABLE_TRACE) |
| 64 | + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; |
| 65 | + NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos; |
| 66 | + NRF_P0->PIN_CNF[7] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
| 67 | + NRF_P1->PIN_CNF[0] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
| 68 | + NRF_P0->PIN_CNF[12] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
| 69 | + NRF_P0->PIN_CNF[11] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
| 70 | + NRF_P1->PIN_CNF[9] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
| 71 | + #endif |
| 72 | + |
| 73 | + /* Workaround for Errata 36 "CLOCK: Some registers are not reset when expected" found at the Errata document |
| 74 | + for your device located at https://infocenter.nordicsemi.com/index.jsp */ |
| 75 | + if (nrf52_errata_36()){ |
| 76 | + NRF_CLOCK->EVENTS_DONE = 0; |
| 77 | + NRF_CLOCK->EVENTS_CTTO = 0; |
| 78 | + NRF_CLOCK->CTIV = 0; |
| 79 | + } |
| 80 | + |
| 81 | + /* Workaround for Errata 66 "TEMP: Linearity specification not met with default settings" found at the Errata document |
| 82 | + for your device located at https://infocenter.nordicsemi.com/index.jsp */ |
| 83 | + if (nrf52_errata_66()){ |
| 84 | + NRF_TEMP->A0 = NRF_FICR->TEMP.A0; |
| 85 | + NRF_TEMP->A1 = NRF_FICR->TEMP.A1; |
| 86 | + NRF_TEMP->A2 = NRF_FICR->TEMP.A2; |
| 87 | + NRF_TEMP->A3 = NRF_FICR->TEMP.A3; |
| 88 | + NRF_TEMP->A4 = NRF_FICR->TEMP.A4; |
| 89 | + NRF_TEMP->A5 = NRF_FICR->TEMP.A5; |
| 90 | + NRF_TEMP->B0 = NRF_FICR->TEMP.B0; |
| 91 | + NRF_TEMP->B1 = NRF_FICR->TEMP.B1; |
| 92 | + NRF_TEMP->B2 = NRF_FICR->TEMP.B2; |
| 93 | + NRF_TEMP->B3 = NRF_FICR->TEMP.B3; |
| 94 | + NRF_TEMP->B4 = NRF_FICR->TEMP.B4; |
| 95 | + NRF_TEMP->B5 = NRF_FICR->TEMP.B5; |
| 96 | + NRF_TEMP->T0 = NRF_FICR->TEMP.T0; |
| 97 | + NRF_TEMP->T1 = NRF_FICR->TEMP.T1; |
| 98 | + NRF_TEMP->T2 = NRF_FICR->TEMP.T2; |
| 99 | + NRF_TEMP->T3 = NRF_FICR->TEMP.T3; |
| 100 | + NRF_TEMP->T4 = NRF_FICR->TEMP.T4; |
| 101 | + } |
| 102 | + |
| 103 | + /* Workaround for Errata 136 "System: Bits in RESETREAS are set when they should not be" found at the Errata document |
| 104 | + for your device located at https://infocenter.nordicsemi.com/index.jsp */ |
| 105 | + if (nrf52_errata_136()){ |
| 106 | + if (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk){ |
| 107 | + NRF_POWER->RESETREAS = ~POWER_RESETREAS_RESETPIN_Msk; |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + /* Enable the FPU if the compiler used floating point unit instructions. __FPU_USED is a MACRO defined by the |
| 112 | + * compiler. Since the FPU consumes energy, remember to disable FPU use in the compiler if floating point unit |
| 113 | + * operations are not used in your code. */ |
| 114 | + #if (__FPU_USED == 1) |
| 115 | + SCB->CPACR |= (3UL << 20) | (3UL << 22); |
| 116 | + __DSB(); |
| 117 | + __ISB(); |
| 118 | + #endif |
| 119 | + |
| 120 | + /* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined, |
| 121 | + two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available as |
| 122 | + normal GPIOs. */ |
| 123 | + #if defined (CONFIG_NFCT_PINS_AS_GPIOS) |
| 124 | + if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){ |
| 125 | + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; |
| 126 | + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
| 127 | + NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk; |
| 128 | + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
| 129 | + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; |
| 130 | + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
| 131 | + NVIC_SystemReset(); |
| 132 | + } |
| 133 | + #endif |
| 134 | + |
| 135 | + /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not |
| 136 | + defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be |
| 137 | + reserved for PinReset and not available as normal GPIO. */ |
| 138 | + #if defined (CONFIG_GPIO_AS_PINRESET) |
| 139 | + if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) || |
| 140 | + ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){ |
| 141 | + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; |
| 142 | + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
| 143 | + NRF_UICR->PSELRESET[0] = 18; |
| 144 | + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
| 145 | + NRF_UICR->PSELRESET[1] = 18; |
| 146 | + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
| 147 | + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; |
| 148 | + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
| 149 | + NVIC_SystemReset(); |
| 150 | + } |
| 151 | + #endif |
| 152 | + |
| 153 | + SystemCoreClockUpdate(); |
| 154 | +} |
| 155 | + |
| 156 | +/*lint --flb "Leave library region" */ |
| 157 | + |
| 158 | +#endif |
| 159 | + |
0 commit comments