cancel
Showing results for 
Search instead for 
Did you mean: 

NVIC_EnableIRQ causes Hardfault when called from SFU_BOOT_RunSecureBootService

Grogu
Associate III

Hi,

Device - STM32H7B3I-DK

SBSFU base Project - STM32H7B3I-DK\Applications\2_Images_ExtFlash

I are using a different flash chip than STM32H7B3I-DK has MX25LM51245G and I am using MX25L51245G

1) I have implemented the flash driver and test with standalone project its working as expected.

2) Tested the code with Images_SBSFU project before beginning of secure code

#if 1
  // Test the OCTO flash driver
  uint32_t buf_len          = 0x100;
  uint32_t start_address   = EXTERNAL_FLASH_ADDRESS + 0x20000;
  uint8_t spibuffer[buf_len];
  uint8_t spibuffer_read[buf_len];
  volatile uint8_t *flash_area_mm = (uint8_t *) (start_address);
 
  for(int i =0; i < buf_len; i++) {
	  spibuffer[i] = i;
	  spibuffer_read[i] = 0xAA;
  }
 
  SFU_LL_FLASH_EXT_Init();
  SFU_FLASH_StatusTypeDef *pFlashStatus = NULL;
  if( SFU_LL_FLASH_EXT_Erase_Size(pFlashStatus, (uint8_t*)start_address, buf_len) == SFU_SUCCESS) {
 
	  if (SFU_LL_FLASH_EXT_Write( pFlashStatus, (uint8_t*)start_address, (uint8_t*)spibuffer, buf_len) == SFU_SUCCESS) {
 
		  if (SFU_LL_FLASH_EXT_Read((uint8_t*)spibuffer_read, (uint8_t*)start_address, buf_len) == SFU_SUCCESS) {
 
				  printf("\r\n FLASH OPERATION COMPLETE \r\n");
		  }
	  }
  }
  if (memcmp(spibuffer, spibuffer_read, buf_len)) {
	  printf("\r\n FLASH TEST FAILED \r\n");
  } else {
	  printf("\r\n FLASH TEST PASSED \r\n");
  }
#endif
  /* Launch the Bootloader----------------------------------------------------*/
  /*
   * This is the beginning of the secure part:
   * security mechanisms will be enabled.
   * The function below should not return (unless a critical failure is encountered).
   */
  (void)SFU_BOOT_RunSecureBootService(); /* no need to take care of the returned value as we reboot in all cases */
 
  /* Security or SecureBoot initialization failure. Force a System Reset */
  SFU_BOOT_ForceReboot();

Problem :

In SFU_LL_FLASH_EXT_Write which Enables ISR   __NVIC_EnableIRQ( OCTOSPI1_IRQn ) immediately causes HardFault_Handler

Thread #1 [main] 1 [core: 0] (Suspended : Breakpoint)	
	OCTOSPIWriteFlash() at OSPIDriver.c:698 0x800a392	
	BSP_OSPI_NOR_Write() at stm32h7b3i_discovery_ospi.c:325 0x800a67c	
	SFU_LL_FLASH_EXT_Write() at sfu_low_level_flash_ext.c:111 0x8009484	
	SFU_LL_FLASH_Write() at sfu_low_level_flash.c:84 0x80093a2	
	WriteTrailerHeader() at sfu_fwimg_no_swap.c:75 0x8008ce2	
	InstallNewVersion() at sfu_fwimg_no_swap.c:647 0x8008d9a	
	SFU_IMG_TriggerImageInstallation() at sfu_fwimg_no_swap.c:880 0x8008fe6	
	SFU_BOOT_SM_InstallNewUserFw() at sfu_boot.c:900 0x8007c60	
	SFU_BOOT_SM_Run() at sfu_boot.c:431 0x80079c8	
	SFU_BOOT_RunSecureBootService() at sfu_boot.c:202 0x8007a1c	
	<...more frames...>	

Any pointer here would be helpful.

Thanks in advance!

5 REPLIES 5
Grogu
Associate III

@Jocelyn RICARD​ have you seen an issue something like this before?

Jocelyn RICARD
ST Employee

Hello @Community member​ 

I understand you have replaced the MX25LM51245G driver in stm32h7b3i_discovery_ospi $by your own driver.

This is working fine in standalone and at beginning of SBSFU but crash when used inside SBSFU.

This is strange indeed.

You say "In SFU_LL_FLASH_EXT_Write which Enables ISR  __NVIC_EnableIRQ( OCTOSPI1_IRQn ) immediately causes HardFault_Handler". Are you sure about this ? Is this something you have added ?

Is MPU activated in your setup ?

Did you try adding a breakpoint in the IRQ Handler ?

Best regards

Jocelyn

All the security settings are disabled soon as I call _NVIC_EnableIRQ( OCTOSPI1_IRQn ) it's in hardfault handler. I stepped in assembly as well

Hi @Community member​ ,

OK Thank you.

Well I would first try to get the hardfault details in the Cortex fault status registers to try to locate the issue.

I would check the interrupt stack pointer before activating interrupt and check

Best regards

Jocelyn

Grogu
Associate III

Thanks will continue debug process and update progress.