Skip to content

mbed sdk boot: copy vectors addition #4503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion platform/mbed_sdk_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mbed_toolchain.h"
#include <stdlib.h>
#include <stdint.h>
#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
Expand Down Expand Up @@ -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)
Expand All @@ -60,6 +79,7 @@ int $Sub$$main(void)

void _platform_post_stackheap_init(void)
{
mbed_copy_nvic();
mbed_sdk_init();
}

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

void software_init_hook(void)
{
mbed_copy_nvic();
mbed_sdk_init();
software_init_hook_rtos();
}
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tools/build_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down