From c59167c196984ba758bcc06e955923fb5ef3fd03 Mon Sep 17 00:00:00 2001 From: adustm Date: Mon, 14 Dec 2015 11:39:39 +0100 Subject: [PATCH] [STM32F0_all] remove the global variable and use SYSCFG register instead --- .../TARGET_STM32F0/TARGET_DISCO_F051R8/cmsis_nvic.c | 5 +---- .../TARGET_STM32F0/TARGET_DISCO_F051R8/system_stm32f0xx.c | 2 -- .../TARGET_STM32F0/TARGET_NUCLEO_F030R8/cmsis_nvic.c | 4 +--- .../TARGET_STM32F0/TARGET_NUCLEO_F030R8/system_stm32f0xx.c | 2 -- .../TARGET_STM32F0/TARGET_NUCLEO_F031K6/cmsis_nvic.c | 4 +--- .../TARGET_STM32F0/TARGET_NUCLEO_F031K6/system_stm32f0xx.c | 2 -- .../TARGET_STM32F0/TARGET_NUCLEO_F042K6/cmsis_nvic.c | 4 +--- .../TARGET_STM32F0/TARGET_NUCLEO_F042K6/system_stm32f0xx.c | 2 -- .../TARGET_STM32F0/TARGET_NUCLEO_F070RB/cmsis_nvic.c | 4 +--- .../TARGET_STM32F0/TARGET_NUCLEO_F070RB/system_stm32f0xx.c | 2 -- .../TARGET_STM32F0/TARGET_NUCLEO_F072RB/cmsis_nvic.c | 4 +--- .../TARGET_STM32F0/TARGET_NUCLEO_F072RB/system_stm32f0xx.c | 3 --- .../TARGET_STM32F0/TARGET_NUCLEO_F091RC/cmsis_nvic.c | 5 +---- .../TARGET_STM32F0/TARGET_NUCLEO_F091RC/system_stm32f0xx.c | 3 --- 14 files changed, 7 insertions(+), 39 deletions(-) diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/cmsis_nvic.c index 02a8b586c9..a5d638105a 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/cmsis_nvic.c @@ -33,19 +33,16 @@ #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM #define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash -int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done - void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { int i; // Copy and switch to dynamic vectors if first time called - if (NVIC_vtor_remap == 0) { + if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) { uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS; for (i = 0; i < NVIC_NUM_VECTORS; i++) { *((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i]; } SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000 - NVIC_vtor_remap = 1; // The vectors remap is done } // Set the vector diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/system_stm32f0xx.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/system_stm32f0xx.c index 156dd002cf..9a36080acb 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/system_stm32f0xx.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/system_stm32f0xx.c @@ -160,7 +160,6 @@ uint8_t SetSysClock_PLL_HSI(void); * @{ */ -extern int NVIC_vtor_remap; /** * @brief Setup the microcontroller system. @@ -229,7 +228,6 @@ void SystemInit(void) /* Configure the Cube driver */ SystemCoreClock = 8000000; // At this stage the HSI is used as system clock - NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector() HAL_Init(); /* Configure the System clock source, PLL Multiplier and Divider factors, diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/cmsis_nvic.c index 02a8b586c9..2e9e8638bb 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/cmsis_nvic.c @@ -33,19 +33,17 @@ #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM #define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash -int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { int i; // Copy and switch to dynamic vectors if first time called - if (NVIC_vtor_remap == 0) { + if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) { uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS; for (i = 0; i < NVIC_NUM_VECTORS; i++) { *((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i]; } SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000 - NVIC_vtor_remap = 1; // The vectors remap is done } // Set the vector diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/system_stm32f0xx.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/system_stm32f0xx.c index 748845bd5c..b666a3eabe 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/system_stm32f0xx.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/system_stm32f0xx.c @@ -161,7 +161,6 @@ uint8_t SetSysClock_PLL_HSI(void); * @{ */ -extern int NVIC_vtor_remap; /** * @brief Setup the microcontroller system. @@ -230,7 +229,6 @@ void SystemInit(void) /* Configure the Cube driver */ SystemCoreClock = 8000000; // At this stage the HSI is used as system clock - NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector() HAL_Init(); /* Configure the System clock source, PLL Multiplier and Divider factors, diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/cmsis_nvic.c index 02a8b586c9..2e9e8638bb 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/cmsis_nvic.c @@ -33,19 +33,17 @@ #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM #define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash -int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { int i; // Copy and switch to dynamic vectors if first time called - if (NVIC_vtor_remap == 0) { + if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) { uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS; for (i = 0; i < NVIC_NUM_VECTORS; i++) { *((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i]; } SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000 - NVIC_vtor_remap = 1; // The vectors remap is done } // Set the vector diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/system_stm32f0xx.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/system_stm32f0xx.c index 39e52538b3..417c29dec4 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/system_stm32f0xx.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/system_stm32f0xx.c @@ -161,7 +161,6 @@ uint8_t SetSysClock_PLL_HSI(void); * @{ */ -extern int NVIC_vtor_remap; /** * @brief Setup the microcontroller system. @@ -230,7 +229,6 @@ void SystemInit(void) /* Configure the Cube driver */ SystemCoreClock = 8000000; // At this stage the HSI is used as system clock - NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector() HAL_Init(); /* Configure the System clock source, PLL Multiplier and Divider factors, diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/cmsis_nvic.c index 02a8b586c9..2e9e8638bb 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/cmsis_nvic.c @@ -33,19 +33,17 @@ #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM #define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash -int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { int i; // Copy and switch to dynamic vectors if first time called - if (NVIC_vtor_remap == 0) { + if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) { uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS; for (i = 0; i < NVIC_NUM_VECTORS; i++) { *((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i]; } SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000 - NVIC_vtor_remap = 1; // The vectors remap is done } // Set the vector diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/system_stm32f0xx.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/system_stm32f0xx.c index 73d4665fd5..489d6b73e4 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/system_stm32f0xx.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/system_stm32f0xx.c @@ -161,7 +161,6 @@ uint8_t SetSysClock_PLL_HSI(void); * @{ */ -extern int NVIC_vtor_remap; /** * @brief Setup the microcontroller system. @@ -230,7 +229,6 @@ void SystemInit(void) /* Configure the Cube driver */ SystemCoreClock = 8000000; // At this stage the HSI is used as system clock - NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector() HAL_Init(); /* Configure the System clock source, PLL Multiplier and Divider factors, diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/cmsis_nvic.c index 02a8b586c9..2e9e8638bb 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/cmsis_nvic.c @@ -33,19 +33,17 @@ #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM #define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash -int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { int i; // Copy and switch to dynamic vectors if first time called - if (NVIC_vtor_remap == 0) { + if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) { uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS; for (i = 0; i < NVIC_NUM_VECTORS; i++) { *((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i]; } SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000 - NVIC_vtor_remap = 1; // The vectors remap is done } // Set the vector diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/system_stm32f0xx.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/system_stm32f0xx.c index f506c2d407..3575134646 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/system_stm32f0xx.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/system_stm32f0xx.c @@ -161,7 +161,6 @@ uint8_t SetSysClock_PLL_HSI(void); * @{ */ -extern int NVIC_vtor_remap; /** * @brief Setup the microcontroller system. @@ -230,7 +229,6 @@ void SystemInit(void) /* Configure the Cube driver */ SystemCoreClock = 8000000; // At this stage the HSI is used as system clock - NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector() HAL_Init(); /* Configure the System clock source, PLL Multiplier and Divider factors, diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/cmsis_nvic.c index 02a8b586c9..2e9e8638bb 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/cmsis_nvic.c @@ -33,19 +33,17 @@ #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM #define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash -int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { int i; // Copy and switch to dynamic vectors if first time called - if (NVIC_vtor_remap == 0) { + if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) { uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS; for (i = 0; i < NVIC_NUM_VECTORS; i++) { *((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i]; } SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000 - NVIC_vtor_remap = 1; // The vectors remap is done } // Set the vector diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/system_stm32f0xx.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/system_stm32f0xx.c index d8f183aca0..e307fc20fb 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/system_stm32f0xx.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/system_stm32f0xx.c @@ -161,8 +161,6 @@ uint8_t SetSysClock_PLL_HSI(void); * @{ */ -extern int NVIC_vtor_remap; - /** * @brief Setup the microcontroller system. * Initialize the default HSI clock source, vector table location and the PLL configuration is reset. @@ -230,7 +228,6 @@ void SystemInit(void) /* Configure the Cube driver */ SystemCoreClock = 8000000; // At this stage the HSI is used as system clock - NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector() HAL_Init(); /* Configure the System clock source, PLL Multiplier and Divider factors, diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/cmsis_nvic.c index 02a8b586c9..a5d638105a 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/cmsis_nvic.c @@ -33,19 +33,16 @@ #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM #define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash -int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done - void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { int i; // Copy and switch to dynamic vectors if first time called - if (NVIC_vtor_remap == 0) { + if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) { uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS; for (i = 0; i < NVIC_NUM_VECTORS; i++) { *((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i]; } SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000 - NVIC_vtor_remap = 1; // The vectors remap is done } // Set the vector diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/system_stm32f0xx.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/system_stm32f0xx.c index bdfbc68bb3..4c50e4399a 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/system_stm32f0xx.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/system_stm32f0xx.c @@ -161,8 +161,6 @@ uint8_t SetSysClock_PLL_HSI(void); * @{ */ -extern int NVIC_vtor_remap; - /** * @brief Setup the microcontroller system. * Initialize the default HSI clock source, vector table location and the PLL configuration is reset. @@ -230,7 +228,6 @@ void SystemInit(void) /* Configure the Cube driver */ SystemCoreClock = 8000000; // At this stage the HSI is used as system clock - NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector() HAL_Init(); /* Configure the System clock source, PLL Multiplier and Divider factors,