blob: b7f318c979cd4d6ef78065e2913a5d488e09518f [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#include "cmsis.h"
18
19extern void *__Vectors; /* see irqs.c */
20
21/*----------------------------------------------------------------------------*\
22 * Define clocks (uses OSC1 ACLK) *
23\*----------------------------------------------------------------------------*/
24#define __XTAL (25000000) /* Oscillator frequency */
25#define __SYSTEM_CLOCK (__XTAL)
26
alexander3c798932021-03-26 21:42:19 +000027#if defined(CPU_CORTEX_M55)
28#define CCR_DL (1 << 19)
29#else
30#error "Invalid CPU; This file only services Cortex-M55 CPUs"
31#endif /* (CPU_CORTEX_M55) */
32
33/*----------------------------------------------------------------------------
34 System Core Clock Variable (Core Clock)
35 *----------------------------------------------------------------------------*/
36uint32_t SystemCoreClock = __SYSTEM_CLOCK;
37
38
39/*----------------------------------------------------------------------------
40 Clock functions
41 *----------------------------------------------------------------------------*/
42/**
43 * @brief Updates the SystemCoreClock variable with current core Clock
44 * retrieved from cpu registers.
45 */
46void SystemCoreClockUpdate(void)
47{
48 /* Update the SystemCoreClock variable */
49 SystemCoreClock = __SYSTEM_CLOCK;
50}
51
52uint32_t GetSystemCoreClock(void)
53{
54 return SystemCoreClock;
55}
56
57/**
58 * @brief Setup the microcontroller system.
59 * Initialize the System.
60 **/
61void SystemInit(void)
62{
63#if (defined (__FPU_USED) && (__FPU_USED == 1U)) || \
64 (defined (__MVE_USED) && (__MVE_USED == 1U))
65 SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */
66 (3U << 11U*2U) );
67#endif
68
alexander3c798932021-03-26 21:42:19 +000069#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
70 SCB->VTOR = (uint32_t) &__Vectors;
71#endif
72
73 /* Enable hard, bus, mem and usage fault detection in SHCSR, bits 16-18.
74 * Enable stkof, bf, div_0_trp, unalign_trp and usersetm bits in CCR.
75 */
76 SCB->SHCSR = (
77 _VAL2FLD(SCB_SHCSR_USGFAULTENA, 1) |
78 _VAL2FLD(SCB_SHCSR_BUSFAULTENA, 1) |
79 _VAL2FLD(SCB_SHCSR_MEMFAULTENA, 1));
80
81 SCB->CCR = (_VAL2FLD(SCB_CCR_USERSETMPEND, 1) |
82 _VAL2FLD(SCB_CCR_DIV_0_TRP, 1) |
83 _VAL2FLD(SCB_CCR_BFHFNMIGN, 1) |
84 _VAL2FLD(SCB_CCR_STKOFHFNMIGN, 1));
85#ifdef UNALIGNED_SUPPORT_DISABLE
86 SCB->CCR |= _VAL2FLD(SCB_CCR_UNALIGN_TRP, 1);
87#endif
88
89 SCB->CCR |= CCR_DL;
90
91 /* Reset pipeline. */
92 __DSB();
93 __ISB();
94
95#ifdef UNALIGNED_SUPPORT_DISABLE
96 SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk;
97#endif
98
99 SystemCoreClock = __SYSTEM_CLOCK;
100}