2022-09-27 02:23 AM
To give a context:
I'm working to implement OTA for an existing project which uses stm32f091xx.
And it already contains separate bootloader(0x08000000) and application(0x08001000) with their own vector tables.
Currently, when a reset occurs, the bootloader which is remapped to 0x0 will call the application at 0x08001000.
Question:
Both bootloader and application have their own vector table.
But on the internet, I found that Cortex-M0 doesn't have a vector table offset.
Just to know more about it, I tried to create a hard fault on the application and surprisingly, the hard fault is now in a location which is relative to the application and not the bootloader.
This is map of the bootloader:
HardFault_Handler 0x080000e3 Thumb Code 2 startup_stm32f0xx.o(.text)
This is map of the application:
HardFault_Handler 0x08002447 Thumb Code 2 stm32f0xx_startup.o(.text)
Why is this working? I mean when I set a hard fault, it should go to 0x080000e3 but why it is going to 0x08002447? Can someone give me any ideas about what is happening?
Solved! Go to Solution.
2022-09-27 05:06 AM
Typically on the CM0 you have to copy the vector table into the base of RAM, and then remap that into the zero address space. Register in SYSCFG
2022-09-27 05:06 AM
Typically on the CM0 you have to copy the vector table into the base of RAM, and then remap that into the zero address space. Register in SYSCFG
2022-09-27 07:21 AM
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
Now I can relate why the start up file above was defined like this.
They mentioned it in Data section I found it like this.
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
Thank you.
2024-11-10 10:56 PM - edited 2024-11-10 10:57 PM
@Tesla DeLorean Please give me that formula for copy the vector table into the base of RAM and then remap that into the zero address space (SYSCFG) for STM32F072RBT6 (CM0) i didn't understand and this is copy vector table and remap that into zero address space in application side ? .
2024-11-12 02:04 AM - edited 2024-11-12 02:12 AM
1. Declare the structure for vector table.
2. In the application and bootloader linker scripts, create a dedicated 192-byte MEMORY section at the beginning of RAM, leaving the rest of RAM, starting at 0x2000000c0, as ordinary RAM section.
3. In the bootloader, define two vector table structures, one at the beginning of application image in Flash, the other in the dedicated RAM section.
4. In the bootloader, just before starting the app, copy the vector table from ram to flash using simple assignment of structures, then map RAM at 0 - see the relevant section in the reference manual of your microcontroller, use "remap" as the keyword.
// Cortex-M0, M0+ vector table with 32 IRQ vectors
struct cm0_vectable_ {
uint32_t Init_SP;
void (*Reset_Handler)(void);
void (*NMI_Handler)(void);
void (*HardFault_Handler)(void);
void (*MemManage_Handler)(void); // v7; unused in CM0
void (*BusFault_Handler)(void); // v7; unused in CM0
void (*UsageFault_Handler)(void); // v7; unused in CM0
void (*SecureFault_Handler)(void); // v8; unused below CM23
void (*Exc8_Handler)(void);
void (*Exc9_Handler)(void);
void (*Exc10_Handler)(void);
void (*SVC_Handler)(void);
void (*DebugMon_Handler)(void); // v7; unused in CM0
void (*Exc13_Handler)(void);
void (*PendSV_Handler)(void);
void (*SysTick_Handler)(void);
void (*NVIC_Interrupt[32])(void);
};
#define APP_VECTABLE (struct cm0_vectable_ *) APP_BASE
#define RAM_VECTABLE (struct cm0_vectable_ *) 0x20000000
*RAM_VECTABLE = *APP_VECTABLE;
__set_MSP(APP_VECTABLE->Init_SP);
APP_VECTABLE->Reset_Handler();