blob: 3046c12a70433bb9e82ce1fe9ba7fd3c75346eeb [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +00002 * Copyright (c) 2022 Arm Limited. All rights reserved.
alexander3c798932021-03-26 21:42:19 +00003 * 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 */
alexander3c798932021-03-26 21:42:19 +000017
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000018#include "platform_drivers.h"
alexander3c798932021-03-26 21:42:19 +000019
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000020#include "uart_stdout.h" /* stdout over UART. */
21#include "log_macros.h" /* Logging functions */
22#include "device_mps3.h" /* FPGA level definitions and functions. */
23
24#include <string.h> /* For strncpy */
25
Isabella Gottardiee4920b2022-02-25 14:29:32 +000026#if defined(ARM_NPU)
27#include "ethosu_npu_init.h"
28
29#if defined(TIMING_ADAPTER_AVAILABLE)
30#include "ethosu_ta_init.h"
31#endif /* TIMING_ADAPTER_AVAILABLE */
32
33#endif /* ARM_NPU */
34
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000035/**
36 * @brief Checks if the platform is valid by checking
37 * the CPU ID for the FPGA implementation against
38 * the register from the CPU core.
39 * @return 0 if successful, 1 otherwise
40 */
41static int verify_platform(void);
42
43int platform_init(void)
44{
45 int err = 0;
46
47 SystemCoreClockUpdate(); /* From start up code */
48
49 /* UART init - will enable valid use of printf (stdout
50 * re-directed at this UART (UART0) */
51 UartStdOutInit();
52
53 if (0 != (err = verify_platform())) {
54 return err;
55 }
56
Isabella Gottardiee4920b2022-02-25 14:29:32 +000057#if defined(ARM_NPU)
58
59#if defined(TIMING_ADAPTER_AVAILABLE)
60 /* If the platform has timing adapter blocks along with Ethos-U core
61 * block, initialise them here. */
62 if (0 != (err = arm_ethosu_timing_adapter_init()))
63 {
64 return err;
65 }
66#endif /* TIMING_ADAPTER_AVAILABLE */
67
68 int state;
69
70 /* If Arm Ethos-U NPU is to be used, we initialise it here */
71 if (0 != (state = arm_ethosu_npu_init()))
72 {
73 return state;
74 }
75
76#endif /* ARM_NPU */
77
78 /* Print target design info */
79 info("Target system design: %s\n", DESIGN_NAME);
80
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000081 return 0;
82}
83
84void platform_release(void)
85{
86 __disable_irq();
87}
88
89void platform_name(char* name, size_t size)
90{
91 strncpy(name, DESIGN_NAME, size);
92}
93
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010094#define CREATE_MASK(msb, lsb) (int)(((1U << ((msb) - (lsb) + 1)) - 1) << (lsb))
95#define MASK_BITS(arg, msb, lsb) (int)((arg) & CREATE_MASK(msb, lsb))
96#define EXTRACT_BITS(arg, msb, lsb) (int)(MASK_BITS(arg, msb, lsb) >> (lsb))
alexander3c798932021-03-26 21:42:19 +000097
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000098static int verify_platform(void)
alexander3c798932021-03-26 21:42:19 +000099{
alexander3c798932021-03-26 21:42:19 +0000100 uint32_t id = 0;
101 uint32_t fpgaid = 0;
102 uint32_t apnote = 0;
103 uint32_t rev = 0;
104 uint32_t aid = 0;
105 uint32_t fpga_clk = 0;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100106 const uint32_t ascii_A = (uint32_t)('A');
alexander3c798932021-03-26 21:42:19 +0000107
108 /* Initialise the LEDs as the switches are */
109 MPS3_FPGAIO->LED = MPS3_FPGAIO->SWITCHES & 0xFF;
alexander3c798932021-03-26 21:42:19 +0000110
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000111 info("Processor internal clock: %" PRIu32 "Hz\n", GetMPS3CoreClock());
alexander3c798932021-03-26 21:42:19 +0000112
alexander3c798932021-03-26 21:42:19 +0000113 /* Get revision information from various registers */
114 rev = MPS3_SCC->CFG_REG4;
115 fpgaid = MPS3_SCC->SCC_ID;
116 aid = MPS3_SCC->SCC_AID;
117 apnote = EXTRACT_BITS(fpgaid, 15, 4);
118 fpga_clk = GetMPS3CoreClock();
119
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100120 info("V2M-MPS3 revision %c\n\n", (char)(rev + ascii_A));
121 info("Application Note AN%" PRIx32 ", Revision %c\n", apnote,
122 (char)(EXTRACT_BITS(aid, 23, 20) + ascii_A));
alexander3c798932021-03-26 21:42:19 +0000123 info("MPS3 build %d\n", EXTRACT_BITS(aid, 31, 24));
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100124 info("MPS3 core clock has been set to: %" PRIu32 "Hz\n", fpga_clk);
alexander3c798932021-03-26 21:42:19 +0000125
126 /* Display CPU ID */
127 id = SCB->CPUID;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100128 info("CPU ID: 0x%08" PRIx32 "\n", id);
alexander3c798932021-03-26 21:42:19 +0000129
130 if(EXTRACT_BITS(id, 15, 8) == 0xD2) {
131 if (EXTRACT_BITS(id, 7, 4) == 2) {
132 info ("CPU: Cortex-M55 r%dp%d\n\n",
133 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
134#if defined (CPU_CORTEX_M55)
135 /* CPU ID should be "0x_41_0f_d2_20" for Cortex-M55 */
136 return 0;
137#endif /* CPU_CORTEX_M55 */
138 } else if (EXTRACT_BITS(id, 7, 4) == 1) {
139 info ("CPU: Cortex-M33 r%dp%d\n\n",
140 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
141#if defined (CPU_CORTEX_M33)
142 return 0;
143#endif /* CPU_CORTEX_M33 */
144 } else if (EXTRACT_BITS(id, 7, 4) == 0) {
145 info ("CPU: Cortex-M23 r%dp%d\n\n",
146 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
147 } else {
148 info ("CPU: Cortex-M processor family");
149 }
150 } else if (EXTRACT_BITS(id, 15, 8) == 0xC6) {
151 info ("CPU: Cortex-M%d+ r%dp%d\n\n",
152 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
153 EXTRACT_BITS(id, 3, 0));
154 } else {
155 info ("CPU: Cortex-M%d r%dp%d\n\n",
156 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
157 EXTRACT_BITS(id, 3, 0));
158 }
alexander3c798932021-03-26 21:42:19 +0000159
160 /* If the CPU is anything other than M33 or M55, we return 1 */
161 printf_err("CPU mismatch!\n");
162 return 1;
163}