From 7d3b2af9c791c169834bc314a20bcc942399fb25 Mon Sep 17 00:00:00 2001 From: Martin Kojtal <0xc0170@gmail.com> Date: Wed, 7 Jun 2017 11:35:28 +0100 Subject: [PATCH 1/2] mbed sdk boot: default nvic implementation Latest cmsis files provide virtual nvic implementation, therefore all nvic set/get vectors were removed. As the result, we did not reallocate vectors for mbed SDK. This should fix it for most of the platforms (cortex m0 and cortex a9 need to provide own if they need it). --- platform/mbed_sdk_boot.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/platform/mbed_sdk_boot.c b/platform/mbed_sdk_boot.c index 5b7e6eae0bb..de6add221cd 100644 --- a/platform/mbed_sdk_boot.c +++ b/platform/mbed_sdk_boot.c @@ -17,6 +17,7 @@ #include "mbed_toolchain.h" #include #include +#include "cmsis.h" /* This startup is for mbed 2 baremetal. There is no config for RTOS for mbed 2, * therefore we protect this file with MBED_CONF_RTOS_PRESENT @@ -46,6 +47,24 @@ MBED_WEAK void software_init_hook_rtos() // Nothing by default } +void mbed_copy_nvic(void) +{ + /* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have + VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is + responsible for correctly handling the vectors. + */ +#if !defined(__CORTEX_M0) && !defined(__CORTEX_A9) +#ifdef NVIC_RAM_VECTOR_ADDRESS + uint32_t *old_vectors = (uint32_t *)SCB->VTOR; + uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; + for (int i = 0; i < NVIC_NUM_VECTORS; i++) { + vectors[i] = old_vectors[i]; + } + SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS; +#endif /* NVIC_RAM_VECTOR_ADDRESS */ +#endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */ +} + /* Toolchain specific main code */ #if defined (__CC_ARM) @@ -60,6 +79,7 @@ int $Sub$$main(void) void _platform_post_stackheap_init(void) { + mbed_copy_nvic(); mbed_sdk_init(); } @@ -69,6 +89,7 @@ extern int __real_main(void); void software_init_hook(void) { + mbed_copy_nvic(); mbed_sdk_init(); software_init_hook_rtos(); } @@ -82,7 +103,11 @@ int __wrap_main(void) #elif defined (__ICCARM__) -// cmsis.S file implements the mbed SDK boot for IAR +int __low_level_init(void) +{ + mbed_copy_nvic(); + return 1; +} #endif From 278634a1f68765681f4e4c4fc669c2f9892cf17c Mon Sep 17 00:00:00 2001 From: Martin Kojtal <0xc0170@gmail.com> Date: Thu, 8 Jun 2017 15:45:29 +0100 Subject: [PATCH 2/2] tools: mbed sdk boot should be separate object file This was probably deleted during the rebase, as mbed sdk boot needs to be own object file due to using weak functions. --- tools/build_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_api.py b/tools/build_api.py index f8385f95c4c..c9e288dae70 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -1061,7 +1061,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False, # weak SDK functions # - mbed_main.o: this contains main redirection separate_names, separate_objects = ['mbed_retarget.o', 'mbed_board.o', - 'mbed_overrides.o', 'mbed_main.o'], [] + 'mbed_overrides.o', 'mbed_main.o', 'mbed_sdk_boot.o'], [] for obj in objects: for name in separate_names: