cancel
Showing results for 
Search instead for 
Did you mean: 

External loader Init() fails at the second call in CubeProgrammer

Emilmart
Senior

Hi everyone,

I'm working on a custom external loader with an OSPI MX66LM1G45G memory and a STM32H7 A3.

If I try to use my external loader in CubeProgrammer (in "Memory & file edition" tab) for reading OSPI at 0x90000000 for example, it works fine the first time, I read datas.

But if I try to read the OSPI an other time at an other adress, the Init() function fails, despite working the first time.

It seems that when my OSPI has been setup once, it can't be reinitialised properly a second time. I have to poweroff my board so that the Init function succeeds, but the Init always fails at the second call.

So I investigate with my debug project for the external loader, and if I try to replay the Init function a second time, I can see that the problem occurs when I try to reconfigure the memory in octal mode, precisly at the configuration of the automatic polling mode to wait for write enable. Here's the part involved (in OSPI_NOR_OctalMode()) :

sConfig.Match        = WRITE_ENABLE_MATCH_VALUE; // 0x02
sConfig.Mask         = WRITE_ENABLE_MASK_VALUE; // 0x02
if (HAL_OSPI_AutoPolling(hospi, &sConfig, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
      return OSPI_NOR_ERROR;
}

It return OSPI_NOR_ERROR, and I can see in my scope that the signal response for the Read Status Register command (HAL_OSPI_AutoPolling) has null values instead of WRITE_ENABLE_MATCH_VALUE and WRITE_ENABLE_MASK_VALUE.

Here's my Init function (for debug):

int Init(void) 
{
	*(uint32_t*)0xE000EDF0=0xA05F0000; //enable interrupts in debug
 
	/*  Init structs to Zero*/
	//memset((void*)0x240049b8, 0, 0x6C);
	SystemInit();
 
	//SCB->VTOR = 0x24000000 | 0x200; // change VTOR setting for H7 device (commented for flash debug)
 
	__set_PRIMASK(0); //enable interrupts
 
	HAL_Init();
 
    SystemClock_Config();
 
    MX_GPIO_Init();
    MX_OCTOSPI1_Init();
 
    BSP_OSPI_NOR_DeInit();
 
	if (BSP_OSPI_NOR_Init() != HAL_OK) 				 /* ==> OK FOR THE FIRST INIT */
	{
		__set_PRIMASK(1); //disable interrupts
		HAL_SuspendTick();
		return LOADER_FAIL;
	}
 
	if (BSP_OSPI_NOR_EnableMemoryMappedMode() != HAL_OK)
	{
		__set_PRIMASK(1); //disable interrupts
		HAL_SuspendTick();
		return LOADER_FAIL;
	}
 
    /*Trigger read access before HAL_QSPI_Abort() otherwise abort functionality gets stuck*/
    uint32_t a = *(uint32_t*) 0x90000000;
    a++;
 
    __set_PRIMASK(1); //disable interrupts
	HAL_SuspendTick();
	
	vvv at this part I repeat the above lines vvv
	[...]
	BSP_OSPI_NOR_DeInit();
	
	if (BSP_OSPI_NOR_Init() != HAL_OK) 				/* ==> fails here when called a second time here */
	{
		__set_PRIMASK(1); //disable interrupts
		HAL_SuspendTick();
		return LOADER_FAIL;
	}
	[...]
}
 
uint8_t BSP_OSPI_NOR_DeInit(void)
{
	//prepare OSPI peripheral for ST-Link Utility operations
	if (HAL_OSPI_DeInit(&hospi1) != HAL_OK)
	{
		return HAL_ERROR;
	}
	 /* System level De-initialization */
	 HAL_OSPI_MspDeInit(&hospi1);
	 return HAL_OK;
}

Did someone encounter this problem ? You will find my full functions attached

Thanks!

0 REPLIES 0