blob: f95f214d0049ac9b9cfc7139e327754d8ffce217 [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
19#include "uart_stdout.h"
20
21#include <string.h>
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010022#include <inttypes.h>
alexander3c798932021-03-26 21:42:19 +000023
24#if defined(MPS3_PLATFORM)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010025#define CREATE_MASK(msb, lsb) (int)(((1U << ((msb) - (lsb) + 1)) - 1) << (lsb))
26#define MASK_BITS(arg, msb, lsb) (int)((arg) & CREATE_MASK(msb, lsb))
27#define EXTRACT_BITS(arg, msb, lsb) (int)(MASK_BITS(arg, msb, lsb) >> (lsb))
alexander3c798932021-03-26 21:42:19 +000028#endif /* MPS3_PLATFORM */
29
30int system_init(void)
31{
32#if defined(MPS3_PLATFORM)
33 uint32_t id = 0;
34 uint32_t fpgaid = 0;
35 uint32_t apnote = 0;
36 uint32_t rev = 0;
37 uint32_t aid = 0;
38 uint32_t fpga_clk = 0;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010039 const uint32_t ascii_A = (uint32_t)('A');
alexander3c798932021-03-26 21:42:19 +000040
41 /* Initialise the LEDs as the switches are */
42 MPS3_FPGAIO->LED = MPS3_FPGAIO->SWITCHES & 0xFF;
43#endif
44
45 /* UART init - will enable valid use of printf (stdout
46 * re-directed at this UART (UART0) */
47 UartStdOutInit();
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010048 info("Processor internal clock: %" PRIu32 "Hz\n", GetSystemCoreClock());
alexander3c798932021-03-26 21:42:19 +000049
50#if defined(MPS3_PLATFORM)
51 /* Get revision information from various registers */
52 rev = MPS3_SCC->CFG_REG4;
53 fpgaid = MPS3_SCC->SCC_ID;
54 aid = MPS3_SCC->SCC_AID;
55 apnote = EXTRACT_BITS(fpgaid, 15, 4);
56 fpga_clk = GetMPS3CoreClock();
57
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010058 info("V2M-MPS3 revision %c\n\n", (char)(rev + ascii_A));
59 info("Application Note AN%" PRIx32 ", Revision %c\n", apnote,
60 (char)(EXTRACT_BITS(aid, 23, 20) + ascii_A));
alexander3c798932021-03-26 21:42:19 +000061 info("MPS3 build %d\n", EXTRACT_BITS(aid, 31, 24));
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010062 info("MPS3 core clock has been set to: %" PRIu32 "Hz\n", fpga_clk);
alexander3c798932021-03-26 21:42:19 +000063
64 /* Display CPU ID */
65 id = SCB->CPUID;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010066 info("CPU ID: 0x%08" PRIx32 "\n", id);
alexander3c798932021-03-26 21:42:19 +000067
68 if(EXTRACT_BITS(id, 15, 8) == 0xD2) {
69 if (EXTRACT_BITS(id, 7, 4) == 2) {
70 info ("CPU: Cortex-M55 r%dp%d\n\n",
71 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
72#if defined (CPU_CORTEX_M55)
73 /* CPU ID should be "0x_41_0f_d2_20" for Cortex-M55 */
74 return 0;
75#endif /* CPU_CORTEX_M55 */
76 } else if (EXTRACT_BITS(id, 7, 4) == 1) {
77 info ("CPU: Cortex-M33 r%dp%d\n\n",
78 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
79#if defined (CPU_CORTEX_M33)
80 return 0;
81#endif /* CPU_CORTEX_M33 */
82 } else if (EXTRACT_BITS(id, 7, 4) == 0) {
83 info ("CPU: Cortex-M23 r%dp%d\n\n",
84 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
85 } else {
86 info ("CPU: Cortex-M processor family");
87 }
88 } else if (EXTRACT_BITS(id, 15, 8) == 0xC6) {
89 info ("CPU: Cortex-M%d+ r%dp%d\n\n",
90 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
91 EXTRACT_BITS(id, 3, 0));
92 } else {
93 info ("CPU: Cortex-M%d r%dp%d\n\n",
94 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
95 EXTRACT_BITS(id, 3, 0));
96 }
97#else /* MPS3_PLATFORM */
98
99 info("ARM model environment ready..\n");
100 return 0;
101#endif /* MPS3_PLATFORM */
102
103 /* If the CPU is anything other than M33 or M55, we return 1 */
104 printf_err("CPU mismatch!\n");
105 return 1;
106}
107
108void system_release(void)
109{
110 __disable_irq();
111}
112
113void system_name(char* name, size_t size)
114{
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100115 strncpy(name, DESIGN_NAME, size);
alexander3c798932021-03-26 21:42:19 +0000116}