alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022 Arm Limited. All rights reserved. |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 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 | */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 17 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 18 | #include "platform_drivers.h" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 19 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 20 | #include "log_macros.h" /* Logging functions */ |
Kshitij Sisodia | acc6b85 | 2022-03-01 10:23:11 +0000 | [diff] [blame] | 21 | #include "uart_stdout.h" /* stdout over UART. */ |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 22 | #include "smm_mps3.h" /* Memory map for MPS3. */ |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 23 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 24 | #include <string.h> /* For strncpy */ |
| 25 | |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 26 | #if defined(ARM_NPU) |
| 27 | #include "ethosu_npu_init.h" |
| 28 | |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 29 | #if defined(ETHOS_U_NPU_TIMING_ADAPTER_ENABLED) |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 30 | #include "ethosu_ta_init.h" |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 31 | #endif /* ETHOS_U_NPU_TIMING_ADAPTER_ENABLED */ |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 32 | |
| 33 | #endif /* ARM_NPU */ |
| 34 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 35 | /** |
| 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 | */ |
| 41 | static int verify_platform(void); |
| 42 | |
| 43 | int 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 Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 57 | #if defined(ARM_NPU) |
| 58 | |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 59 | #if defined(ETHOS_U_NPU_TIMING_ADAPTER_ENABLED) |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 60 | /* If the platform has timing adapter blocks along with Ethos-U core |
| 61 | * block, initialise them here. */ |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 62 | if (0 != (err = arm_ethosu_timing_adapter_init())) { |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 63 | return err; |
| 64 | } |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 65 | #endif /* ETHOS_U_NPU_TIMING_ADAPTER_ENABLED */ |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 66 | |
| 67 | int state; |
| 68 | |
| 69 | /* If Arm Ethos-U NPU is to be used, we initialise it here */ |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 70 | if (0 != (state = arm_ethosu_npu_init())) { |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 71 | 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 Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | void platform_release(void) |
| 83 | { |
| 84 | __disable_irq(); |
| 85 | } |
| 86 | |
| 87 | void platform_name(char* name, size_t size) |
| 88 | { |
| 89 | strncpy(name, DESIGN_NAME, size); |
| 90 | } |
| 91 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 92 | #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)) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 95 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 96 | static int verify_platform(void) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 97 | { |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 98 | 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 Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 104 | const uint32_t ascii_A = (uint32_t)('A'); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 105 | |
| 106 | /* Initialise the LEDs as the switches are */ |
| 107 | MPS3_FPGAIO->LED = MPS3_FPGAIO->SWITCHES & 0xFF; |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 108 | |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 109 | info("Processor internal clock: %" PRIu32 "Hz\n", get_mps3_core_clock()); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 110 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 111 | /* 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 Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 116 | fpga_clk = get_mps3_core_clock(); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 117 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 118 | 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)); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 121 | info("MPS3 build %d\n", EXTRACT_BITS(aid, 31, 24)); |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 122 | info("MPS3 core clock has been set to: %" PRIu32 "Hz\n", fpga_clk); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 123 | |
| 124 | /* Display CPU ID */ |
| 125 | id = SCB->CPUID; |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 126 | info("CPU ID: 0x%08" PRIx32 "\n", id); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 127 | |
| 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 | } |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 157 | |
| 158 | /* If the CPU is anything other than M33 or M55, we return 1 */ |
| 159 | printf_err("CPU mismatch!\n"); |
| 160 | return 1; |
| 161 | } |