cancel
Showing results for 
Search instead for 
Did you mean: 

SBSFU: Memory Fault when trying to read external SPI Nor Flash through QSPI in STM32F730

JYeh.9
Associate III

Hi

I am now trying to port the SBSFU project to my STM32F730 discovery board.

I would like to use the SBSFU in single image mode to upgrade the firmware in the external Nor flash connected via the QSPI interface.

My idea was to replace the flash related operation in sfu_low_level_flash.c with the corresponding flash operations. For example, replace the existing read operation with the read operation of the external flash memory via QSPI bus.

However, I got a error message trace:  [EXCPT] MEMORY FAULT when the SFU_BOOT_SM_CheckUserFwStatus function and its sub-functions tried to read the flash.

To dig deeper, the HAL_QSPI_Command API triggered this exception.

To verify the correctness of my flash memory operation, I tried to use the same implementation in the main.c, and it worked well(line 25 to 33 in the follow sni).

The QSPI interface did init successfully and the read operation did read correct data in the external flash.

int main(void)
{
#ifdef SFU_MPU_PROTECT_ENABLE
    /* Enable the CPU Cache */
  CPU_CACHE_Enable();
 
#endif /* SFU_MPU_PROTECT_ENABLE */
 
  /* MCU Configuration--------------------------------------------------------*/
  /* This part is NOT secure (security mechanisms NOT enabled yet)            */
  /* Reset of all peripherals, Initializes the Flash interface and the Systick*/
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Board BSP  Configuration-------------------------------------------------*/
  /*
   * As the secure mode has not been entered yet, we do not configure BSP right now .
   * The BSP will be configured by the bootloader.
   */
	SFU_COM_Init();
	TRACE("\r\nSBSFU Start\r\n");
       // Test to read the external flash
	if(BSP_QSPI_Init() == 0){
		TRACE("QSPI init ok\r\n");
		if(BSP_QSPI_Read(testBuf, 0, 192) == 0){
				TRACE("QSPI read ok\r\n");
		}
	}
	else{
		TRACE("QSPI init fail\r\n");
	}
 
		
  /* 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();
 
}

However, when I copied the same code to the SFU_BOOT_RunSecureBootService() function(line 29), it lead to the same memory fault error.

SFU_BOOT_InitErrorTypeDef SFU_BOOT_RunSecureBootService()
{
  SFU_BOOT_InitErrorTypeDef e_ret_code = SFU_BOOT_INIT_ERROR;
 
  /*
   * initialize Secure Engine variable as secure Engine is managed as a completely separate binary - not
   * "automatically" managed by SBSFU compiler command
   */
  if (SE_Startup() == SE_SUCCESS)
  {
    /* Security Configuration */
    if (SFU_BOOT_SystemSecurity_Config() == SFU_SUCCESS)
    {
      /* Board BSP  Configuration */
      SFU_BOOT_BspConfiguration();
 
      /* Configure the Secure Boot and start the State machine */
	
      if (SFU_BOOT_Init() == SFU_SUCCESS)
      {
				if(BSP_QSPI_Init() == 0){
					TRACE("QSPI init ok\r\n");
					if(BSP_QSPI_Read(testBuf, 0, 192) == 0){
						TRACE("QSPI read ok\r\n");
					}
				}
				else{
					TRACE("QSPI init fail\r\n");
				}
        /* Start the Secure Boot State Machine */
        SFU_BOOT_SM_Run();
      }
      else
      {
        /* failure when initializing the secure boot service */
        e_ret_code = SFU_BOOT_INIT_FAIL;
      }
    }
    else
    {
      /* failure when configuring the security IPs  */
      e_ret_code = SFU_BOOT_SECIPS_CFG_FAIL;
    }
  }
  else
  {
    /* failure at secure engine initialization stage */
    e_ret_code = SFU_BOOT_SECENG_INIT_FAIL;
  }
 
  /*
   * This point should not be reached unless a critical init failure occurred
   * Return the error code
   */
  return (e_ret_code);
}

Could anyone help?

Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions
JYeh.9
Associate III

The issue is solved.

It is caused by the MPU setting in the SBSFU project.

To use QSPI peripheral in the SBSFU project, we need to add it into the MPU protect area as well as the QSPI memory-mapped area,

View solution in original post

1 REPLY 1
JYeh.9
Associate III

The issue is solved.

It is caused by the MPU setting in the SBSFU project.

To use QSPI peripheral in the SBSFU project, we need to add it into the MPU protect area as well as the QSPI memory-mapped area,