STMicroelectronics / STM32CubeF4

STM32Cube MCU Full Package for the STM32F4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
869 stars 418 forks source link

STM32F4 1.26 Vector table position can not be defined by compiler define #65

Closed theadib closed 3 years ago

theadib commented 3 years ago

@see https://github.com/STMicroelectronics/STM32CubeF4/issues/30 @see https://github.com/STMicroelectronics/STM32CubeF4/pull/64

Hello ST Team please listen to your users.

I need to be able to redefine the position of the vector table based on compiler defines. So that I do not need to modify code when I compile for target that has bootloader. in my proposal #30 this was possible.

now in 1.26 the template code lookes like that: https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c

#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         0x00000000U     /*!< Vector Table base offset field.
                                                     This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */

and

#if defined(USER_VECT_TAB_ADDRESS)
  SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#endif /* USER_VECT_TAB_ADDRESS */

1) please set the vector address register regardless of USER_VECT_TAB_ADDRESS

2) please test before setting VECT_TAB_OFFSET

#if !defined(VECT_TAB_OFFSET)
#define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field.
#endif

3) however I do not really understand the use of USER_VECT_TAB_ADDRESS this define should hold the address itself. why is it not as simple as:

#if defined(USER_VECT_TAB_ADDRESS)
  SCB->VTOR = USER_VECT_TAB_ADDRESS);
#else
  SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
RKOUSTM commented 3 years ago

Hi @theadib,

I hope you are fine. Our development teams said your proposal could not be taken into consideration for the following reason:

The modifying of VTOR is now only performed if USER_VECT_TAB_ADDRESS is activated (in the IDE or directly in the file). This is done on purpose as the memory remap is performed at boot, allows the vector table to be basically at address 0x00. So, if the user does not want to relocate it anywhere else, there is no need to access this register. More than that some products (like dual CPU ones) use the boot address from the option bytes, so having a generic way of setting VTOR is worse than letting the default configuration (option bytes set boot @ => that one is remapped @ 0x0)

Please allow me to close this issue now and thank you for your comprehension. We are looking forward to reading from you again.

With regards,

ALABSTM commented 2 years ago

Hi @theadib,

Hope you are fine. Back to you about the points you raised:

  1. please set the vector address register regardless of USER_VECT_TAB_ADDRESS
  2. please test before setting VECT_TAB_OFFSET
  3. however I do not really understand the use of USER_VECT_TAB_ADDRESS

Regarding point 1, as explained by @RKOUSTM, the default value 0x00000000 of the SCB->VOTR register after a re-boot supposes the vector table is located at address 0x08000000, which is the default setting. Since address 0x08000000 is aliased 0x00000000 by default, access to the vector table will be correctly performed in case of interrupt.

This is why, in case this default setting is not to be changed by the user, there is no need to write-access the SCB->VTOR register during system initialization. Now, this also supposes, in case of a custom board, that pin BOOT0 is connected to the GND. You can find more details in the reference manual.

Regarding points 2 and 3, we do agree that, even with the new proposal, it is not yet possible to define the VECT_TAB_OFFSET at IDE- or Makefile-level. The point has been reported to our development teams. You can follow the progress here.

With regards,

diyfr commented 2 years ago

Same problem with IAP. Forced to make this modification with each code regeneration, it is rather painful. Strongly that this is put in place !!

theadib commented 1 year ago

Hello ST Team not solved at all at the 1.27.1 release.

here a pullrequest to SOLVE the issue. https://github.com/STMicroelectronics/STM32CubeF4/pull/146

Adib.