From fb93fa74b821d883e7d19999dfd1a358aacebb88 Mon Sep 17 00:00:00 2001 From: Kshitij Sisodia Date: Thu, 24 Feb 2022 09:51:02 +0000 Subject: MLECO-2944: CMSIS device refactoring * RTE_components header to include corresponding Arm Cortex-M system header * remove custom CMSIS implementation from repo * use templates within CMSIS repo instead * update cmake to use header and source files within CMSIS repo Change-Id: I3534dae97b93c07a5056471b1d1dedbc78f00aa7 --- source/hal/cmsis_device/CMakeLists.txt | 8 +- source/hal/cmsis_device/include/RTE_components.h | 24 +++ source/hal/cmsis_device/include/cmsis.h | 33 ---- source/hal/cmsis_device/include/irqs.h | 39 ---- source/hal/cmsis_device/source/cmsis.c | 100 ---------- source/hal/cmsis_device/source/irqs.c | 216 --------------------- source/hal/include/hal.h | 1 + .../hal/platform/mps3/include/platform_drivers.h | 2 +- source/hal/platform/mps3/source/include/smm_mps3.h | 2 +- .../hal/platform/simple/include/platform_drivers.h | 2 +- .../simple/include/timer_simple_platform.h | 2 + .../platform/simple/source/timer_simple_platform.c | 2 +- 12 files changed, 37 insertions(+), 394 deletions(-) create mode 100644 source/hal/cmsis_device/include/RTE_components.h delete mode 100644 source/hal/cmsis_device/include/cmsis.h delete mode 100644 source/hal/cmsis_device/include/irqs.h delete mode 100644 source/hal/cmsis_device/source/cmsis.c delete mode 100644 source/hal/cmsis_device/source/irqs.c (limited to 'source') diff --git a/source/hal/cmsis_device/CMakeLists.txt b/source/hal/cmsis_device/CMakeLists.txt index 9f834d5..255bd30 100644 --- a/source/hal/cmsis_device/CMakeLists.txt +++ b/source/hal/cmsis_device/CMakeLists.txt @@ -50,8 +50,12 @@ target_include_directories(${CMSIS_DEVICE_TARGET} ## Sources target_sources(${CMSIS_DEVICE_TARGET} PRIVATE - source/cmsis.c - source/irqs.c) + ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c + ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c) + +# Device definition needs to be set, is checked in source files to include correct header +target_compile_definitions(${CMSIS_DEVICE_TARGET} PUBLIC ${ARM_CPU}) + # Tell linker that reset interrupt handler is our entry point target_link_options( diff --git a/source/hal/cmsis_device/include/RTE_components.h b/source/hal/cmsis_device/include/RTE_components.h new file mode 100644 index 0000000..8988e9b --- /dev/null +++ b/source/hal/cmsis_device/include/RTE_components.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef RTE_COMPONENTS_H +#define RTE_COMPONENTS_H + +#if defined(CPU_HEADER_FILE) +#include CPU_HEADER_FILE /* Cortex M system header file from CMSIS. */ +#endif /* CPU_HEADER_FILE */ + +#endif /* RTE_COMPONENTS_H */ diff --git a/source/hal/cmsis_device/include/cmsis.h b/source/hal/cmsis_device/include/cmsis.h deleted file mode 100644 index 9d6326a..0000000 --- a/source/hal/cmsis_device/include/cmsis.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2021 Arm Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef BAREMETAL_CMSIS_H -#define BAREMETAL_CMSIS_H - -#if defined(CPU_HEADER_FILE) -#include CPU_HEADER_FILE /* Cortex M system header file from CMSIS. */ -#endif /* CPU_HEADER_FILE */ -#include "irqs.h" /* Interrupt definitions file. */ - -/* Addition to template functions should be mentioned here. */ - -/** - * @brief Gets the internal processor clock. - * @return Clock frequency as unsigned 32 bit value. - **/ -uint32_t GetSystemCoreClock(void); - -#endif /* BAREMETAL_CMSIS_H */ diff --git a/source/hal/cmsis_device/include/irqs.h b/source/hal/cmsis_device/include/irqs.h deleted file mode 100644 index 234edd7..0000000 --- a/source/hal/cmsis_device/include/irqs.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Arm Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef IRQS_H -#define IRQS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* Interrupt handler function type. */ -typedef void (*const irq_vec_type)(void); - -/** - * @brief Reset interrupt handler and also, the starting - * point of the application. - **/ -extern void Reset_Handler(void); - -#ifdef __cplusplus -} -#endif - -#endif /* IRQS_H */ diff --git a/source/hal/cmsis_device/source/cmsis.c b/source/hal/cmsis_device/source/cmsis.c deleted file mode 100644 index 9cf6213..0000000 --- a/source/hal/cmsis_device/source/cmsis.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2021 Arm Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "cmsis.h" - -extern void *__Vectors; /* see irqs.c */ - -/*----------------------------------------------------------------------------*\ - * Define clocks (uses OSC1 ACLK) * -\*----------------------------------------------------------------------------*/ -#define __XTAL (32000000) /* Oscillator frequency */ -#define __SYSTEM_CLOCK (__XTAL) - -#if defined(CPU_CORTEX_M55) -#define CCR_DL (1 << 19) -#else -#error "Invalid CPU; This file only services Cortex-M55 CPUs" -#endif /* (CPU_CORTEX_M55) */ - -/*---------------------------------------------------------------------------- - System Core Clock Variable (Core Clock) - *----------------------------------------------------------------------------*/ -uint32_t SystemCoreClock = __SYSTEM_CLOCK; - - -/*---------------------------------------------------------------------------- - Clock functions - *----------------------------------------------------------------------------*/ -/** - * @brief Updates the SystemCoreClock variable with current core Clock - * retrieved from cpu registers. - */ -void SystemCoreClockUpdate(void) -{ - /* Update the SystemCoreClock variable */ - SystemCoreClock = __SYSTEM_CLOCK; -} - -uint32_t GetSystemCoreClock(void) -{ - return SystemCoreClock; -} - -/** - * @brief Setup the microcontroller system. - * Initialize the System. - **/ -void SystemInit(void) -{ -#if (defined (__FPU_USED) && (__FPU_USED == 1U)) || \ - (defined (__MVE_USED) && (__MVE_USED == 1U)) - SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ - (3U << 11U*2U) ); -#endif - -#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) - SCB->VTOR = (uint32_t) &__Vectors; -#endif - - /* Enable hard, bus, mem and usage fault detection in SHCSR, bits 16-18. - * Enable stkof, bf, div_0_trp, unalign_trp and usersetm bits in CCR. - */ - SCB->SHCSR = ( - _VAL2FLD(SCB_SHCSR_USGFAULTENA, 1) | - _VAL2FLD(SCB_SHCSR_BUSFAULTENA, 1) | - _VAL2FLD(SCB_SHCSR_MEMFAULTENA, 1)); - - SCB->CCR = (_VAL2FLD(SCB_CCR_USERSETMPEND, 1) | - _VAL2FLD(SCB_CCR_DIV_0_TRP, 1) | - _VAL2FLD(SCB_CCR_BFHFNMIGN, 1) | - _VAL2FLD(SCB_CCR_STKOFHFNMIGN, 1)); -#ifdef UNALIGNED_SUPPORT_DISABLE - SCB->CCR |= _VAL2FLD(SCB_CCR_UNALIGN_TRP, 1); -#endif - - SCB->CCR |= CCR_DL; - - /* Reset pipeline. */ - __DSB(); - __ISB(); - -#ifdef UNALIGNED_SUPPORT_DISABLE - SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; -#endif - - SystemCoreClock = __SYSTEM_CLOCK; -} diff --git a/source/hal/cmsis_device/source/irqs.c b/source/hal/cmsis_device/source/irqs.c deleted file mode 100644 index 2ecd4d5..0000000 --- a/source/hal/cmsis_device/source/irqs.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2021 Arm Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "irqs.h" -#include "cmsis.h" - -#include -#include - -/** - * External references - */ -extern uint32_t __INITIAL_SP; -extern uint32_t __STACK_LIMIT; - -#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) - extern uint32_t __STACK_SEAL; -#endif - -extern __NO_RETURN void __PROGRAM_START(void); - -/** - * @brief Dump core registers on stdout - */ -static void LogCoreCPURegisters(void) -{ - printf("CTRL : 0x%08" PRIx32 "\n", __get_CONTROL()); - printf("IPSR : 0x%08" PRIx32 "\n", __get_IPSR()); - printf("APSR : 0x%08" PRIx32 "\n", __get_APSR()); - printf("xPSR : 0x%08" PRIx32 "\n", __get_xPSR()); - printf("PSP : 0x%08" PRIx32 "\n", __get_PSP()); - printf("MSP : 0x%08" PRIx32 "\n", __get_MSP()); - printf("PRIMASK : 0x%08" PRIx32 "\n", __get_PRIMASK()); - printf("BASEPRI : 0x%08" PRIx32 "\n", __get_BASEPRI()); - printf("FAULTMSK: 0x%08" PRIx32 "\n", __get_FAULTMASK()); -} - -/** - * @brief Default interrupt handler - an infinite loop. - **/ -__attribute__((noreturn)) static void DefaultHandler(void) -{ - LogCoreCPURegisters(); - while (1) { - /* Without the following line, armclang may optimize away the - * infinite loop because it'd be without side effects and thus - * undefined behaviour. */ - __ASM volatile(""); - } -} - -#define DEFAULT_HANDLER_CALL(type) \ - do { \ - printf("\n"); \ - printf("%s caught by function %s\n", \ - type, __FUNCTION__); \ - DefaultHandler(); \ - } while (0) - -#define DEFAULT_ERROR_HANDLER_CALL() \ - DEFAULT_HANDLER_CALL("Exception") - -#define DEFAULT_IRQ_HANDLER_CALL() \ - DEFAULT_HANDLER_CALL("Interrupt") - -/** - * Dummy Exception Handlers for core interrupts. - * - * Weak definitions provided to be used if the user chooses not - * to override them. - **/ - -/** - * @brief Non maskable interrupt handler. - **/ - __attribute__((weak)) void NMI_Handler(void) -{ - DEFAULT_ERROR_HANDLER_CALL(); -} - -/** - * @brief Hardfault interrupt handler. - **/ - __attribute__((weak)) void HardFault_Handler(void) -{ - DEFAULT_ERROR_HANDLER_CALL(); -} - -/** - * @brief Memory management interrupt handler. - **/ -__attribute__((weak)) void MemManage_Handler(void) -{ - DEFAULT_IRQ_HANDLER_CALL(); -} - -/** - * @brief Bus fault interrupt handler. - **/ -__attribute__((weak)) void BusFault_Handler(void) -{ - DEFAULT_ERROR_HANDLER_CALL(); -} - -/** - * @brief Usage fault interrupt handler. - **/ -__attribute__((weak)) void UsageFault_Handler(void) -{ - DEFAULT_ERROR_HANDLER_CALL(); -} - -/** - * @brief Secure access fault interrupt handler. - **/ -__attribute__((weak)) void SecureFault_Handler(void) -{ - DEFAULT_ERROR_HANDLER_CALL(); -} - -/** - * @brief Supervisor call interrupt handler. - **/ -__attribute__((weak)) void SVC_Handler(void) -{ - DEFAULT_IRQ_HANDLER_CALL(); -} - -/** - * @brief Debug monitor interrupt handler. - **/ -__attribute__((weak)) void DebugMon_Handler(void) -{ - DEFAULT_IRQ_HANDLER_CALL(); -} - -/** - * @brief Pending SV call interrupt handler. - */ -__attribute__((weak)) void PendSV_Handler(void) -{ - DEFAULT_IRQ_HANDLER_CALL(); -} - -/** - * @brief System tick interrupt handler. - **/ -__attribute__((weak)) void SysTick_Handler(void) -{ - DEFAULT_IRQ_HANDLER_CALL(); -} - -/** - * Interrupt vector table. - */ -irq_vec_type __VECTOR_TABLE[] __VECTOR_TABLE_ATTRIBUTE = { - (irq_vec_type)(&__INITIAL_SP), /* Initial Stack Pointer */ - Reset_Handler , /* 1 Initial PC, set to entry point */ - - NMI_Handler , /* 2 (-14) NMI Handler */ - HardFault_Handler , /* 3 (-13) Hard Fault Handler */ - MemManage_Handler , /* 4 (-12) MPU Fault Handler */ - BusFault_Handler , /* 5 (-11) Bus Fault Handler */ - UsageFault_Handler , /* 6 (-10) Usage Fault Handler */ - SecureFault_Handler, /* 7 ( -9) Secure Fault Handler */ - 0 , /* 8 ( -8) Reserved */ - 0 , /* 9 ( -7) Reserved */ - 0 , /* 10 ( -6) Reserved */ - SVC_Handler , /* 11 ( -5) SVCall Handler */ - DebugMon_Handler , /* 12 ( -4) Debug Monitor Handler */ - 0 , /* 13 ( -3) Reserved */ - PendSV_Handler , /* 14 ( -2) PendSV Handler */ - SysTick_Handler , /* 15 ( -1) SysTick Handler */ - - /* External sources to be populated by user. */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - 16 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16 - 32 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 32 - 48 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 48 - 64 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 64 - 80 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 96 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 96 - 112 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 112 - 128 */ -}; - -/* Reset handler - starting point of our application. */ -__attribute__((used)) void Reset_Handler(void) -{ - /* Initialise system. */ - SystemInit(); - - /* cmsis supplied entry point. */ - __PROGRAM_START(); -} - -#ifdef __cplusplus -} -#endif diff --git a/source/hal/include/hal.h b/source/hal/include/hal.h index a535dc9..6335e6d 100644 --- a/source/hal/include/hal.h +++ b/source/hal/include/hal.h @@ -28,6 +28,7 @@ extern "C" { #endif +#include "platform_drivers.h" /* Platform drivers */ #include "data_acq.h" /* Data acquisition abstraction */ #include "data_psn.h" /* Data presentation abstraction */ #include "timer.h" /* Timer/profiler API */ diff --git a/source/hal/platform/mps3/include/platform_drivers.h b/source/hal/platform/mps3/include/platform_drivers.h index 156b136..da3af1e 100644 --- a/source/hal/platform/mps3/include/platform_drivers.h +++ b/source/hal/platform/mps3/include/platform_drivers.h @@ -22,7 +22,7 @@ /* Platform components */ #include "timer_mps3.h" /* Timer functions. */ -#include "cmsis.h" /* For CPU related defintiions */ +#include "RTE_components.h" /* For CPU related defintiions */ #include "glcd_mps3.h" /* LCD functions. */ /** Platform definitions. TODO: These should be removed. */ diff --git a/source/hal/platform/mps3/source/include/smm_mps3.h b/source/hal/platform/mps3/source/include/smm_mps3.h index 5a2bcc5..9e848e4 100644 --- a/source/hal/platform/mps3/source/include/smm_mps3.h +++ b/source/hal/platform/mps3/source/include/smm_mps3.h @@ -17,9 +17,9 @@ #ifndef SMM_MPS3_H #define SMM_MPS3_H -#include "cmsis.h" /* For CPU related defintiions */ #include "peripheral_memmap.h" /* Peripheral memory map definitions. */ +#include "RTE_components.h" #if defined ( __CC_ARM ) #pragma anon_unions diff --git a/source/hal/platform/simple/include/platform_drivers.h b/source/hal/platform/simple/include/platform_drivers.h index c9928c0..4140f76 100644 --- a/source/hal/platform/simple/include/platform_drivers.h +++ b/source/hal/platform/simple/include/platform_drivers.h @@ -23,7 +23,7 @@ /* Platform components */ #include "stubs/glcd.h" /* LCD stubs to support use cases that use LCD */ #include "timer_simple_platform.h" /* timer implementation */ -#include "cmsis.h" /* For CPU related defintiions */ +#include "RTE_components.h" /* For CPU related defintiions */ /** Platform definitions. TODO: These should be removed. */ #include "peripheral_memmap.h" /* Peripheral memory map definitions. */ diff --git a/source/hal/platform/simple/include/timer_simple_platform.h b/source/hal/platform/simple/include/timer_simple_platform.h index 4df22da..5f3c26b 100644 --- a/source/hal/platform/simple/include/timer_simple_platform.h +++ b/source/hal/platform/simple/include/timer_simple_platform.h @@ -18,6 +18,8 @@ #define TIMER_SIMPLE_PLATFORM_H #include +#include "RTE_components.h" + /* Container for timestamp for simple platform. */ typedef struct _generic_time_counter { uint64_t counter_systick; diff --git a/source/hal/platform/simple/source/timer_simple_platform.c b/source/hal/platform/simple/source/timer_simple_platform.c index 3d28261..b1f3194 100644 --- a/source/hal/platform/simple/source/timer_simple_platform.c +++ b/source/hal/platform/simple/source/timer_simple_platform.c @@ -17,7 +17,7 @@ #include "timer_simple_platform.h" #include "log_macros.h" /* Logging macros */ -#include "cmsis.h" /* For CPU related defintiions */ +#include "RTE_components.h" /* For CPU related defintiions */ #include -- cgit v1.2.1