Skip to content

Commit 4624628

Browse files
bors[bot]ryan-summersjordens
authored
Merge #76
76: Add quadspi r=ryan-summers a=jordens @ryan-summers I went ahead and drafted this PR to be able to discuss it. Co-authored-by: Ryan Summers <[email protected]> Co-authored-by: Robert Jördens <[email protected]>
2 parents 99fe504 + 1218ec6 commit 4624628

File tree

7 files changed

+609
-4
lines changed

7 files changed

+609
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
with:
3333
use-cross: true
3434
command: build
35-
args: --verbose --release --examples --target thumbv7em-none-eabihf --features rt,${{ matrix.mcu }}
35+
args: --verbose --release --examples --target thumbv7em-none-eabihf --features rt,quadspi,${{ matrix.mcu }}
3636
- uses: actions-rs/cargo@v1
3737
with:
3838
command: test
39-
args: --lib --target x86_64-unknown-linux-gnu --features rt,${{ matrix.mcu }}
39+
args: --lib --target x86_64-unknown-linux-gnu --features rt,${{ matrix.mcu }},quadspi

.github/workflows/nightly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
with:
2121
use-cross: true
2222
command: build
23-
args: --verbose --release --examples --target thumbv7em-none-eabihf --features rt,stm32h743v
23+
args: --verbose --release --examples --target thumbv7em-none-eabihf --features rt,stm32h743v,quadspi
2424
- uses: actions-rs/cargo@v1
2525
with:
2626
command: test
27-
args: --lib --target x86_64-unknown-linux-gnu --features rt,stm32h743v
27+
args: --lib --target x86_64-unknown-linux-gnu --features rt,stm32h743v,quadspi

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ dualcore = []
5050
dsi = []
5151
cm4 = []
5252
cm7 = []
53+
quadspi = []
5354
rt = ["stm32h7/rt"]
5455
stm32h742 = ["stm32h7/stm32h743", "device-selected", "singlecore"]
5556
stm32h743 = ["stm32h7/stm32h743", "device-selected", "singlecore"]
@@ -84,3 +85,7 @@ required-features = ["rt"]
8485
[[example]]
8586
name = "vos0"
8687
required-features = ["revision_v"]
88+
89+
[[example]]
90+
name = "qspi"
91+
required-features = ["quadspi"]

examples/qspi.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#![deny(warnings)]
2+
#![deny(unsafe_code)]
3+
#![no_main]
4+
#![no_std]
5+
6+
extern crate panic_itm;
7+
8+
use cortex_m_rt::entry;
9+
use stm32h7xx_hal::{pac, prelude::*, qspi::QspiMode};
10+
11+
#[entry]
12+
fn main() -> ! {
13+
let dp = pac::Peripherals::take().unwrap();
14+
15+
// Constrain and Freeze power
16+
let pwr = dp.PWR.constrain();
17+
let vos = pwr.freeze();
18+
19+
// Constrain and Freeze clock
20+
let rcc = dp.RCC.constrain();
21+
let ccdr = rcc.sys_ck(96.mhz()).freeze(vos, &dp.SYSCFG);
22+
23+
// Acquire the GPIO peripherals. This also enables the clock for
24+
// the GPIOs in the RCC register.
25+
let gpiog = dp.GPIOG.split(ccdr.peripheral.GPIOG);
26+
let gpiob = dp.GPIOB.split(ccdr.peripheral.GPIOB);
27+
let gpiod = dp.GPIOD.split(ccdr.peripheral.GPIOD);
28+
let gpioe = dp.GPIOE.split(ccdr.peripheral.GPIOE);
29+
30+
let _qspi_cs = gpiog.pg6.into_alternate_af10();
31+
32+
let sck = gpiob.pb2.into_alternate_af9();
33+
let io0 = gpiod.pd11.into_alternate_af9();
34+
let io1 = gpiod.pd12.into_alternate_af9();
35+
let io2 = gpioe.pe2.into_alternate_af9();
36+
let io3 = gpiod.pd13.into_alternate_af9();
37+
38+
// Initialise the QSPI peripheral.
39+
let mut qspi = dp.QUADSPI.bank1(
40+
(sck, io0, io1, io2, io3),
41+
3.mhz(),
42+
&ccdr.clocks,
43+
ccdr.peripheral.QSPI,
44+
);
45+
46+
qspi.configure_mode(QspiMode::FourBit).unwrap();
47+
48+
loop {
49+
qspi.write(0x00, &[0xAA, 0x00, 0xFF]).unwrap();
50+
51+
let mut read: [u8; 3] = [0; 3];
52+
qspi.read(0xFF, &mut read).unwrap();
53+
}
54+
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ pub mod pwm;
129129
pub mod pwr;
130130
#[cfg(feature = "device-selected")]
131131
pub mod qei;
132+
#[cfg(all(feature = "device-selected", feature = "quadspi"))]
133+
pub mod qspi;
132134
#[cfg(feature = "device-selected")]
133135
pub mod rcc;
134136
#[cfg(feature = "device-selected")]

src/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub use crate::gpio::GpioExt as _stm32h7xx_hal_gpio_GpioExt;
1010
pub use crate::i2c::I2cExt as _stm32h7xx_hal_i2c_I2cExt;
1111
pub use crate::pwm::PwmExt as _stm32_hal_pwm_PwmExt;
1212
pub use crate::pwr::PwrExt as _stm32h7xx_hal_pwr_PwrExt;
13+
#[cfg(feature = "quadspi")]
14+
pub use crate::qspi::QspiExt as _stm32h7xx_hal_qspi_QspiExt;
1315
pub use crate::rcc::RccExt as _stm32h7xx_hal_rcc_RccExt;
1416
pub use crate::rng::RngCore as _stm32h7xx_hal_rng_RngCore;
1517
pub use crate::rng::RngExt as _stm32h7xx_hal_rng_RngExt;

0 commit comments

Comments
 (0)