Skip to content

Commit a63257b

Browse files
committed
Merge pull request #1432 from adustm/DEV_FIX_1419_baudrateissue
[TARGET_STMF0] Fix #1419 baudrateissue
2 parents 7899cff + c59167c commit a63257b

File tree

16 files changed

+150
-106
lines changed

16 files changed

+150
-106
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/cmsis_nvic.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,26 @@
2727
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*******************************************************************************
30-
*/
30+
*/
3131
#include "cmsis_nvic.h"
3232

3333
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM
3434
#define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash
3535

3636
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3737
int i;
38-
// To keep track that the vectors remap is done
39-
static volatile uint32_t vtor_remap = 0;
40-
// Space for dynamic vectors, initialised to allocate in R/W
41-
static volatile uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
4238

4339
// Copy and switch to dynamic vectors if first time called
44-
if (vtor_remap == 0) {
45-
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
46-
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
47-
vectors[i] = old_vectors[i];
48-
}
49-
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
50-
vtor_remap = 1; // The vectors remap is done
40+
if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) {
41+
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
42+
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
43+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
44+
}
45+
SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000
5146
}
5247

5348
// Set the vector
54-
vectors[IRQn + 16] = vector;
49+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5550
}
5651

5752
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/system_stm32f0xx.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
8685
/**
8786
* @}
8887
*/
@@ -161,6 +160,7 @@ uint8_t SetSysClock_PLL_HSI(void);
161160
* @{
162161
*/
163162

163+
164164
/**
165165
* @brief Setup the microcontroller system.
166166
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +225,15 @@ void SystemInit(void)
225225

226226
/* Disable all interrupts */
227227
RCC->CIR = 0x00000000;
228+
229+
/* Configure the Cube driver */
230+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
231+
HAL_Init();
232+
233+
/* Configure the System clock source, PLL Multiplier and Divider factors,
234+
AHB/APBx prescalers and Flash settings */
235+
SetSysClock();
236+
228237
}
229238

230239
/**

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/cmsis_nvic.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* mbed Microcontroller Library
22
* CMSIS-style functionality to support dynamic vectors
33
*******************************************************************************
4-
* Copyright (c) 2014, STMicroelectronics
4+
* Copyright (c) 2015, STMicroelectronics
55
* All rights reserved.
66
*
77
* Redistribution and use in source and binary forms, with or without
@@ -27,31 +27,27 @@
2727
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*******************************************************************************
30-
*/
30+
*/
3131
#include "cmsis_nvic.h"
3232

3333
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM
3434
#define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash
3535

36-
static unsigned char vtor_remap = 0; // To keep track that the vectors remap is done
3736

3837
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3938
int i;
40-
// Space for dynamic vectors, initialised to allocate in R/W
41-
static volatile uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
4239

4340
// Copy and switch to dynamic vectors if first time called
44-
if (vtor_remap == 0) {
45-
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
46-
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
47-
vectors[i] = old_vectors[i];
48-
}
49-
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
50-
vtor_remap = 1; // The vectors remap is done
41+
if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) {
42+
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
43+
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
44+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
45+
}
46+
SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000
5147
}
5248

5349
// Set the vector
54-
vectors[IRQn + 16] = vector;
50+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5551
}
5652

5753
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/cmsis_nvic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* mbed Microcontroller Library
22
* CMSIS-style functionality to support dynamic vectors
33
*******************************************************************************
4-
* Copyright (c) 2014, STMicroelectronics
4+
* Copyright (c) 2015, STMicroelectronics
55
* All rights reserved.
66
*
77
* Redistribution and use in source and binary forms, with or without

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/system_stm32f0xx.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
85+
#include "hal_tick.h"
8686
/**
8787
* @}
8888
*/
@@ -161,6 +161,7 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
164165
/**
165166
* @brief Setup the microcontroller system.
166167
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +226,18 @@ void SystemInit(void)
225226

226227
/* Disable all interrupts */
227228
RCC->CIR = 0x00000000;
229+
230+
/* Configure the Cube driver */
231+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
232+
HAL_Init();
233+
234+
/* Configure the System clock source, PLL Multiplier and Divider factors,
235+
AHB/APBx prescalers and Flash settings */
236+
SetSysClock();
237+
238+
/* Reset the timer to avoid issues after the RAM initialization */
239+
TIM_MST_RESET_ON;
240+
TIM_MST_RESET_OFF;
228241
}
229242

230243
/**

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/cmsis_nvic.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,21 @@
3333
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM
3434
#define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash
3535

36+
3637
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3738
int i;
38-
// To keep track that the vectors remap is done
39-
static volatile uint32_t vtor_remap = 0;
40-
// Space for dynamic vectors, initialised to allocate in R/W
41-
static volatile uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
42-
39+
4340
// Copy and switch to dynamic vectors if first time called
44-
if (vtor_remap == 0) {
41+
if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) {
4542
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
4643
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
47-
vectors[i] = old_vectors[i];
44+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
4845
}
49-
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
50-
vtor_remap = 1; // The vectors remap is done
46+
SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000
5147
}
5248

5349
// Set the vector
54-
vectors[IRQn + 16] = vector;
50+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5551
}
5652

5753
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/system_stm32f0xx.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
85+
#include "hal_tick.h"
8686
/**
8787
* @}
8888
*/
@@ -161,6 +161,7 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
164165
/**
165166
* @brief Setup the microcontroller system.
166167
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +226,18 @@ void SystemInit(void)
225226

226227
/* Disable all interrupts */
227228
RCC->CIR = 0x00000000;
229+
230+
/* Configure the Cube driver */
231+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
232+
HAL_Init();
233+
234+
/* Configure the System clock source, PLL Multiplier and Divider factors,
235+
AHB/APBx prescalers and Flash settings */
236+
SetSysClock();
237+
238+
/* Reset the timer to avoid issues after the RAM initialization */
239+
TIM_MST_RESET_ON;
240+
TIM_MST_RESET_OFF;
228241
}
229242

230243
/**

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/cmsis_nvic.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,21 @@
3333
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM
3434
#define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash
3535

36+
3637
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3738
int i;
38-
// To keep track that the vectors remap is done
39-
static volatile uint32_t vtor_remap = 0;
40-
// Space for dynamic vectors, initialised to allocate in R/W
41-
static volatile uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
42-
39+
4340
// Copy and switch to dynamic vectors if first time called
44-
if (vtor_remap == 0) {
41+
if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) {
4542
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
4643
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
47-
vectors[i] = old_vectors[i];
44+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
4845
}
49-
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
50-
vtor_remap = 1; // The vectors remap is done
46+
SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000
5147
}
5248

5349
// Set the vector
54-
vectors[IRQn + 16] = vector;
50+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5551
}
5652

5753
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/system_stm32f0xx.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
85+
#include "hal_tick.h"
8686
/**
8787
* @}
8888
*/
@@ -161,6 +161,7 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
164165
/**
165166
* @brief Setup the microcontroller system.
166167
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +226,18 @@ void SystemInit(void)
225226

226227
/* Disable all interrupts */
227228
RCC->CIR = 0x00000000;
229+
230+
/* Configure the Cube driver */
231+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
232+
HAL_Init();
233+
234+
/* Configure the System clock source, PLL Multiplier and Divider factors,
235+
AHB/APBx prescalers and Flash settings */
236+
SetSysClock();
237+
238+
/* Reset the timer to avoid issues after the RAM initialization */
239+
TIM_MST_RESET_ON;
240+
TIM_MST_RESET_OFF;
228241
}
229242

230243
/**

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/cmsis_nvic.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,27 @@
2727
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*******************************************************************************
30-
*/
30+
*/
3131
#include "cmsis_nvic.h"
3232

3333
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Vectors positioned at start of RAM
3434
#define NVIC_FLASH_VECTOR_ADDRESS (0x08000000) // Initial vector position in flash
3535

36+
3637
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3738
int i;
38-
// To keep track that the vectors remap is done
39-
static volatile uint32_t vtor_remap = 0;
40-
// Space for dynamic vectors, initialised to allocate in R/W
41-
static volatile uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
4239

4340
// Copy and switch to dynamic vectors if first time called
44-
if (vtor_remap == 0) {
45-
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
46-
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
47-
vectors[i] = old_vectors[i];
48-
}
49-
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
50-
vtor_remap = 1; // The vectors remap is done
41+
if ((SYSCFG->CFGR1 & SYSCFG_CFGR1_MEM_MODE) != SYSCFG_CFGR1_MEM_MODE) {
42+
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
43+
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
44+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
45+
}
46+
SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE; // Embedded SRAM mapped at 0x00000000
5147
}
5248

5349
// Set the vector
54-
vectors[IRQn + 16] = vector;
50+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5551
}
5652

5753
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/system_stm32f0xx.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
*/
8383

8484
#include "stm32f0xx.h"
85-
85+
#include "hal_tick.h"
8686
/**
8787
* @}
8888
*/
@@ -161,6 +161,7 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
164165
/**
165166
* @brief Setup the microcontroller system.
166167
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +226,18 @@ void SystemInit(void)
225226

226227
/* Disable all interrupts */
227228
RCC->CIR = 0x00000000;
229+
230+
/* Configure the Cube driver */
231+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
232+
HAL_Init();
233+
234+
/* Configure the System clock source, PLL Multiplier and Divider factors,
235+
AHB/APBx prescalers and Flash settings */
236+
SetSysClock();
237+
238+
/* Reset the timer to avoid issues after the RAM initialization */
239+
TIM_MST_RESET_ON;
240+
TIM_MST_RESET_OFF;
228241
}
229242

230243
/**

0 commit comments

Comments
 (0)