STM32H730: Enabling caching on OCTOSPI RAM crashes the program
Dear Community,
I've got STM32H730 with ext Flash on OCTOSPI2 and ext RAM (s70kl1283) on OCTOSPI1.
I call SCB_EnableICache(); and SCB_EnableDCache(); early in main, then I configure the MPU.
I've got no problems executing code from ext Flash/OCTOSPI2 when MPU is configured as follows:
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = OCTOSPI2_BASE;
MPU_InitStruct.Size = MPU_REGION_SIZE_16MB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER4;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
It has a big, measurable impact on the execution speed compared to non-cached OCTOSPI2 MPU configuration.
I can also execute code from ext RAM on OCTOSPI1 if I set MPU parameters as above, but disable buffering, caching and sharing. I tried enabling caching, enabling all options, playing with TEX LEVEL (basically trying to use various setting combinations from MPU docu in relevant Programmers Manual). I either crash on any RAM access or crash on RAM execution, depending on tested MPU settings (I didn't note precisely which setting set causes which outcome). And the CPU gets seemingly stuck in HAL TICK isr, doesn't even signal any MPU or whatever fault.
I tried invalidating cache after setting the MPU, configuring the MPU both when in bootloader or external image (when in external image, the MPU config fcn actually executes from within ITCM and problems start on 1st ext ram access).
I haven't noticed anything relevant in Errata sheet.
I'm quite lost in what direction should I investigate.
Can those problems result from a different place- namely wrongly configuring OCTISPI1 parameters for the RAM chip? I'm pretty sure thy're OK but maybe I'm overlooking something here (I also tried setting the Refresh to 0). I'm operating the RAM chip at its defaults.
hospi1.Instance = OCTOSPI1;
hospi1.Init.FifoThreshold = 1;
hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_APMEMORY;
hospi1.Init.DeviceSize = 24;
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_32_BYTES;
hospi1.Init.ClockPrescaler = 4;
hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE;
hospi1.Init.ChipSelectBoundary = 10;
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_USED;
hospi1.Init.MaxTran = 0;
hospi1.Init.Refresh = 200;
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
{
Error_Handler();
}
sOspiManagerCfg.ClkPort = 1;
sOspiManagerCfg.DQSPort = 1;
sOspiManagerCfg.NCSPort = 1;
sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
sOspiManagerCfg.IOHighPort = HAL_OSPIM_IOPORT_1_HIGH;
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
I'd be grateful for any tips what could I check more or what I may be doing wrong.
PS- now that I think of it, the "stuck in HAL tick isr" without fault may be because I got to the point where bootloader jumps to ext ram, but waits indefinitely to fetch instructions for some reason. VTOR is not remapped yet so still points to bootloader ISRs so HAL tick gets fired periodically. Which would be weird because I do call HAL_SuspendTick before jumping, but well... As I said I'm a bit lost here.
