cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader jump to Application HardFault - STM32H563

PFlor.2
Senior II

I am developing a bootloader for the STM32H563 that is stored at the beginning of internal Flash (0x08000000) and the application is stored at 0x08020000.  The application runs fine when I program/start from STM32CubeIDE once I changed the linker script to set the appropriate Flash address and the VEC_TAB_ADDRESS to be 0x20000 in system_stm32h5xx.c, so the application runs fine on its own from the new 0x08020000 address.

In the bootloader I am executing the following code the should work fine as I've used similar before in a project with the STM32H743.

    __disable_irq();
    SCB->VTOR = (uint32_t)EuiFlashFile_loadAddress;
    __set_MSP(*(__IO uint32_t*) EuiFlashFile_loadAddress);
    void (*app_reset_handler)(void);
    app_reset_handler = (void (*)(void))(*(__IO uint32_t*)(EuiFlashFile_loadAddress + 4U));
    app_reset_handler();

The app_reset_handler is set to the correct Reset_Handler address stored at 0x08020004 (0x0802FC3D)...

PFlor2_0-1758668001701.png

....but after the app_reset_handler() is called I used the debugger to attach to the application .elf and it was in the hard fault handler.  I tried to step through again and once it jumped I detached and attached to application debugger and it seemed to be stuck in the HAL_Delay()...so not sure what is happening.

Any ideas or advice would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Saket_Om
ST Employee

Hello @PFlor.2 

Did you enable the the irq in your application? 

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.
Saket_Om

View solution in original post

2 REPLIES 2
Saket_Om
ST Employee

Hello @PFlor.2 

Did you enable the the irq in your application? 

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.
Saket_Om

Interestingly I never had to manually enable IRQ in my application with the STM32H743, but you are correct, by enabling the IRQ after the clock configuration as shown below the jump works fine.  Makes sense this was causing the HAL_Delay() to hang since the timer would not be running...thanks for the tip!  There must be some difference in the HAL initializations of the STM743 that enables the IRQ that does not exist for the STM32H563.  The generated HAL is a great feature of the STM32 line but I have found that the HAL code is very inconsistent from micro to micro, makes it difficult to reuse code from one project to another.

  /* 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();

  /* Configure the peripherals common clocks */
  PeriphCommonClock_Config();

  /* USER CODE BEGIN SysInit */
  /* I've found I have to manually enable this when jumping from the bootloader
   * because it's disabled to relocate the vector table before jumping to the
   * application.
   */
  __enable_irq();

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_GPDMA1_Init();
  MX_GPDMA2_Init();
  MX_OCTOSPI1_Init();
  MX_SPI3_Init();
  MX_UART5_Init();