2025-04-10 1:03 PM - last edited on 2025-04-10 1:08 PM by mƎALLEm
Hi,
My board consists of stm32h733 that interfaces SDRAM via FMC. I want to execute code from SDRAM. Code is loaded from external flash(OCTOSPI) to SDRAM at address 0xc0700000.
But running the code from this region causes hard-fault disabling the Debug Port. After this I'm unable to flash firmware into the hardware. I have to bring board into "connection under reset" by connecting BOOT0 to 3.3v and NRST to GND. I have tried with multiple test firmware but always got into hard-fault. Why MCU disables, it's debug port?
While debugging in the disassembly I can execute firmware running from SDRAM one by one line, but at some point code hard-fault, causing it to stuck into the above told situation. Here is the MPU config for SDRAM;
/* Configure the MPU attributes for SDRAM */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0xC0000000; // Start address of SDRAM Bank 1
MPU_InitStruct.Size = MPU_REGION_SIZE_8MB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER3; // MPU region number
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
Why am I not able to execute code from SDRAM after jump from bootloader???
Thanks,
Umair
2025-04-10 1:56 PM
Perhaps Instrument your code, via output to the serial port, and have a HardFault Handler that outputs actionable information from the running system.
The SDRAM will not be working until initialized, the debugger typically doesn't bring it up. Ideally it would be done in SystemInit() so it would work for static copies and initialization, and by the time you hit main()
Determine what instruction and address is actually faulting, and let's diagnose the issue from there..
2025-04-10 5:47 PM
Since you can access and execute SDRAM during debug, seems MPU config and overall code is fine.
> While debugging in the disassembly I can execute firmware running from SDRAM one by one line, but at some point code hard-fault,
At what point does it hard fault?
Does SDRAM pass sanity checks for read/write access over the entire region?
2025-04-11 4:02 AM - edited 2025-04-11 4:58 AM
> The SDRAM will not be working until initialized, the debugger typically doesn't bring it up. Ideally it would be done in SystemInit() so it would work for static copies and initialization, and by the time you hit main()
Are you talking about SDRAM initialization in bootloader or application. SDRAM is being initialized in bootloader and I can successfully perform erase/read/write operations to it. Do I have to reinitialize the SDRAM from application, or if the initialization done in bootloader will be enough? Although I have also tried by disabling the FMC in application, but that also didn't work.
> At what point does it hard fault?
I would like to add a point here, while line by line execution. The stack got loaded with 0xdeadbeee after the instruction 0xC070059A(in case of blinky test application as I have update the Flash address to 0xC0700000 in ld file(is this right?)) got executed. As I have seen this behavior with multiple test firmwares, the issue seems to be related to applications'(MCU) Startup code after jump.
> Does SDRAM pass sanity checks for read/write access over the entire region?
I'm not sure what do you mean by SDRAM's sanity checks but in bootloader, I'm able to erase the last MB of the SDRAM, move code from external flash to SDRAM. I have also verified the content of flashed binary with external flash as well as SDRAM.