Skip to content

Commit b658172

Browse files
authored
Merge pull request #2 from glindstedt/expose-structs
Export FmcSdramConfiguration and FmcSdramTiming structs
2 parents 4e18ac3 + e57df99 commit b658172

File tree

7 files changed

+91
-16
lines changed

7 files changed

+91
-16
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ TODO
8888

8989
TODO
9090

91+
### Implementing a new device
92+
93+
If you end up depending on a fork or a newer version of this crate than the
94+
HAL crate for your device, you can override the version pulled in by the
95+
external crate using a `[patch]` section in your `Cargo.toml`, as described
96+
in the
97+
[Cargo Book](https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section).
98+
9199
## Releasing
92100

93101
* Update Cargo.toml

src/devices/is42s16400j.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/// Speed Grade 7
55
pub mod is42s16400j_7 {
6-
use crate::sdram::{FmcSdramConfiguration, FmcSdramTiming, SdramChip};
6+
use crate::sdram::{SdramChip, SdramConfiguration, SdramTiming};
77

88
const BURST_LENGTH_1: u16 = 0x0000;
99
const BURST_LENGTH_2: u16 = 0x0001;
@@ -32,7 +32,7 @@ pub mod is42s16400j_7 {
3232
| WRITEBURST_MODE_SINGLE;
3333

3434
/// Timing Parameters
35-
const TIMING: FmcSdramTiming = FmcSdramTiming {
35+
const TIMING: SdramTiming = SdramTiming {
3636
startup_delay_ns: 100_000, // 100 µs
3737
max_sd_clock_hz: 100_000_000, // 100 MHz
3838
refresh_period_ns: 15_625, // 64ms / (4096 rows) = 15625ns
@@ -45,7 +45,7 @@ pub mod is42s16400j_7 {
4545
};
4646

4747
/// SDRAM controller configuration
48-
const CONFIG: FmcSdramConfiguration = FmcSdramConfiguration {
48+
const CONFIG: SdramConfiguration = SdramConfiguration {
4949
column_bits: 8,
5050
row_bits: 12,
5151
memory_data_width: 16, // 16-bit

src/devices/is42s32800g.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/// Speed Grade 6
55
pub mod is42s32800g_6 {
6-
use crate::sdram::{FmcSdramConfiguration, FmcSdramTiming, SdramChip};
6+
use crate::sdram::{SdramChip, SdramConfiguration, SdramTiming};
77

88
const BURST_LENGTH_1: u16 = 0x0000;
99
const BURST_LENGTH_2: u16 = 0x0001;
@@ -30,7 +30,7 @@ pub mod is42s32800g_6 {
3030
| WRITEBURST_MODE_SINGLE;
3131

3232
/// Timing Parameters
33-
const TIMING: FmcSdramTiming = FmcSdramTiming {
33+
const TIMING: SdramTiming = SdramTiming {
3434
startup_delay_ns: 100_000, // 100 µs
3535
max_sd_clock_hz: 100_000_000, // 100 MHz
3636
refresh_period_ns: 15_625, // 64ms / (4096 rows) = 15625ns
@@ -43,7 +43,7 @@ pub mod is42s32800g_6 {
4343
};
4444

4545
/// SDRAM controller configuration
46-
const CONFIG: FmcSdramConfiguration = FmcSdramConfiguration {
46+
const CONFIG: SdramConfiguration = SdramConfiguration {
4747
column_bits: 9,
4848
row_bits: 12,
4949
memory_data_width: 32, // 32-bit

src/devices/mt48lc4m32b2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
/// Speed Grade 6
77
pub mod mt48lc4m32b2_6 {
8-
use crate::sdram::{FmcSdramConfiguration, FmcSdramTiming, SdramChip};
8+
use crate::sdram::{SdramChip, SdramConfiguration, SdramTiming};
99

1010
const BURST_LENGTH_1: u16 = 0x0000;
1111
const BURST_LENGTH_2: u16 = 0x0001;
@@ -32,7 +32,7 @@ pub mod mt48lc4m32b2_6 {
3232
| WRITEBURST_MODE_SINGLE;
3333

3434
/// Timing Parameters
35-
const TIMING: FmcSdramTiming = FmcSdramTiming {
35+
const TIMING: SdramTiming = SdramTiming {
3636
startup_delay_ns: 100_000, // 100 µs
3737
max_sd_clock_hz: 100_000_000, // 100 MHz
3838
refresh_period_ns: 15_625, // 64ms / (4096 rows) = 15625ns
@@ -45,7 +45,7 @@ pub mod mt48lc4m32b2_6 {
4545
};
4646

4747
/// SDRAM controller configuration
48-
const CONFIG: FmcSdramConfiguration = FmcSdramConfiguration {
48+
const CONFIG: SdramConfiguration = SdramConfiguration {
4949
column_bits: 9,
5050
row_bits: 12,
5151
memory_data_width: 32, // 32-bit

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ pub use fmc::*;
140140
#[cfg(feature = "sdram")]
141141
mod sdram;
142142
#[cfg(feature = "sdram")]
143-
pub use sdram::{PinsSdram, Sdram, SdramChip, SdramPinSet, SdramTargetBank};
143+
pub use sdram::{
144+
PinsSdram, Sdram, SdramChip, SdramConfiguration, SdramPinSet,
145+
SdramTargetBank, SdramTiming,
146+
};
144147

145148
/// Memory device definitions
146149
pub mod devices;

src/sdram.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::ral::{fmc, modify_reg, write_reg};
1313

1414
/// FMC SDRAM Configuration Structure definition
1515
#[derive(Clone, Copy, Debug, PartialEq)]
16-
pub struct FmcSdramConfiguration {
16+
pub struct SdramConfiguration {
1717
/// Number of bits of column address
1818
pub column_bits: u8,
1919
/// Number of bits of column address
@@ -34,7 +34,7 @@ pub struct FmcSdramConfiguration {
3434

3535
/// FMC SDRAM Timing parameters structure definition
3636
#[derive(Clone, Copy, Debug, PartialEq)]
37-
pub struct FmcSdramTiming {
37+
pub struct SdramTiming {
3838
/// Time between applying a valid clock and any command other than
3939
/// COMMAND INHIBIT or NOP
4040
pub startup_delay_ns: u32,
@@ -62,10 +62,10 @@ pub trait SdramChip {
6262
const MODE_REGISTER: u16;
6363

6464
/// SDRAM controller configuration
65-
const CONFIG: FmcSdramConfiguration;
65+
const CONFIG: SdramConfiguration;
6666

6767
/// Timing parameters
68-
const TIMING: FmcSdramTiming;
68+
const TIMING: SdramTiming;
6969
}
7070

7171
/// SDRAM Controller
@@ -338,8 +338,8 @@ impl<IC: SdramChip, FMC: FmcPeripheral> Sdram<FMC, IC> {
338338
/// For example, see RM0433 rev 7 Section 22.9.3
339339
unsafe fn set_features_timings(
340340
&mut self,
341-
config: FmcSdramConfiguration,
342-
timing: FmcSdramTiming,
341+
config: SdramConfiguration,
342+
timing: SdramTiming,
343343
sd_clock_divide: u32,
344344
) {
345345
// Features ---- SDCR REGISTER

tests/sdram_pin.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,67 @@ fn sdram_pins_12a_4b_not_enough_bank_pins() {
100100
// Check we can create a SDRAM
101101
Sdram::new(fmc, pins, chip);
102102
}
103+
104+
#[derive(Clone, Copy, Debug, PartialEq)]
105+
pub struct DummyChip {}
106+
107+
const BURST_LENGTH_1: u16 = 0x0000;
108+
const BURST_TYPE_SEQUENTIAL: u16 = 0x0000;
109+
const CAS_LATENCY_3: u16 = 0x0030;
110+
const OPERATING_MODE_STANDARD: u16 = 0x0000;
111+
const WRITEBURST_MODE_SINGLE: u16 = 0x0200;
112+
113+
impl SdramChip for DummyChip {
114+
const MODE_REGISTER: u16 = BURST_LENGTH_1
115+
| BURST_TYPE_SEQUENTIAL
116+
| CAS_LATENCY_3
117+
| OPERATING_MODE_STANDARD
118+
| WRITEBURST_MODE_SINGLE;
119+
120+
const CONFIG: stm32_fmc::SdramConfiguration = SdramConfiguration {
121+
column_bits: 9,
122+
row_bits: 12,
123+
memory_data_width: 32, // 32-bit
124+
internal_banks: 4, // 4 internal banks
125+
cas_latency: 3, // CAS latency = 3
126+
write_protection: false,
127+
read_burst: true,
128+
read_pipe_delay_cycles: 0,
129+
};
130+
131+
const TIMING: stm32_fmc::SdramTiming = SdramTiming {
132+
startup_delay_ns: 100_000, // 100 µs
133+
max_sd_clock_hz: 100_000_000, // 100 MHz
134+
refresh_period_ns: 15_625, // 64ms / (4096 rows) = 15625ns
135+
mode_register_to_active: 2, // tMRD = 2 cycles
136+
exit_self_refresh: 7, // tXSR = 70ns
137+
active_to_precharge: 4, // tRAS = 42ns
138+
row_cycle: 7, // tRC = 70ns
139+
row_precharge: 2, // tRP = 18ns
140+
row_to_column: 2, // tRCD = 18ns
141+
};
142+
}
143+
144+
#[test]
145+
/// Test that we can implement the SdramChip trait
146+
fn sdram_chip_impl() {
147+
let fmc = DummyFMC {};
148+
let pins = fmc_pin_set!(
149+
// 12 address bits
150+
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11,
151+
// 4 internal banks --------------------------------------
152+
BA0, BA1,
153+
// 32 bit data -------------------------------------------
154+
D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
155+
D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29,
156+
D30, D31,
157+
// NBL0-3 ------------------------------------------------
158+
NBL0, NBL1, NBL2, NBL3,
159+
// SDRAM Bank 0 ------------------------------------------
160+
SDCKE0, SDCLK, SDNCAS, SDNE0, SDNRAS, SDNWE
161+
);
162+
let chip = DummyChip {};
163+
164+
// Check we can create a SDRAM
165+
Sdram::new(fmc, pins, chip);
166+
}

0 commit comments

Comments
 (0)