Skip to content

NANO130: Fix optimization error with NVIC_SetVector/NVIC_GetVector on ARMC6 #10534

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region IRAM_region = mem:[from __ICFEDIT_region_IRAM_start__ to __ICFEDIT_region_IRAM_end__];

define block ROMVEC with alignment = 8 { readonly section .intvec };
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };


initialize by copy { readwrite };
do not initialize { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place at address mem:__ICFEDIT_intvec_start__ { block ROMVEC };

place in ROM_region { readonly };
place at start of IRAM_region { block CSTACK };
Expand Down
24 changes: 16 additions & 8 deletions targets/TARGET_NUVOTON/TARGET_NANO100/device/cmsis_nvic.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@
#define NVIC_USER_IRQ_NUMBER 32
#define NVIC_NUM_VECTORS (NVIC_USER_IRQ_OFFSET + NVIC_USER_IRQ_NUMBER)

#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
# define NVIC_RAM_VECTOR_ADDRESS ((uint32_t) &Image$$ER_IRAMVEC$$ZI$$Base)
/* Avoid optimization error on e.g. ARMC6
*
* If NVIC_FLASH_VECTOR_ADDRESS is directly defined as 0, the compiler would see it
* as NULL, and deliberately optimize NVIC_GetVector to an undefined instruction -
* trapping because we're accessing an array at NULL.
*
* A suggested solution by Arm is to define NVIC_FLASH_VECTOR_ADDRESS as a symbol
* instead to avoid such unwanted optimization.
*/
#if defined(__ARMCC_VERSION)
extern uint32_t Image$$ER_IROM1$$Base;
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t) &Image$$ER_IROM1$$Base)
#elif defined(__ICCARM__)
# pragma section = "IRAMVEC"
# define NVIC_RAM_VECTOR_ADDRESS ((uint32_t) __section_begin("IRAMVEC"))
#pragma section = "ROMVEC"
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t) __section_begin("ROMVEC"))
#elif defined(__GNUC__)
# define NVIC_RAM_VECTOR_ADDRESS ((uint32_t) &__start_vector_table__)
extern uint32_t __vector_table;
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t) &__vector_table)
#endif


#define NVIC_FLASH_VECTOR_ADDRESS 0

#ifdef __cplusplus
extern "C" {
#endif
Expand Down