cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 - external SDRAM on FMC - optimal configuration for code execution

VZolt.1
Associate II

We have a STM32H745 MCU, an IS45S16320F SDRAM on the FMC interface, which is used for a Codesys application code execution.

  • This is the SDRAM init:
/** Perform the SDRAM1 memory initialization sequence
	 */
	hsdram1.Instance = FMC_SDRAM_DEVICE;
	/* hsdram1.Init */
	hsdram1.Init.SDBank = FMC_SDRAM_BANK1;
	hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_10;
	hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13;
	hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
	hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
	hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
	hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
	hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
	hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
	hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
	/* SdramTiming */
	SdramTiming.LoadToActiveDelay = 2;
	SdramTiming.ExitSelfRefreshDelay = 6;
	SdramTiming.SelfRefreshTime = 4;
	SdramTiming.RowCycleDelay = 6;
	SdramTiming.WriteRecoveryTime = 2;
	SdramTiming.RPDelay = 2;
	SdramTiming.RCDDelay = 2;
 
	if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
	{
		debug("CM7:ERROR_SDRAM_INIT");PrintLog();
		SfMode_vSwitchToSafeMode( );
	}
 
	/* USER CODE BEGIN FMC_Init 2 */
	/* Program the SDRAM external device */
	SDRAM_Initialization_Sequence(&hsdram1, &command);
	/* USER CODE END FMC_Init 2 */

  • Following is linker file setting:

RAM_EXT_CODE (xrw)    : ORIGIN = 0x70000000, LENGTH = 16M

  • Following is MPU setting:

   MPU_InitStruct.Enable = MPU_REGION_ENABLE;
    MPU_InitStruct.Number = MPU_REGION_NUMBER5;
    MPU_InitStruct.BaseAddress = 0x70000000;
    MPU_InitStruct.Size = MPU_REGION_SIZE_16MB;
    MPU_InitStruct.SubRegionDisable = 0x0;
    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_NOT_BUFFERABLE;
 
    HAL_MPU_ConfigRegion(&MPU_InitStruct);
  • Cache is enabled in the main.c

/* Enable the CPU Cache */

  CPU_CACHE_Enable();

static void CPU_CACHE_Enable(void)

{

  /* Enable I-Cache */

  SCB_EnableICache();

  /* Enable D-Cache */

  SCB_EnableDCache();

}

Question would be, do you find these settings as being optimal for this purpose, of running code from the external SDRAM? Especially those related to the L1-Cache and MPU settings.

Thanks in advance,

Zoltan

0 REPLIES 0