mojinpan 发表于 2022-6-11 12:57:31

STM32H7 SDRAM启动的坑

       最近在尝试将程序转移到SDRAM来运行,发现有一些坑,分享给大家:

1.bootloader将程序搬运到SDRAM并跳转后发现SDRAM所有数据都变成AA.调试后发现问题是在新版本驱动中SystemInit()存在禁用FMC的代码

void SystemInit (void)
{
#if defined (DATA_IN_D2_SRAM)
__IO uint32_t tmpreg;
#endif /* DATA_IN_D2_SRAM */

/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2)));/* set CP10 and CP11 Full Access */
#endif
/* Reset the RCC clock configuration to the default reset state ------------*/
....

#if defined(DUAL_CORE) && defined(CORE_CM4)
/* Configure the Vector Table location add offset address for cortex-M4 ------------------*/
#if defined(USER_VECT_TAB_ADDRESS)
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal D2 AXI-RAM or in Internal FLASH */
#endif /* USER_VECT_TAB_ADDRESS */

#else

/*
   * Disable the FMC bank1 (enabled after reset).
   * This, prevents CPU speculation access on this bank which blocks the use of FMC during
   * 24us. During this time the others FMC master (such as LTDC) cannot use it!
   */
FMC_Bank1_R->BTCR = 0x000030D2;//此处会禁用FMC,到时SDRAM,必须注释掉才能SDRAM启动

/* Configure the Vector Table location -------------------------------------*/
#if defined(USER_VECT_TAB_ADDRESS)
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal D1 AXI-RAM or in Internal FLASH */
#endif /* USER_VECT_TAB_ADDRESS */

#endif /*DUAL_CORE && CORE_CM4*/

}

2.如果希望SystemInit()来帮自己设置中断向量的位置,需要设定宏定义USER_VECT_TAB_ADDRESS=0xD0000000U,这个是和以前不同的

3.官方的ExtMem_CodeExecution范例程序里面,其实在SystemInit()是有一个SystemInit_ExtMemCtl(),提前初始化SDRAM,这样是可以解决__main()无法将RW和RO数据释放到SDRAM的问题

eric2013 发表于 2022-6-11 16:06:22

谢谢分享。

emwin 发表于 2022-6-11 23:17:16

如楼主所说,确实,C启动代码Execution region的加载是核心。

zff0414 发表于 2024-1-25 16:36:47

感谢老哥,卡了三天的问题,终于解决了
页: [1]
查看完整版本: STM32H7 SDRAM启动的坑