]> begriffs open source - cmsis/blob - CMSIS/Core/Template/Device_M/Source/system_Device.c
Possible bugs in MMU_MemorySection(), MMU_MemoryPage() (#219)
[cmsis] / CMSIS / Core / Template / Device_M / Source / system_Device.c
1 /*************************************************************************//**
2  * @file     system_<Device>.c
3  * @brief    CMSIS-Core(M) Device Peripheral Access Layer Source File for
4  *           Device <Device>
5  * @version  V1.0.0
6  * @date     20. January 2021
7  *****************************************************************************/
8 /*
9  * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
10  *
11  * SPDX-License-Identifier: Apache-2.0
12  *
13  * Licensed under the Apache License, Version 2.0 (the License); you may
14  * not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
21  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */
25
26 /* ToDo: rename this file from 'system_Device.c' to 'system_<Device>.c according to your device naming */
27
28 #include <stdint.h>
29 #include "<Device>.h"
30
31 /* ToDo: Include partition header file if TZ is used */
32 #if defined (__ARM_FEATURE_CMSE) &&  (__ARM_FEATURE_CMSE == 3U)
33   #include "partition_<Device>.h"
34 #endif
35
36
37 /*---------------------------------------------------------------------------
38   Define clocks
39  *---------------------------------------------------------------------------*/
40 /* ToDo: Add here your necessary defines for device initialization
41          following is an example for different system frequencies */
42 #define XTAL            (12000000U)       /* Oscillator frequency */
43
44 #define SYSTEM_CLOCK    (5 * XTAL)
45
46
47 /*---------------------------------------------------------------------------
48   Exception / Interrupt Vector table
49  *---------------------------------------------------------------------------*/
50 extern const VECTOR_TABLE_Type __VECTOR_TABLE[496];
51
52
53 /*---------------------------------------------------------------------------
54   System Core Clock Variable
55  *---------------------------------------------------------------------------*/
56 /* ToDo: Initialize SystemCoreClock with the system core clock frequency value
57          achieved after system intitialization.
58          This means system core clock frequency after call to SystemInit() */
59 uint32_t SystemCoreClock = SYSTEM_CLOCK;  /* System Clock Frequency (Core Clock)*/
60
61
62 /*---------------------------------------------------------------------------
63   System Core Clock function
64  *---------------------------------------------------------------------------*/
65 void SystemCoreClockUpdate (void)
66 {
67 /* ToDo: Add code to calculate the system frequency based upon the current
68          register settings.
69          This function can be used to retrieve the system core clock frequeny
70          after user changed register sittings. */
71   SystemCoreClock = SYSTEM_CLOCK;
72 }
73
74
75 /*---------------------------------------------------------------------------
76   System initialization function
77  *---------------------------------------------------------------------------*/
78 void SystemInit (void)
79 {
80 /* ToDo: Add code to initialize the system.
81          Do not use global variables because this function is called before
82          reaching pre-main. RW section maybe overwritten afterwards. */
83
84 /* ToDo: Initialize VTOR if available */
85 #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
86   SCB->VTOR = (uint32_t)(&__VECTOR_TABLE[0]);
87 #endif
88
89 /* ToDo: Enable co-processor if it is used */
90 #if (defined (__FPU_USED) && (__FPU_USED == 1U)) || \
91     (defined (__ARM_FEATURE_MVE) && (__ARM_FEATURE_MVE > 0U))
92   SCB->CPACR |= ((3U << 10U*2U) |           /* enable CP10 Full Access */
93                  (3U << 11U*2U)  );         /* enable CP11 Full Access */
94 #endif
95
96 /* ToDo: Initialize SAU if TZ is used */
97 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
98   TZ_SAU_Setup();
99 #endif
100
101   SystemCoreClock = SYSTEM_CLOCK;
102 }