cancel
Showing results for 
Search instead for 
Did you mean: 

relocation of main source and IRQ vector stm32f103

eabul.1
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
gbm
Lead III

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

View solution in original post

6 REPLIES 6
gbm
Lead III

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
Bubbles
ST Employee

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.

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

you are welcome. I will ask them about that

ARM doesn't disable the interrupt, and code doesn't expect it to be disabled.

SOMEONE disabled interrupts in their bootloader. Code provided, and code endlessly duplicated, propagating flaws and expectations.

A better solution is to set SCB->VTOR with a symbol for the vector table that the LINKER can fix up. Why it is a define is beyond me, as it requires a lot of changes with what could be automatic and based on the settings in the Linker via the Scatter File or Linker Script. It takes an address, this Base/Offset is just some confusing concept someone inserted here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

yes, it was my fold. i disabled everything before jumping. thanks