17
17
#include "mbed_toolchain.h"
18
18
#include <stdlib.h>
19
19
#include <stdint.h>
20
+ #include "cmsis.h"
20
21
21
22
/* This startup is for mbed 2 baremetal. There is no config for RTOS for mbed 2,
22
23
* therefore we protect this file with MBED_CONF_RTOS_PRESENT
@@ -46,6 +47,24 @@ MBED_WEAK void software_init_hook_rtos()
46
47
// Nothing by default
47
48
}
48
49
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
+
49
68
/* Toolchain specific main code */
50
69
51
70
#if defined (__CC_ARM )
@@ -60,6 +79,7 @@ int $Sub$$main(void)
60
79
61
80
void _platform_post_stackheap_init (void )
62
81
{
82
+ mbed_copy_nvic ();
63
83
mbed_sdk_init ();
64
84
}
65
85
@@ -69,6 +89,7 @@ extern int __real_main(void);
69
89
70
90
void software_init_hook (void )
71
91
{
92
+ mbed_copy_nvic ();
72
93
mbed_sdk_init ();
73
94
software_init_hook_rtos ();
74
95
}
@@ -82,7 +103,11 @@ int __wrap_main(void)
82
103
83
104
#elif defined (__ICCARM__ )
84
105
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
+ }
86
111
87
112
#endif
88
113
0 commit comments