Skip to content

Commit 5fbe329

Browse files
LMESTMkegilbert
authored andcommitted
Rebase of: e51c40c
Fix vector table The address of the vector table is hardcoded to the start of flash. This patch updates make it properly handle updating the VTOR with a bootloader.
1 parent b1a56be commit 5fbe329

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_DISCO_L476VG/system_stm32l4xx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484

8585
#include "stm32l4xx.h"
8686
#include "hal_tick.h"
87+
#include "nvic_addr.h"
8788

8889
#if !defined (HSE_VALUE)
8990
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
@@ -215,7 +216,7 @@ void SystemInit(void)
215216
#ifdef VECT_TAB_SRAM
216217
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
217218
#else
218-
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
219+
SCB->VTOR = NVIC_FLASH_VECTOR_ADDRESS; /* Vector Table Relocation in Internal FLASH */
219220
#endif
220221

221222
/* Configure the Cube driver */

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_NUCLEO_L476RG/system_stm32l4xx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484

8585
#include "stm32l4xx.h"
8686
#include "hal_tick.h"
87+
#include "nvic_addr.h"
8788

8889
#if !defined (HSE_VALUE)
8990
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
@@ -215,7 +216,7 @@ void SystemInit(void)
215216
#ifdef VECT_TAB_SRAM
216217
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
217218
#else
218-
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
219+
SCB->VTOR = NVIC_FLASH_VECTOR_ADDRESS;; /* Vector Table Relocation in Internal FLASH */
219220
#endif
220221

221222
/* Configure the Cube driver */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef NVIC_ADDR_H
17+
#define NVIC_ADDR_H
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#if defined(__ICCARM__)
24+
#pragma section=".intvec"
25+
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)__section_begin(".intvec"))
26+
#elif defined(__CC_ARM)
27+
extern uint32_t Load$$LR$$LR_IROM1$$Base[];
28+
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)Load$$LR$$LR_IROM1$$Base)
29+
#elif defined(__GNUC__)
30+
extern uint32_t g_pfnVectors[];
31+
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)g_pfnVectors)
32+
#else
33+
#error "Flash vector address not set for this toolchain"
34+
#endif
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
40+
#endif

0 commit comments

Comments
 (0)