Unable to execute code in SDRAM on STM32H745
Hi all,
Board: STM32H745I-DISCO
IDE: 1.16.1
I am facing some issues with trying to execute code on the SDRAM. I have a 2nd stage bootloader that loads the user application onto QSPI located at 0x9000 0000. After that, I copy the user application code to the SDRAM 0xD0000000. This part works as verified in the debugger.
However when I try to jump to the SDRAM address, my program is not executing. And it seems like the SDRAM has lost connection? Attached below is the image(sdram_becomes_unreadable.PNG) where my bootloader jumped to the SDRAM address but unable to read from the SDRAM. There is no hard fault..
Background:
I have tried to load the user application onto QSPI and jump to the QSPI address, my program executes successfully.
I have checked my MPU configuration to make sure that SDRAM is MPU_INSTRUCTION_ACCESS_ENABLE.
Below is my MPU configuration
void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct = {0};
/* Disables the MPU */
HAL_MPU_Disable();
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.BaseAddress = 0x90000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_128MB;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
MPU_InitStruct.BaseAddress = 0xD0000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_64MB;
MPU_InitStruct.SubRegionDisable = 0x0;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
Lastly, I tried to bank swap the SDRAM to 0x70000000, and execute from there incase the SDRAM is still in Execute Never(XN) mode. But this doesn't work too as the SDRAM is unreadable after the jump.
What am I missing? Do I need to initialize the SDRAM for my user application? How come this is not needed for QSPI in such a scenario?
Regards,
Reuben Goh
