Skip to content

Commit 5765076

Browse files
committed
Fix #1419 : solve baud_rate issue
Issue was : stdio printf is ok, serial.printf is failing, in case it is inialized as a global variable. It works on mbed version 107. Fix: revert to version 107 for systemxxx.c, mbed_overrides.c + cmsis_nvic.c. Modify cmsis_nvic.c to use direct addressing instead of a pointer (this pointer is not yet initialized when called in systemxx.c) Call HAL_Init in mbed_overrides.c for every platforms.
1 parent d590d8b commit 5765076

File tree

16 files changed

+184
-104
lines changed

16 files changed

+184
-104
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,29 @@
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+
int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done
37+
3638
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3739
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;
4240

4341
// 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
42+
if (NVIC_vtor_remap == 0) {
43+
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
44+
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
45+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
46+
}
47+
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
48+
NVIC_vtor_remap = 1; // The vectors remap is done
5149
}
5250

5351
// Set the vector
54-
vectors[IRQn + 16] = vector;
52+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5553
}
5654

5755
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

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

Lines changed: 16 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,8 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
extern int NVIC_vtor_remap;
165+
164166
/**
165167
* @brief Setup the microcontroller system.
166168
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +227,19 @@ void SystemInit(void)
225227

226228
/* Disable all interrupts */
227229
RCC->CIR = 0x00000000;
230+
231+
/* Configure the Cube driver */
232+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
233+
NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector()
234+
HAL_Init();
235+
236+
/* Configure the System clock source, PLL Multiplier and Divider factors,
237+
AHB/APBx prescalers and Flash settings */
238+
SetSysClock();
239+
240+
/* Reset the timer to avoid issues after the RAM initialization */
241+
TIM_MST_RESET_ON;
242+
TIM_MST_RESET_OFF;
228243
}
229244

230245
/**

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

Lines changed: 11 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,29 @@
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
36+
int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done
3737

3838
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3939
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;
4240

4341
// 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
42+
if (NVIC_vtor_remap == 0) {
43+
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
44+
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
45+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
46+
}
47+
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
48+
NVIC_vtor_remap = 1; // The vectors remap is done
5149
}
5250

5351
// Set the vector
54-
vectors[IRQn + 16] = vector;
52+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5553
}
5654

5755
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: 16 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,8 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
extern int NVIC_vtor_remap;
165+
164166
/**
165167
* @brief Setup the microcontroller system.
166168
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +227,19 @@ void SystemInit(void)
225227

226228
/* Disable all interrupts */
227229
RCC->CIR = 0x00000000;
230+
231+
/* Configure the Cube driver */
232+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
233+
NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector()
234+
HAL_Init();
235+
236+
/* Configure the System clock source, PLL Multiplier and Divider factors,
237+
AHB/APBx prescalers and Flash settings */
238+
SetSysClock();
239+
240+
/* Reset the timer to avoid issues after the RAM initialization */
241+
TIM_MST_RESET_ON;
242+
TIM_MST_RESET_OFF;
228243
}
229244

230245
/**

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,23 @@
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+
int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done
37+
3638
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3739
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-
40+
4341
// Copy and switch to dynamic vectors if first time called
44-
if (vtor_remap == 0) {
42+
if (NVIC_vtor_remap == 0) {
4543
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
4644
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
47-
vectors[i] = old_vectors[i];
45+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
4846
}
4947
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
50-
vtor_remap = 1; // The vectors remap is done
48+
NVIC_vtor_remap = 1; // The vectors remap is done
5149
}
5250

5351
// Set the vector
54-
vectors[IRQn + 16] = vector;
52+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5553
}
5654

5755
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

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

Lines changed: 16 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,8 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
extern int NVIC_vtor_remap;
165+
164166
/**
165167
* @brief Setup the microcontroller system.
166168
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +227,19 @@ void SystemInit(void)
225227

226228
/* Disable all interrupts */
227229
RCC->CIR = 0x00000000;
230+
231+
/* Configure the Cube driver */
232+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
233+
NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector()
234+
HAL_Init();
235+
236+
/* Configure the System clock source, PLL Multiplier and Divider factors,
237+
AHB/APBx prescalers and Flash settings */
238+
SetSysClock();
239+
240+
/* Reset the timer to avoid issues after the RAM initialization */
241+
TIM_MST_RESET_ON;
242+
TIM_MST_RESET_OFF;
228243
}
229244

230245
/**

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,23 @@
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+
int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done
37+
3638
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3739
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-
40+
4341
// Copy and switch to dynamic vectors if first time called
44-
if (vtor_remap == 0) {
42+
if (NVIC_vtor_remap == 0) {
4543
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
4644
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
47-
vectors[i] = old_vectors[i];
45+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
4846
}
4947
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
50-
vtor_remap = 1; // The vectors remap is done
48+
NVIC_vtor_remap = 1; // The vectors remap is done
5149
}
5250

5351
// Set the vector
54-
vectors[IRQn + 16] = vector;
52+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5553
}
5654

5755
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

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

Lines changed: 16 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,8 @@ uint8_t SetSysClock_PLL_HSI(void);
161161
* @{
162162
*/
163163

164+
extern int NVIC_vtor_remap;
165+
164166
/**
165167
* @brief Setup the microcontroller system.
166168
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
@@ -225,6 +227,19 @@ void SystemInit(void)
225227

226228
/* Disable all interrupts */
227229
RCC->CIR = 0x00000000;
230+
231+
/* Configure the Cube driver */
232+
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
233+
NVIC_vtor_remap = 0; // Because it is not cleared the first time we enter in NVIC_SetVector()
234+
HAL_Init();
235+
236+
/* Configure the System clock source, PLL Multiplier and Divider factors,
237+
AHB/APBx prescalers and Flash settings */
238+
SetSysClock();
239+
240+
/* Reset the timer to avoid issues after the RAM initialization */
241+
TIM_MST_RESET_ON;
242+
TIM_MST_RESET_OFF;
228243
}
229244

230245
/**

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,29 @@
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+
int NVIC_vtor_remap = 0; // To keep track that the vectors remap is done
37+
3638
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3739
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;
4240

4341
// 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
42+
if (NVIC_vtor_remap == 0) {
43+
uint32_t *old_vectors = (uint32_t *)NVIC_FLASH_VECTOR_ADDRESS;
44+
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
45+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (i*4))) = old_vectors[i];
46+
}
47+
SYSCFG->CFGR1 |= 0x03; // Embedded SRAM mapped at 0x00000000
48+
NVIC_vtor_remap = 1; // The vectors remap is done
5149
}
5250

5351
// Set the vector
54-
vectors[IRQn + 16] = vector;
52+
*((uint32_t *)(NVIC_RAM_VECTOR_ADDRESS + (IRQn*4) + (NVIC_USER_IRQ_OFFSET*4))) = vector;
5553
}
5654

5755
uint32_t NVIC_GetVector(IRQn_Type IRQn) {

0 commit comments

Comments
 (0)