cancel
Showing results for 
Search instead for 
Did you mean: 

BSP_OSPI_NOR_Erase_Block() fails

Tomasz Ozon
Associate III

I've created a project using STM32H7B3I-DK eval board with all settings default, unmodified, taken from TouchGFX. UI menu is working fine with some resources stored in OSPI Flash memory.

Now I wish to store some data in this OSPI memory. The procedure should be to disable Memory Mapped Mode, erase, write and enable Memory Mapped Mode again. All this I do with task switch disabled so that TouchGFX doesn't access OSPI Flash during the process. But BSP_OSPI_NOR_Erase_Block() returns error.

Ccalled are MX25LM51245G_BlockErase()

then HAL_OSPI_Command()

then status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_TC, SET, tickstart, Timeout);

and here timeout is reported.

I've tried to erase OSPI Flash even before TouchGFX is started and it fails too.

Here is my simple code called from main with just one modification:

static void MX_OCTOSPI1_Init(void)

{

 /* USER CODE BEGIN OCTOSPI1_Init 0 */

 /* USER CODE END OCTOSPI1_Init 0 */

 /* USER CODE BEGIN OCTOSPI1_Init 1 */

 /* USER CODE END OCTOSPI1_Init 1 */

 /* OCTOSPI1 parameter configuration*/

 hospi1.Instance = OCTOSPI1;

 hospi1.Init.FifoThreshold = 1;

 hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;

 hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON;

 hospi1.Init.DeviceSize = 26;

 hospi1.Init.ChipSelectHighTime = 2;

 hospi1.Init.FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE;

 hospi1.Init.ClockMode = HAL_OSPI_CLOCK_MODE_0;

 hospi1.Init.WrapSize = HAL_OSPI_WRAP_NOT_SUPPORTED;

 hospi1.Init.ClockPrescaler = 3;

 hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;

 hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_DISABLE;

 hospi1.Init.ChipSelectBoundary = 0;

 hospi1.Init.ClkChipSelectHighTime = 0;

 hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_BYPASSED;

 hospi1.Init.MaxTran = 0;

 hospi1.Init.Refresh = 0;

 if (HAL_OSPI_Init(&hospi1) != HAL_OK)

 {

   Error_Handler();

 }

 /* USER CODE BEGIN OCTOSPI1_Init 2 */

 BSP_OSPI_NOR_Init_t Flash;

 Flash.InterfaceMode = BSP_OSPI_NOR_OPI_MODE;

 Flash.TransferRate = BSP_OSPI_NOR_DTR_TRANSFER;

 BSP_OSPI_NOR_DeInit(0);

 int32_t RetVal = BSP_OSPI_NOR_Init(0, &Flash);

 if(RetVal != BSP_ERROR_NONE)

 {

   Error_Handler();

 }

/**************************************************************/

 BSP_OSPI_NOR_Erase_Block(0, 0x90000200, MX25LM51245G_ERASE_4K); //that's the only modification, it fails with timeout, then enabling memory mapped mode below fails too

/**************************************************************/

 RetVal = BSP_OSPI_NOR_EnableMemoryMappedMode(0);

 if(RetVal != BSP_ERROR_NONE)

 {

   Error_Handler();

 }

 /* USER CODE END OCTOSPI1_Init 2 */

}

1 ACCEPTED SOLUTION

Accepted Solutions
Tomasz Ozon
Associate III

Answering to myself:

everything is working fine, the simple mistake was in my address calculation. BSP_OSPI_NOR_...() functions must get Flash Memory address starting from 0 and not with +0x90000000 offset, as CPU sees it.

So I can confirm, that switching from Memory Mapped Mode, erasing, writing and enabling MMM again is fully functional.

View solution in original post

3 REPLIES 3
Tomasz Ozon
Associate III

Answering to myself:

everything is working fine, the simple mistake was in my address calculation. BSP_OSPI_NOR_...() functions must get Flash Memory address starting from 0 and not with +0x90000000 offset, as CPU sees it.

So I can confirm, that switching from Memory Mapped Mode, erasing, writing and enabling MMM again is fully functional.

OLync.1
Associate III

Hi @Tomasz Ozon​ I just wanted to say thanks for posting your answer as this was exactly my problem and your post saved me untold hours in solving this!

Yes

sCommand.Address = Address & 0x0FFFFFFF; // 256 MB masking

One should also watch this on the External Loaders, and probably ensure all checks and comparisons are done with masked addresses. Things passed in are not always zero based, the Erase range has caused me headaches in the past. Might have been fixed along the way.

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