blob: 5de41c28f5840a8ac2054b93c60a7efe78c82c10 [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 "log_macros.h" /* Logging functions */
Kshitij Sisodiaacc6b852022-03-01 10:23:11 +000021#include "uart_stdout.h" /* stdout over UART. */
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000022#include "smm_mps3.h" /* Memory map for MPS3. */
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000023
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000024#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
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000029#if defined(ETHOS_U_NPU_TIMING_ADAPTER_ENABLED)
Isabella Gottardiee4920b2022-02-25 14:29:32 +000030#include "ethosu_ta_init.h"
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000031#endif /* ETHOS_U_NPU_TIMING_ADAPTER_ENABLED */
Isabella Gottardiee4920b2022-02-25 14:29:32 +000032
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
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000059#if defined(ETHOS_U_NPU_TIMING_ADAPTER_ENABLED)
Isabella Gottardiee4920b2022-02-25 14:29:32 +000060 /* If the platform has timing adapter blocks along with Ethos-U core
61 * block, initialise them here. */
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000062 if (0 != (err = arm_ethosu_timing_adapter_init())) {
Isabella Gottardiee4920b2022-02-25 14:29:32 +000063 return err;
64 }
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000065#endif /* ETHOS_U_NPU_TIMING_ADAPTER_ENABLED */
Isabella Gottardiee4920b2022-02-25 14:29:32 +000066
67 int state;
68
69 /* If Arm Ethos-U NPU is to be used, we initialise it here */
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000070 if (0 != (state = arm_ethosu_npu_init())) {
Isabella Gottardiee4920b2022-02-25 14:29:32 +000071 return state;
72 }
73
74#endif /* ARM_NPU */
75
76 /* Print target design info */
77 info("Target system design: %s\n", DESIGN_NAME);
78
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000079 return 0;
80}
81
82void platform_release(void)
83{
84 __disable_irq();
85}
86
87void platform_name(char* name, size_t size)
88{
89 strncpy(name, DESIGN_NAME, size);
90}
91
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010092#define CREATE_MASK(msb, lsb) (int)(((1U << ((msb) - (lsb) + 1)) - 1) << (lsb))
93#define MASK_BITS(arg, msb, lsb) (int)((arg) & CREATE_MASK(msb, lsb))
94#define EXTRACT_BITS(arg, msb, lsb) (int)(MASK_BITS(arg, msb, lsb) >> (lsb))
alexander3c798932021-03-26 21:42:19 +000095
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000096static int verify_platform(void)
alexander3c798932021-03-26 21:42:19 +000097{
alexander3c798932021-03-26 21:42:19 +000098 uint32_t id = 0;
99 uint32_t fpgaid = 0;
100 uint32_t apnote = 0;
101 uint32_t rev = 0;
102 uint32_t aid = 0;
103 uint32_t fpga_clk = 0;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100104 const uint32_t ascii_A = (uint32_t)('A');
alexander3c798932021-03-26 21:42:19 +0000105
106 /* Initialise the LEDs as the switches are */
107 MPS3_FPGAIO->LED = MPS3_FPGAIO->SWITCHES & 0xFF;
alexander3c798932021-03-26 21:42:19 +0000108
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000109 info("Processor internal clock: %" PRIu32 "Hz\n", get_mps3_core_clock());
alexander3c798932021-03-26 21:42:19 +0000110
alexander3c798932021-03-26 21:42:19 +0000111 /* Get revision information from various registers */
112 rev = MPS3_SCC->CFG_REG4;
113 fpgaid = MPS3_SCC->SCC_ID;
114 aid = MPS3_SCC->SCC_AID;
115 apnote = EXTRACT_BITS(fpgaid, 15, 4);
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000116 fpga_clk = get_mps3_core_clock();
alexander3c798932021-03-26 21:42:19 +0000117
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100118 info("V2M-MPS3 revision %c\n\n", (char)(rev + ascii_A));
119 info("Application Note AN%" PRIx32 ", Revision %c\n", apnote,
120 (char)(EXTRACT_BITS(aid, 23, 20) + ascii_A));
alexander3c798932021-03-26 21:42:19 +0000121 info("MPS3 build %d\n", EXTRACT_BITS(aid, 31, 24));
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100122 info("MPS3 core clock has been set to: %" PRIu32 "Hz\n", fpga_clk);
alexander3c798932021-03-26 21:42:19 +0000123
124 /* Display CPU ID */
125 id = SCB->CPUID;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100126 info("CPU ID: 0x%08" PRIx32 "\n", id);
alexander3c798932021-03-26 21:42:19 +0000127
128 if(EXTRACT_BITS(id, 15, 8) == 0xD2) {
129 if (EXTRACT_BITS(id, 7, 4) == 2) {
130 info ("CPU: Cortex-M55 r%dp%d\n\n",
131 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
132#if defined (CPU_CORTEX_M55)
133 /* CPU ID should be "0x_41_0f_d2_20" for Cortex-M55 */
134 return 0;
135#endif /* CPU_CORTEX_M55 */
136 } else if (EXTRACT_BITS(id, 7, 4) == 1) {
137 info ("CPU: Cortex-M33 r%dp%d\n\n",
138 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
139#if defined (CPU_CORTEX_M33)
140 return 0;
141#endif /* CPU_CORTEX_M33 */
142 } else if (EXTRACT_BITS(id, 7, 4) == 0) {
143 info ("CPU: Cortex-M23 r%dp%d\n\n",
144 EXTRACT_BITS(id, 23, 20),EXTRACT_BITS(id, 3, 0));
145 } else {
146 info ("CPU: Cortex-M processor family");
147 }
148 } else if (EXTRACT_BITS(id, 15, 8) == 0xC6) {
149 info ("CPU: Cortex-M%d+ r%dp%d\n\n",
150 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
151 EXTRACT_BITS(id, 3, 0));
152 } else {
153 info ("CPU: Cortex-M%d r%dp%d\n\n",
154 EXTRACT_BITS(id, 7, 4), EXTRACT_BITS(id, 23, 20),
155 EXTRACT_BITS(id, 3, 0));
156 }
alexander3c798932021-03-26 21:42:19 +0000157
158 /* If the CPU is anything other than M33 or M55, we return 1 */
159 printf_err("CPU mismatch!\n");
160 return 1;
161}