Skip to main content
Associate III
September 26, 2025
Question

STM32N6 SDRAM CLK is inactive

  • September 26, 2025
  • 1 reply
  • 581 views

Hello,
I cant start SDRAM to work, I ques what FMC controller do not initialize interface correctly because CLK is dead (bug !?), there is no activity at all, I connected oscilloscope to CLK output to check, if I toggle manually the pin PD9 (FMC_SDCLK) is changing state, there is no difference what frequency is set and what is RCC source, now CLK is set to 50Mhz, source IC4 100Mhz, similar code on H7 works without problems even if frequency is to high for my SDRAM 143Mhz (tested - works well up to ~165Mhz), there is initialization code:

static void MX_FMC_Init(void){
 /* USER CODE BEGIN FMC_Init 0 */
 /* USER CODE END FMC_Init 0 */
 FMC_SDRAM_TimingTypeDef SdramTiming = {0};
 /* USER CODE BEGIN FMC_Init 1 */
 /* USER CODE END FMC_Init 1 */
 /** 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_9;
 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_2;
 hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
 hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
 hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_2;
 /* SdramTiming */
 SdramTiming.LoadToActiveDelay = 2;
 SdramTiming.ExitSelfRefreshDelay = 7;
 SdramTiming.SelfRefreshTime = 4;
 SdramTiming.RowCycleDelay = 7;
 SdramTiming.WriteRecoveryTime = 3;
 SdramTiming.RPDelay = 2;
 SdramTiming.RCDDelay = 2;

 if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK){
 Error_Handler( );
 }
 /* USER CODE BEGIN FMC_Init 2 */
 //-----------------------------------------------------------------------------------
 FMC_SDRAM_CommandTypeDef Command;
 Command.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; /* Set MODE bits to "001" */
 Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; /* configure the Target Bank bits */
 Command.AutoRefreshNumber = 1;
 Command.ModeRegisterDefinition = 0;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
 HAL_Delay(1); /* Step 4: Insert 100 us minimum delay - Min HAL Delay is 1ms */

 Command.CommandMode = FMC_SDRAM_CMD_PALL; /* Set MODE bits to "010" */
 Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; /* configure the Target Bank bits */
 Command.AutoRefreshNumber = 1;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);

 Command.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; /* Set MODE bits to "011" */
 Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; /* configure the Target Bank bits */
 Command.AutoRefreshNumber = 2; // 2 8
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);

 Command.CommandMode = FMC_SDRAM_CMD_LOAD_MODE;/*set the MODE bits to "100" */
 Command.CommandTarget		 = FMC_SDRAM_CMD_TARGET_BANK1;
 Command.AutoRefreshNumber = 1;
 //Command.ModeRegisterDefinition = (uint32_t) SDRAM_MODEREG_BURST_LENGTH_1 | SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | SDRAM_MODEREG_CAS_LATENCY_3 | SDRAM_MODEREG_OPERATING_MODE_STANDARD | SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
 Command.ModeRegisterDefinition = (uint32_t)0 | 0<<3 | 2<<4 | 0<<7 | 1<<9;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);

 uint32 freqsdrm = (50000 * 64 / 8192) - 20;
 HAL_SDRAM_ProgramRefreshRate(&hsdram1, freqsdrm); // 2058 = 133, 1933 1542

 /* USER CODE END FMC_Init 2 */
}

 

1 reply

Associate III
September 28, 2025

I found the problem, in HAL_SDRAM_Init() function the SDRAM control registers for SDRAM device 1 (FMC_SDCR1) the bit 16 (SDEN) is not enabled/set in function, you have to enable to get FMC to work, but still there is some problem with frequency, I have set IC14 to 280 and FMC SDRAM common clock to 2, but SDCLK output is only 8Mhz !  With H7 mcu I dont had such problems !
This MCU is good, but SW is full of bugs !

Ghofrane GSOURI
Technical Moderator
October 3, 2025

Hello @TheImmortal 

Regarding the first point " Missing code for enabling the SDEN " , an internal Ticket 218981 has been raised to our dev team  for further investigation.

For the second point, could you please provide your IOC file? This will allow me to review your configuration in detail and help identify the cause of the issue.

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Ghofrane GSOURI
Technical Moderator
October 8, 2025

Hello @TheImmortal 

I am sharing with you the explanation provided by our expert:

The SDEN bit is set in the SystemInit_ExtMemCtl() function, which is called by SystemInit().

Indeed, FMC_SDRAM_DataMemory() is an advanced example that shows to the customer how to bypass the internal SRAM and how to use only the SDRAM available on the external memory.

This is why, BEFORE entering main(), the SDRAM is fully initialized and enabled by direct register accesses, done in SystemInit().

Once the code starts executing in main(), the SDRAM is up and running and replaces the internal SRAM.

And this is why the initialization must be done as early as possible.
Since CubeMX does not automatically generate a call to SystemInit_ExtMemCtl(), you should manually add the following line of code:
FMC_Bank5_6_R->SDCR[0] |= FMC_SDCRx_SDEN;

 

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.