[solved][STM32H7-33] HardFault_Handler in application jumping from custom bootloader
Hi!
I'm currently having troubles jumping from custom bootloader to application.
Working on STM32H733 MCU, the boot code that makes the jump is the following:
void vSetupAndJumpToAddr(uint32_t flashStartAddr)
{
uint32_t i=0;
// Disable all interrupts
__disable_irq(); //correspond to assembly cmd: CPSID i
HAL_MPU_Disable();
HAL_RCC_DeInit();
HAL_DeInit();
/* Clear Interrupt Enable Register & Interrupt Pending Register */
for (i = 0 ; i < 8 ; i ++)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
// Disable I-Cache
SCB_DisableICache();
// Disable D-Cache
SCB_DisableDCache();
__enable_irq();
// Jump to user application
uint32_t JumpAddress = *(__IO uint32_t*)(flashStartAddr+4);
pFunction Jump_To_Adress = (pFunction)JumpAddress;
// re-init stack pointer (first entry of the vector table)
__set_MSP(*(__IO uint32_t*) flashStartAddr);
Jump_To_Adress();
// *** codeline never reached ***
Error_Handler();
}After that, I correctly jump to application with start address 0x0804 0200.
In the Application project, the define "VECT_TAB_OFFSET=0x40200" was inserted to offset the Interrupt Vector Table.
The application starts correctly (I checked both the entrance in the startup code startup_stm32h723xx.s, the execution of SCB->VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET; that correctly setup the Application VIT address at 0x08040200), but then the same application that worked alone placed at 0x0800 0000 enter in hard fault.
Hard fault is reached when main.c is initializing stuffs, when HAL_TIM_PeriodElapsedCallback(htim); is hit by the htim7, wich in my case is set as the Timebase Source of the SYS in the CubeMX project.
the Application main.c init code looks like this:
int main(void)
{
/* USER CODE BEGIN 1 */
__HAL_DBGMCU_FREEZE_IWDG1(); // must be declared using debug session
__HAL_DBGMCU_FREEZE_IWDG1(); // must be declared using debug session
__HAL_DBGMCU_FREEZE_TIM1 ();
__HAL_DBGMCU_FREEZE_TIM4 ();
__HAL_DBGMCU_FREEZE_TIM6 ();
__HAL_DBGMCU_FREEZE_TIM12 ();
__HAL_DBGMCU_FREEZE_TIM15 ();
__HAL_DBGMCU_FREEZE_TIM16 ();
__HAL_DBGMCU_FREEZE_TIM23 ();
__HAL_DBGMCU_FREEZE_TIM3 ();
__HAL_DBGMCU_FREEZE_I2C5 ();
__HAL_DBGMCU_FREEZE_WWDG1 ();
__HAL_DBGMCU_FREEZE_IWDG1 ();
/* USER CODE END 1 */
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
memset ((void *)0x30004000, 0xEE, 0x00004000); //LWIP_RAM_HEAP_POINTER area
memset ((void *)0x30004640, 0xAA, 0x000039C0); //LWIP_RAM_HEAP_POINTER area
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_ADC3_Init();
MX_FDCAN3_Init();
MX_I2C5_Init();
MX_OCTOSPI1_Init();
MX_TIM1_Init();
MX_TIM4_Init();
MX_TIM12_Init();
MX_TIM15_Init();
MX_TIM16_Init();
MX_TIM23_Init();
MX_UART4_Init();
MX_UART5_Init();
MX_UART9_Init();
MX_USART3_Init();
MX_USART10_Init();
MX_TIM3_Init();
MX_DAC1_Init();
MX_TIM6_Init();
MX_CRC_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */
//__enable_irq();
// HW initialization
HAL_GPIO_WritePin([blablabla]_GPIO_Port, [blablabla]_Pin, GPIO_PIN_RESET);
HAL_TIM_Base_Start (&htim6); // Start TIM6.
BSP_Capture_Timers_Init ();
BSP_Analog_Init(); // HW board support package for Analog Components
[ ... other code never reached before the error ... ]Any clue on the problem?
I enabled and disabled in different ways irqs without success, it might be something small I cannot see.
It is for sure an interrupt problem, _irq_disable() is used in the begin of the code, the hard fault is never reached.
Thanks :folded_hands:
