2021-02-24 03:56 AM
I'm using a STM32F401 that has its FLASH located at address 0x08000000.
I'm trying to use the Vector Table Offset Register. I need to put the Vector Table at address 0x0800C000.
My first question would be what do I need to put in VTOR?
0x0800C000 (absolute addres) or 0x0000C000 (offset from 0x08000000)
Second question:
The manual
https://developer.arm.com/documentation/ddi0439/b/System-Control/Register-summary?lang=en
gives the information about VTOR as:
address=0xE000ED08 reset value=0x00000000
When I reset the processor with STM32CubeIDE and place a breakpoint at the very beginning of the code:
Reset_Handler:
ldr sp, =_estack /* set stack pointer */
I can see through the SFRs window that the register has in fact value 0x00000000
However when I stop the program at main() the register value is now 0x08000000
So what is changing the VTOR between the ResetHandler and main()?
It must be said that the program works and it is using interrupts...
Solved! Go to Solution.
2021-02-24 06:06 AM
After the reset, first thing is to load stack pointer initial value, followed by code to initialize default RAM variables and call SystemInit. THere is also configuration of VTOR register.
Then you jump to main.
2021-02-24 05:39 AM
Reset_Handler:
ldr sp, =_estack /* set stack pointer */
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system initialization function.*/
bl SystemInit
/* Call static constructors */
bl __libc_init_array
/* Call the application's entry point.*/
bl main
bx lr
.size Reset_Handler, .-Reset_Handler
/**
* @brief Setup the microcontroller system
* Initialize the Embedded Flash Interface, the PLL and update the
* SystemFrequency variable.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
/* Reset the RCC clock configuration to the default reset state ------------*/
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001;
/* Reset CFGR register */
RCC->CFGR = 0x00000000;
/* Reset HSEON, CSSON and PLLON bits */
RCC->CR &= (uint32_t)0xFEF6FFFF;
/* Reset PLLCFGR register */
RCC->PLLCFGR = 0x24003010;
/* Reset HSEBYP bit */
RCC->CR &= (uint32_t)0xFFFBFFFF;
/* Disable all interrupts */
RCC->CIR = 0x00000000;
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = RAMDTCM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}
2021-02-24 06:06 AM
After the reset, first thing is to load stack pointer initial value, followed by code to initialize default RAM variables and call SystemInit. THere is also configuration of VTOR register.
Then you jump to main.