STM32H7B3I-DK OctoSPI Memory Mapped Mode disable/enable problem
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.
I have problems with switching from Memory Mapped Mode to Indirect Mode and returning to MMP again.
I have modified MX_OCTOSPI1_Init() function by adding a test loop at the end to use it as a test procedure (memory settings are not modified).
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();
}
RetVal = BSP_OSPI_NOR_EnableMemoryMappedMode(0);
if(RetVal != BSP_ERROR_NONE)
{
Error_Handler();
}
//test loop
#define BLOCK_SIZE 4096
static uint8_t blockBuf[BLOCK_SIZE];
for(int i = 5; i < 15; i++)
{
bool ok = true;
if(BSP_OSPI_NOR_DisableMemoryMappedMode(0) != BSP_ERROR_NONE) ok = false;
if(BSP_OSPI_NOR_Erase_Block(0, 0, MX25LM51245G_ERASE_4K) != BSP_ERROR_NONE) ok = false;
if(BSP_OSPI_NOR_EnableMemoryMappedMode(0) != BSP_ERROR_NONE) ok = false;
memcpy(blockBuf, (uint8_t*)0x90000000, BLOCK_SIZE);
//now I expect to see 0xff... in the buffer
if(BSP_OSPI_NOR_DisableMemoryMappedMode(0) != BSP_ERROR_NONE) ok = false;
memset(blockBuf, i, BLOCK_SIZE); //put some data to the buffer
if(BSP_OSPI_NOR_Write(0, blockBuf, 0, BLOCK_SIZE) != BSP_ERROR_NONE) ok = false;
memset(blockBuf, 0, BLOCK_SIZE); //clear buffer
if(BSP_OSPI_NOR_EnableMemoryMappedMode(0) != BSP_ERROR_NONE) ok = false;
memcpy(blockBuf, (uint8_t*)0x90000000, BLOCK_SIZE);
//now I expect to see data in the buffer, but I see 0xff...
}
/* USER CODE END OCTOSPI1_Init 2 */
}
I can see memory block being erased, but not written. If I remove Memory Mapped Mode enter/exit functions memory erase and write works fine.
Do you know a reason for that?
