Skip to content

Commit c7d6ee4

Browse files
pat-rogersjklmnn
authored andcommitted
Fix SDRAM timing setup parameters
We now compute them from the datasheet constants. Specifically, in procedure Initialize: * ExitSelfRefreshDelay, SelfRefreshTime, and RowCycleDelay were all derived from a single SDRAM_Min_Delay_In_ns constant, collapsing three distinct timing constraints (TXSR, TRAS, TRC) into one value. SelfRefreshTime was also hardcoded to 4 cycles, valid only at 90 MHz SDCLK. * Replace with per-parameter ceiling division over named board constants (SDRAM_TXSR_In_Ns, SDRAM_TRAS_In_Ns, SDRAM_TRC_In_Ns) so each constraint is satisfied independently at any clock frequency. STM32.Board spec: * add new SDRAM constants for the sake of the SDRAM initialization
1 parent 95a8ae7 commit c7d6ee4

2 files changed

Lines changed: 15 additions & 19 deletions

File tree

boards/stm32_common/sdram/stm32-sdram.adb

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
------------------------------------------------------------------------------
22
-- --
3-
-- Copyright (C) 2015-2016, AdaCore --
3+
-- Copyright (C) 2015-2026, AdaCore --
44
-- --
55
-- Redistribution and use in source and binary forms, with or without --
66
-- modification, are permitted provided that the following conditions are --
@@ -141,9 +141,7 @@ package body STM32.SDRAM is
141141
SDRAM_Conf : FMC_SDRAM_Init_Config;
142142
SDCLK : constant Unsigned_32 :=
143143
Unsigned_32 (STM32.Device.System_Clock_Frequencies.SYSCLK / 2);
144-
SDPeriod_In_ns : constant Unsigned_32 :=
145-
1_000_000_000 / SDCLK;
146-
Refresh_Delay : Unsigned_32;
144+
SDPeriod_In_Ns : constant Unsigned_32 := 1_000_000_000 / SDCLK;
147145

148146
begin
149147
if Initialized then
@@ -171,22 +169,19 @@ package body STM32.SDRAM is
171169
-- 100 MHz of SD clock frequency (200MHz / 2)
172170
-- 1 Clock cycle = 1 / 100MHz = 10ns
173171

174-
Refresh_Delay :=
175-
(SDRAM_Min_Delay_In_ns - SDPeriod_In_ns + 1) / SDPeriod_In_ns;
176-
177172
Timing_Conf :=
178173
(
179174
-- 2 Clock cycles for Load to Active delay
180175
LoadToActiveDelay => 2,
181176

182-
-- min = 60ns: 6 * 10.0
183-
ExitSelfRefreshDelay => FMC_SDRAM_Timing (Refresh_Delay),
184-
185-
-- in range [42ns, 120k ns] => using 4 * 11.1 ns
186-
SelfRefreshTime => 4,
187-
188-
-- min = 60ns
189-
RowCycleDelay => FMC_SDRAM_Timing (Refresh_Delay),
177+
-- Each timing parameter is computed as a cycle count by dividing the
178+
-- required minimum time (in ns) by the SDCLK period, using ceiling
179+
-- division to ensure the minimum is always satisfied regardless of
180+
-- clock frequency. The timing constants are defined in STM32.Board
181+
-- and reflect the IS42S32400F SDRAM datasheet specifications.
182+
ExitSelfRefreshDelay => FMC_SDRAM_Timing ((SDRAM_TXSR_In_Ns + SDPeriod_In_Ns - 1) / SDPeriod_In_Ns),
183+
SelfRefreshTime => FMC_SDRAM_Timing ((SDRAM_TRAS_In_Ns + SDPeriod_In_Ns - 1) / SDPeriod_In_Ns),
184+
RowCycleDelay => FMC_SDRAM_Timing ((SDRAM_TRC_In_Ns + SDPeriod_In_Ns - 1) / SDPeriod_In_Ns),
190185

191186
-- min = 20ns
192187
WriteRecoveryTime => 2,
@@ -241,8 +236,7 @@ package body STM32.SDRAM is
241236
begin
242237
Initialize;
243238
Rounded_Size := Amount + Align;
244-
Rounded_Size :=
245-
Rounded_Size - Rounded_Size rem Align;
239+
Rounded_Size := Rounded_Size - Rounded_Size rem Align;
246240

247241
G_Base_Addr := G_Base_Addr + Rounded_Size;
248242

boards/stm32_common/stm32f746disco/stm32-board.ads

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
------------------------------------------------------------------------------
22
-- --
3-
-- Copyright (C) 2015-2018, AdaCore --
3+
-- Copyright (C) 2015-2026, AdaCore --
44
-- --
55
-- Redistribution and use in source and binary forms, with or without --
66
-- modification, are permitted provided that the following conditions are --
@@ -116,7 +116,9 @@ package STM32.Board is
116116
SDRAM_Read_Pipe : constant STM32.FMC.FMC_SDRAM_Read_Pipe_Delay :=
117117
STM32.FMC.FMC_ReadPipe_Delay_0;
118118
SDRAM_Refresh_Cnt : constant := 1539;
119-
SDRAM_Min_Delay_In_ns : constant := 60;
119+
SDRAM_TRAS_In_Ns : constant := 42; -- IS42S32400F min self-refresh time
120+
SDRAM_TRC_In_Ns : constant := 60; -- IS42S32400F min row cycle time
121+
SDRAM_TXSR_In_Ns : constant := 70; -- IS42S32400F min exit self-refresh delay
120122

121123
---------
122124
-- I2C --

0 commit comments

Comments
 (0)