Skip to content

Commit 7d3b2af

Browse files
0xc0170c1728p9
authored andcommitted
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).
1 parent 1afb23b commit 7d3b2af

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

platform/mbed_sdk_boot.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mbed_toolchain.h"
1818
#include <stdlib.h>
1919
#include <stdint.h>
20+
#include "cmsis.h"
2021

2122
/* This startup is for mbed 2 baremetal. There is no config for RTOS for mbed 2,
2223
* therefore we protect this file with MBED_CONF_RTOS_PRESENT
@@ -46,6 +47,24 @@ MBED_WEAK void software_init_hook_rtos()
4647
// Nothing by default
4748
}
4849

50+
void mbed_copy_nvic(void)
51+
{
52+
/* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have
53+
VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is
54+
responsible for correctly handling the vectors.
55+
*/
56+
#if !defined(__CORTEX_M0) && !defined(__CORTEX_A9)
57+
#ifdef NVIC_RAM_VECTOR_ADDRESS
58+
uint32_t *old_vectors = (uint32_t *)SCB->VTOR;
59+
uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
60+
for (int i = 0; i < NVIC_NUM_VECTORS; i++) {
61+
vectors[i] = old_vectors[i];
62+
}
63+
SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
64+
#endif /* NVIC_RAM_VECTOR_ADDRESS */
65+
#endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */
66+
}
67+
4968
/* Toolchain specific main code */
5069

5170
#if defined (__CC_ARM)
@@ -60,6 +79,7 @@ int $Sub$$main(void)
6079

6180
void _platform_post_stackheap_init(void)
6281
{
82+
mbed_copy_nvic();
6383
mbed_sdk_init();
6484
}
6585

@@ -69,6 +89,7 @@ extern int __real_main(void);
6989

7090
void software_init_hook(void)
7191
{
92+
mbed_copy_nvic();
7293
mbed_sdk_init();
7394
software_init_hook_rtos();
7495
}
@@ -82,7 +103,11 @@ int __wrap_main(void)
82103

83104
#elif defined (__ICCARM__)
84105

85-
// cmsis.S file implements the mbed SDK boot for IAR
106+
int __low_level_init(void)
107+
{
108+
mbed_copy_nvic();
109+
return 1;
110+
}
86111

87112
#endif
88113

0 commit comments

Comments
 (0)