cancel
Showing results for 
Search instead for 
Did you mean: 

CPU stuck in HAL_NVIC_EnableIRQ

armdude
Visitor

Hi, this is my first post so I will try to provide as much information as possible. Any help is greatly appreciated! I will try to provide any missing details.

What I'm Trying To Do

  • I am trying to erase sector 1 using the HAL provided APIs
  • Tried HAL_FLASHEx_Erase(&p_erase_init, &page_error);
  • Tried FLASH_Erase_Sector(uint32_t Sector, uint32_t Banks, uint32_t VoltageRange)
  • Just for testing, I am attempting to erase sector 1 just before the while(1) loop in main
  • I am using a debug LED to indicate if my program is successful (enteres the while(1) loop)

Context

  • Target MCU is the STM32H755
  • A custom bootloader Cortex-M7 application that lives in FLASH in 0x08000000
  • The custom bootloader Cortex-M4 appliction is gutted out and runs a while (1) {} 

Problem

  • The CPU hangs when this function is called HAL_NVIC_EnableIRQ(pSpiIoCfg->IntrIrq);

Note

  • I am unlocking the FLASH and locking FLASH afer erasing sector 1

Sample Code

 

 

 

FLASH_EraseInitTypeDef p_erase_init = {0};
uint32_t page_error;

p_erase_init.TypeErase = FLASH_TYPEERASE_SECTORS;
p_erase_init.Banks = FLASH_BANK_1;
p_erase_init.Sector = 1;
p_erase_init.NbSectors = 1U;
p_erase_init.VoltageRange = FLASH_VOLTAGE_RANGE_3;
HAL_FLASHEx_Erase(&p_erase_init, &page_error);

...

#if AL_EVENT_ENABLED
	/* Configure GPIO as SPI interrupt input */
	HW_GPIO_ClkSource(pSpiIoCfg->pIntrPort, ENABLE);	
	GPIO_InitStructure.Pin = pSpiIoCfg->IntrPin;
	GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
	GPIO_InitStructure.Pull = GPIO_PULLUP;
	GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(pSpiIoCfg->pIntrPort, &GPIO_InitStructure);
	
	/* Enable SPI interrupt source at NVIC */
	HAL_NVIC_SetPriorityGrouping(HW_NVIC_PRIORITY_GROUP);
	HAL_NVIC_SetPriority(pSpiIoCfg->IntrIrq, pSpiIoCfg->IntrPrePrio, pSpiIoCfg->IntrSubPrio);

	// CPU hangs when calling this function
	HAL_NVIC_EnableIRQ(pSpiIoCfg->IntrIrq);
	HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, 0);
#endif


...

 

 

 

 

Pin and Clock Configuration

Clock Tree

 

armdude_1-1736819053460.png

NVIC1 Settings

armdude_3-1736819102471.png

 

 

2 REPLIES 2
Pavel A.
Evangelist III

Hello and welcome to the forum!

So you want to erase a sector in the internal flash of STM32H755.

SPI is not related to this so there's no any sense in enabling its interrupt (and what is "SPI interrupt source" at all?)

Remove or comment out lines 24, 27. Will it work?

 

 

 

 

Hangs where? If you stop the MCU in debugger where is it?

Hard Fault or perpetually locked in IRQ Handler trying and failing to clear the source.

You Erase a sector with live code in it?

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