Skip to main content
eabul.1
Associate
December 22, 2022
Solved

relocation of main source and IRQ vector stm32f103

  • December 22, 2022
  • 2 replies
  • 3112 views

hello!

I'm working on stm32f103 and I found one problem which has a weird solution.

In my project, I have a bootloader and main source. I use the 0x800000 address to start the bootloader and 0x8008200 to begin my main project (the bootloader jumps to this address). after changing the main project:

0693W00000WLce4QAD.png 

address I defined also:

#define USER_VECT_TAB_ADDRESS 

in "system_stm32f1xx.c"

it opened me section where I wrote this

#define USER_VECT_TAB_ADDRESS 
 
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
 in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
 This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
 This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
 This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00008200 /*!< Vector Table base offset field.
 This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */

after this everything works great if I will add __eneable_irq(); in the main source

int main(void)
{
 /* USER CODE BEGIN 1 */
 
 /* USER CODE END 1 */
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* USER CODE BEGIN SysInit */
	static dev_trace_init_t trace_init;
	trace_init.mosi.port = GPIO_PB;
	trace_init.sck.port = GPIO_PA;
	trace_init.nss.port = GPIO_PA;
	trace_init.mosi.pin = BB(0, b00100000);
	trace_init.sck.pin = BB(b00010000, 0);
	trace_init.nss.pin = BB(b00001000, 0);
	dev_trace_init(&trace_init);
	debug_printf("\n\r\n\r\n\r----------------------------------------------start Version 0.10----------------------------------------------\n\r\n\r");
	//IWDG_Init();
 /* USER CODE END SysInit */
 
	__enable_irq();
 
 /* Initialize all configured peripherals */
	
 /* USER CODE BEGIN 2 */

so why is it needed and why it doesn't work without enabling? is there some bug in shifting the IRQ vector? if I won't write this, project will be broken at the first IRQ

This topic has been closed for replies.
Best answer by gbm

Look at the bootloader you use. I guess it disables interrupts before jumping to the application. 0x8008200 is strange choice - it's in the middle of Flash page; why not 0x8008000?

Also, it's better to set the VECTBASE in the bootloader and remove any VECTBASE setting from the app. This way the only thing to change in the app while relocating the app is the Flash base address.

2 replies

gbm
gbmBest answer
Lead III
December 22, 2022

Look at the bootloader you use. I guess it disables interrupts before jumping to the application. 0x8008200 is strange choice - it's in the middle of Flash page; why not 0x8008000?

Also, it's better to set the VECTBASE in the bootloader and remove any VECTBASE setting from the app. This way the only thing to change in the app while relocating the app is the Flash base address.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
eabul.1
eabul.1Author
Associate
December 22, 2022

i have not thaught about that i'll see my boot tomorrow thanks ^__^

Bubbles
ST Employee
December 22, 2022

Hi @eabul.1​,

this is not an ST-specific part, the SCB->VTOR is part of the Cortex-M core and the vector relocation is described in ARM documentation. You'd have to ask ARM why they decided to have global IRQ disabled by default after writing the VT offset.

I'm anyway glad that you were able to figure out the solution and you shared it with the community. Thanks.

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
eabul.1
eabul.1Author
Associate
December 22, 2022

you are welcome. I will ask them about that