From f758c4b3910e8cb4d09c284db245e66de8cb5e5e Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Fri, 14 Jun 2024 16:55:05 +0200 Subject: Start implementing lcd --- examples/stm32u0/.cargo/config.toml | 2 +- examples/stm32u0/Cargo.toml | 2 +- examples/stm32u0/src/bin/lcd.rs | 76 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 examples/stm32u0/src/bin/lcd.rs (limited to 'examples') diff --git a/examples/stm32u0/.cargo/config.toml b/examples/stm32u0/.cargo/config.toml index 688347084..06eed6c8f 100644 --- a/examples/stm32u0/.cargo/config.toml +++ b/examples/stm32u0/.cargo/config.toml @@ -1,6 +1,6 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] # replace stm32u083rctx with your chip as listed in `probe-rs chip list` -runner = "probe-rs run --chip stm32u083rctx" +runner = "probe-rs run --chip stm32u083rctx --catch-hardfault" [build] target = "thumbv6m-none-eabi" diff --git a/examples/stm32u0/Cargo.toml b/examples/stm32u0/Cargo.toml index afeb4dc34..6c310b0f6 100644 --- a/examples/stm32u0/Cargo.toml +++ b/examples/stm32u0/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] # Change stm32u083rc to your chip name, if necessary. -embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32u083rc", "memory-x", "unstable-pac", "exti", "chrono"] } +embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32u083mc", "memory-x", "unstable-pac", "exti", "chrono"] } embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] } embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.3.1", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } diff --git a/examples/stm32u0/src/bin/lcd.rs b/examples/stm32u0/src/bin/lcd.rs new file mode 100644 index 000000000..8612c3dfc --- /dev/null +++ b/examples/stm32u0/src/bin/lcd.rs @@ -0,0 +1,76 @@ +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_stm32::lcd::{Bias, Config, Duty, Lcd, VoltageSource}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let mut config = embassy_stm32::Config::default(); + // The RTC clock = the LCD clock and must be running + { + use embassy_stm32::rcc::*; + config.rcc.sys = Sysclk::PLL1_R; + config.rcc.hsi = true; + config.rcc.pll = Some(Pll { + source: PllSource::HSI, // 16 MHz + prediv: PllPreDiv::DIV1, + mul: PllMul::MUL7, // 16 * 7 = 112 MHz + divp: None, + divq: None, + divr: Some(PllRDiv::DIV2), // 112 / 2 = 56 MHz + }); + config.rcc.ls = LsConfig::default(); + } + + let p = embassy_stm32::init(config); + info!("Hello World!"); + + let mut config = Config::default(); + config.bias = Bias::Third; + config.duty = Duty::Quarter; + + let mut lcd = Lcd::new( + p.LCD, + config, + [ + p.PC4.into(), + p.PC5.into(), + p.PB1.into(), + p.PE7.into(), + p.PE8.into(), + p.PE9.into(), + p.PB11.into(), + p.PB14.into(), + p.PB15.into(), + p.PD8.into(), + p.PD9.into(), + p.PD12.into(), + p.PB9.into(), + p.PA10.into(), + p.PA9.into(), + p.PA8.into(), + p.PD13.into(), + p.PC6.into(), + p.PC8.into(), + p.PC9.into(), + p.PC10.into(), + p.PD0.into(), + p.PD1.into(), + p.PD3.into(), + p.PD4.into(), + p.PD5.into(), + p.PD6.into(), + p.PC11.into(), + ], + ); + + loop { + defmt::info!("Writing frame"); + lcd.write_frame(&[0xAAAAAAAA; 16]); + defmt::info!("Writing frame"); + lcd.write_frame(&[!0xAAAAAAAA; 16]); + } +} -- cgit