Skip to content

Commit f55a8c3

Browse files
Merge pull request #4503 from 0xc0170/fix_issue_sdk_vectors
mbed sdk boot: copy vectors addition
2 parents e850355 + 278634a commit f55a8c3

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
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

tools/build_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
10611061
# weak SDK functions
10621062
# - mbed_main.o: this contains main redirection
10631063
separate_names, separate_objects = ['mbed_retarget.o', 'mbed_board.o',
1064-
'mbed_overrides.o', 'mbed_main.o'], []
1064+
'mbed_overrides.o', 'mbed_main.o', 'mbed_sdk_boot.o'], []
10651065

10661066
for obj in objects:
10671067
for name in separate_names:

0 commit comments

Comments
 (0)