blob: 23af14fd231134e8fb853f13f8d2beea3896a299 [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 "system_init.h"
18
alexander3c798932021-03-26 21:42:19 +000019#include <string.h>
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010020#include <inttypes.h>
alexander3c798932021-03-26 21:42:19 +000021
22#if defined(MPS3_PLATFORM)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010023#define CREATE_MASK(msb, lsb) (int)(((1U << ((msb) - (lsb) + 1)) - 1) << (lsb))
24#define MASK_BITS(arg, msb, lsb) (int)((arg) & CREATE_MASK(msb, lsb))
25#define EXTRACT_BITS(arg, msb, lsb) (int)(MASK_BITS(arg, msb, lsb) >> (lsb))
alexander3c798932021-03-26 21:42:19 +000026#endif /* MPS3_PLATFORM */
27
28int system_init(void)
29{
30#if defined(MPS3_PLATFORM)
31 uint32_t id = 0;
32 uint32_t fpgaid = 0;
33 uint32_t apnote = 0;
34 uint32_t rev = 0;
35 uint32_t aid = 0;
36 uint32_t fpga_clk = 0;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010037 const uint32_t ascii_A = (uint32_t)('A');
alexander3c798932021-03-26 21:42:19 +000038
39 /* Initialise the LEDs as the switches are */
40 MPS3_FPGAIO->LED = MPS3_FPGAIO->SWITCHES & 0xFF;
41#endif
42
43 /* UART init - will enable valid use of printf (stdout
44 * re-directed at this UART (UART0) */
45 UartStdOutInit();
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010046 info("Processor internal clock: %" PRIu32 "Hz\n", GetSystemCoreClock());
alexander3c798932021-03-26 21:42:19 +000047
48#if defined(MPS3_PLATFORM)
49 /* Get revision information from various registers */
50 rev = MPS3_SCC->CFG_REG4;
51 fpgaid = MPS3_SCC->SCC_ID;
52 aid = MPS3_SCC->SCC_AID;
53 apnote = EXTRACT_BITS(fpgaid, 15, 4);
54 fpga_clk = GetMPS3CoreClock();
55
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010056 info("V2M-MPS3 revision %c\n\n", (char)(rev + ascii_A));
57 info("Application Note AN%" PRIx32 ", Revision %c\n", apnote,
58 (char)(EXTRACT_BITS(aid, 23, 20) + ascii_A));
alexander3c798932021-03-26 21:42:19 +000059 info("MPS3 build %d\n", EXTRACT_BITS(aid, 31, 24));
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010060 info("MPS3 core clock has been set to: %" PRIu32 "Hz\n", fpga_clk);
alexander3c798932021-03-26 21:42:19 +000061
62 /* Display CPU ID */
63 id = SCB->CPUID;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010064 info("CPU ID: 0x%08" PRIx32 "\n", id);
alexander3c798932021-03-26 21:42:19 +000065
66 if(EXTRACT_BITS(id, 15, 8) == 0xD2) {
67 if (EXTRACT_BITS(id, 7, 4) == 2) {
68 info ("CPU: Cortex-M55 r%dp%d\n\n",
69 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
70#if defined (CPU_CORTEX_M55)
71 /* CPU ID should be "0x_41_0f_d2_20" for Cortex-M55 */
72 return 0;
73#endif /* CPU_CORTEX_M55 */
74 } else if (EXTRACT_BITS(id, 7, 4) == 1) {
75 info ("CPU: Cortex-M33 r%dp%d\n\n",
76 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
77#if defined (CPU_CORTEX_M33)
78 return 0;
79#endif /* CPU_CORTEX_M33 */
80 } else if (EXTRACT_BITS(id, 7, 4) == 0) {
81 info ("CPU: Cortex-M23 r%dp%d\n\n",
82 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
83 } else {
84 info ("CPU: Cortex-M processor family");
85 }
86 } else if (EXTRACT_BITS(id, 15, 8) == 0xC6) {
87 info ("CPU: Cortex-M%d+ r%dp%d\n\n",
88 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
89 EXTRACT_BITS(id, 3, 0));
90 } else {
91 info ("CPU: Cortex-M%d r%dp%d\n\n",
92 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
93 EXTRACT_BITS(id, 3, 0));
94 }
95#else /* MPS3_PLATFORM */
96
Kshitij Sisodia659fcd92021-05-19 10:30:06 +010097 info("%s: complete\n", __FUNCTION__);
alexander3c798932021-03-26 21:42:19 +000098 return 0;
99#endif /* MPS3_PLATFORM */
100
101 /* If the CPU is anything other than M33 or M55, we return 1 */
102 printf_err("CPU mismatch!\n");
103 return 1;
104}
105
106void system_release(void)
107{
108 __disable_irq();
109}
110
111void system_name(char* name, size_t size)
112{
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100113 strncpy(name, DESIGN_NAME, size);
alexander3c798932021-03-26 21:42:19 +0000114}