Skip to content

Commit

Permalink
sdio & fsmc
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Apr 10, 2023
1 parent 24e923d commit b805e51
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 585 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ stm32f446 = ["stm32f4/stm32f446", "device-selected", "gpio-f446",
"otg-fs",
"otg-hs",
"sai",
#"sdio",
"spi3", "spi4",
"tim2", "tim8",
"usart3", "uart4", "uart5",
Expand Down
47 changes: 22 additions & 25 deletions examples/display-touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
use cortex_m;
use cortex_m_rt::entry;
use rtt_target::{rprintln, rtt_init_print};
#[cfg(feature = "stm32f412")]
use stm32f4xx_hal::fsmc_lcd::ChipSelect1;
#[cfg(feature = "stm32f413")]
use stm32f4xx_hal::fsmc_lcd::ChipSelect3;
use stm32f4xx_hal::{
fsmc_lcd::{FsmcLcd, LcdPins, Timing},
gpio::Speed,
Expand Down Expand Up @@ -70,32 +66,33 @@ fn main() -> ! {
let gpiog = p.GPIOG.split();

// Pins connected to the LCD on the board
use stm32f4xx_hal::gpio::alt::fsmc as alt;
let lcd_pins = LcdPins {
data: (
gpiod.pd14.into_alternate(),
gpiod.pd15.into_alternate(),
gpiod.pd0.into_alternate(),
gpiod.pd1.into_alternate(),
gpioe.pe7.into_alternate(),
gpioe.pe8.into_alternate(),
gpioe.pe9.into_alternate(),
gpioe.pe10.into_alternate(),
gpioe.pe11.into_alternate(),
gpioe.pe12.into_alternate(),
gpioe.pe13.into_alternate(),
gpioe.pe14.into_alternate(),
gpioe.pe15.into_alternate(),
gpiod.pd8.into_alternate(),
gpiod.pd9.into_alternate(),
gpiod.pd10.into_alternate(),
gpiod.pd14.into(),
gpiod.pd15.into(),
gpiod.pd0.into(),
gpiod.pd1.into(),
gpioe.pe7.into(),
gpioe.pe8.into(),
gpioe.pe9.into(),
gpioe.pe10.into(),
gpioe.pe11.into(),
gpioe.pe12.into(),
gpioe.pe13.into(),
gpioe.pe14.into(),
gpioe.pe15.into(),
gpiod.pd8.into(),
gpiod.pd9.into(),
gpiod.pd10.into(),
),
address: gpiof.pf0.into_alternate(),
read_enable: gpiod.pd4.into_alternate(),
write_enable: gpiod.pd5.into_alternate(),
address: alt::Address::from(gpiof.pf0),
read_enable: gpiod.pd4.into(),
write_enable: gpiod.pd5.into(),
#[cfg(feature = "stm32f413")]
chip_select: ChipSelect3(gpiog.pg10.into_alternate()),
chip_select: alt::ChipSelect3::from(gpiog.pg10.into()),
#[cfg(feature = "stm32f412")]
chip_select: ChipSelect1(gpiod.pd7.into_alternate()),
chip_select: alt::ChipSelect1::from(gpiod.pd7),
};

// Enable backlight
Expand Down
43 changes: 22 additions & 21 deletions examples/f413disco-lcd-ferris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rtt_target::{self, rtt_init_print};
use stm32f4xx_hal as hal;

use crate::hal::{
fsmc_lcd::{ChipSelect3, FsmcLcd, LcdPins, Timing},
fsmc_lcd::{FsmcLcd, LcdPins, Timing},
gpio::Speed,
pac::{CorePeripherals, Peripherals},
prelude::*,
Expand Down Expand Up @@ -709,29 +709,30 @@ fn main() -> ! {
let clocks = rcc.cfgr.sysclk(100.MHz()).freeze();

// Define the pins we need for our 16bit parallel bus
use stm32f4xx_hal::gpio::alt::fsmc as alt;
let lcd_pins = LcdPins {
data: (
gpiod.pd14.into_alternate(),
gpiod.pd15.into_alternate(),
gpiod.pd0.into_alternate(),
gpiod.pd1.into_alternate(),
gpioe.pe7.into_alternate(),
gpioe.pe8.into_alternate(),
gpioe.pe9.into_alternate(),
gpioe.pe10.into_alternate(),
gpioe.pe11.into_alternate(),
gpioe.pe12.into_alternate(),
gpioe.pe13.into_alternate(),
gpioe.pe14.into_alternate(),
gpioe.pe15.into_alternate(),
gpiod.pd8.into_alternate(),
gpiod.pd9.into_alternate(),
gpiod.pd10.into_alternate(),
gpiod.pd14.into(),
gpiod.pd15.into(),
gpiod.pd0.into(),
gpiod.pd1.into(),
gpioe.pe7.into(),
gpioe.pe8.into(),
gpioe.pe9.into(),
gpioe.pe10.into(),
gpioe.pe11.into(),
gpioe.pe12.into(),
gpioe.pe13.into(),
gpioe.pe14.into(),
gpioe.pe15.into(),
gpiod.pd8.into(),
gpiod.pd9.into(),
gpiod.pd10.into(),
),
address: gpiof.pf0.into_alternate(),
read_enable: gpiod.pd4.into_alternate(),
write_enable: gpiod.pd5.into_alternate(),
chip_select: ChipSelect3(gpiog.pg10.into_alternate()),
address: alt::Address::from(gpiof.pf0),
read_enable: gpiod.pd4.into(),
write_enable: gpiod.pd5.into(),
chip_select: alt::ChipSelect3::from(gpiog.pg10),
};

// Setup the RESET pin
Expand Down
12 changes: 6 additions & 6 deletions examples/sd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ fn main() -> ! {
let gpioc = device.GPIOC.split();
let gpiod = device.GPIOD.split();

let d0 = gpioc.pc8.into_alternate().internal_pull_up(true);
let d1 = gpioc.pc9.into_alternate().internal_pull_up(true);
let d2 = gpioc.pc10.into_alternate().internal_pull_up(true);
let d3 = gpioc.pc11.into_alternate().internal_pull_up(true);
let clk = gpioc.pc12.into_alternate().internal_pull_up(false);
let cmd = gpiod.pd2.into_alternate().internal_pull_up(true);
let d0 = gpioc.pc8.internal_pull_up(true);
let d1 = gpioc.pc9.internal_pull_up(true);
let d2 = gpioc.pc10.internal_pull_up(true);
let d3 = gpioc.pc11.internal_pull_up(true);
let clk = gpioc.pc12;
let cmd = gpiod.pd2.internal_pull_up(true);
let mut sdio: Sdio<SdCard> = Sdio::new(device.SDIO, (clk, cmd, d0, d1, d2, d3), &clocks);

hprintln!("Waiting for card...");
Expand Down
43 changes: 22 additions & 21 deletions examples/st7789-lcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use embedded_graphics::prelude::*;

use embedded_graphics::primitives::{Circle, PrimitiveStyle};
use st7789::ST7789;
use stm32f4xx_hal::fsmc_lcd::{ChipSelect1, FsmcLcd, LcdPins, Timing};
use stm32f4xx_hal::fsmc_lcd::{FsmcLcd, LcdPins, Timing};
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
use stm32f4xx_hal::prelude::*;

Expand All @@ -50,29 +50,30 @@ fn main() -> ! {
let gpiof = dp.GPIOF.split();

// Pins connected to the LCD on the 32F412GDISCOVERY board
use stm32f4xx_hal::gpio::alt::fsmc as alt;
let lcd_pins = LcdPins {
data: (
gpiod.pd14.into_alternate(),
gpiod.pd15.into_alternate(),
gpiod.pd0.into_alternate(),
gpiod.pd1.into_alternate(),
gpioe.pe7.into_alternate(),
gpioe.pe8.into_alternate(),
gpioe.pe9.into_alternate(),
gpioe.pe10.into_alternate(),
gpioe.pe11.into_alternate(),
gpioe.pe12.into_alternate(),
gpioe.pe13.into_alternate(),
gpioe.pe14.into_alternate(),
gpioe.pe15.into_alternate(),
gpiod.pd8.into_alternate(),
gpiod.pd9.into_alternate(),
gpiod.pd10.into_alternate(),
gpiod.pd14.into(),
gpiod.pd15.into(),
gpiod.pd0.into(),
gpiod.pd1.into(),
gpioe.pe7.into(),
gpioe.pe8.into(),
gpioe.pe9.into(),
gpioe.pe10.into(),
gpioe.pe11.into(),
gpioe.pe12.into(),
gpioe.pe13.into(),
gpioe.pe14.into(),
gpioe.pe15.into(),
gpiod.pd8.into(),
gpiod.pd9.into(),
gpiod.pd10.into(),
),
address: gpiof.pf0.into_alternate(),
read_enable: gpiod.pd4.into_alternate(),
write_enable: gpiod.pd5.into_alternate(),
chip_select: ChipSelect1(gpiod.pd7.into_alternate()),
address: alt::Address::from(gpiof.pf0),
read_enable: gpiod.pd4.into(),
write_enable: gpiod.pd5.into(),
chip_select: alt::ChipSelect1::from(gpiod.pd7),
};
let lcd_reset = gpiod.pd11.into_push_pull_output();
let backlight_control = gpiof.pf5.into_push_pull_output();
Expand Down
59 changes: 27 additions & 32 deletions src/fsmc_lcd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ mod timing;

use core::marker::PhantomData;

pub use self::pins::{
AddressPins, ChipSelect1, ChipSelect2, ChipSelect3, ChipSelect4, ChipSelectPins, DataPins,
LcdPins, PinAddress, PinChipSelect1, PinChipSelect2, PinChipSelect3, PinChipSelect4, PinD0,
PinD1, PinD10, PinD11, PinD12, PinD13, PinD14, PinD15, PinD2, PinD3, PinD4, PinD5, PinD6,
PinD7, PinD8, PinD9, PinReadEnable, PinWriteEnable, Pins,
};
pub use self::pins::{AddressPins, ChipSelectPins, DataPins, LcdPins, Pins};
pub use self::timing::{AccessMode, Timing};

use crate::pac::RCC;
Expand Down Expand Up @@ -157,39 +152,39 @@ where
/// ```ignore
/// let lcd_pins = LcdPins {
/// data: (
/// gpiod.pd14.into_alternate_af12(),
/// gpiod.pd15.into_alternate_af12(),
/// gpiod.pd0.into_alternate_af12(),
/// gpiod.pd1.into_alternate_af12(),
/// gpioe.pe7.into_alternate_af12(),
/// gpioe.pe8.into_alternate_af12(),
/// gpioe.pe9.into_alternate_af12(),
/// gpioe.pe10.into_alternate_af12(),
/// gpioe.pe11.into_alternate_af12(),
/// gpioe.pe12.into_alternate_af12(),
/// gpioe.pe13.into_alternate_af12(),
/// gpioe.pe14.into_alternate_af12(),
/// gpioe.pe15.into_alternate_af12(),
/// gpiod.pd8.into_alternate_af12(),
/// gpiod.pd9.into_alternate_af12(),
/// gpiod.pd10.into_alternate_af12(),
/// gpiod.pd14.into(),
/// gpiod.pd15.into(),
/// gpiod.pd0.into(),
/// gpiod.pd1.into(),
/// gpioe.pe7.into(),
/// gpioe.pe8.into(),
/// gpioe.pe9.into(),
/// gpioe.pe10.into(),
/// gpioe.pe11.into(),
/// gpioe.pe12.into(),
/// gpioe.pe13.into(),
/// gpioe.pe14.into(),
/// gpioe.pe15.into(),
/// gpiod.pd8.into(),
/// gpiod.pd9.into(),
/// gpiod.pd10.into(),
/// ),
/// // Four address pins, one for each LCD
/// // All of them will have the same output
/// address: (
/// gpiof.pf0.into_alternate_af12(),
/// gpioe.pe2.into_alternate_af12(),
/// gpioe.pe3.into_alternate_af12(),
/// gpiof.pf14.into_alternate_af12(),
/// gpiof.pf0.into(),
/// gpioe.pe2.into(),
/// gpioe.pe3.into(),
/// gpiof.pf14.into(),
/// ),
/// read_enable: gpiod.pd4.into_alternate_af12(),
/// write_enable: gpiod.pd5.into_alternate_af12(),
/// read_enable: gpiod.pd4.into(),
/// write_enable: gpiod.pd5.into(),
/// // Four chip select pins, one for each LCD, controlled independently
/// chip_select: (
/// ChipSelect1(gpiod.pd7.into_alternate_af12()),
/// ChipSelect2(gpiog.pg9.into_alternate_af12()),
/// ChipSelect3(gpiog.pg10.into_alternate_af12()),
/// ChipSelect4(gpiog.pg12.into_alternate_af12()),
/// ChipSelect1::from(gpiod.pd7),
/// ChipSelect2::from(gpiog.pg9),
/// ChipSelect3::from(gpiog.pg10),
/// ChipSelect4::from(gpiog.pg12),
/// ),
/// };
///
Expand Down
Loading

0 comments on commit b805e51

Please sign in to comment.