From 5d1cff57f9f5acd740a8b5f8c941beefdcc00176 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 28 Jun 2020 16:42:21 +0200 Subject: sw: configure si5351 --- .../examples/stm32f30x-i2c/.cargo/config | 9 ++++ .../examples/stm32f30x-i2c/.gitignore | 5 +++ .../examples/stm32f30x-i2c/Cargo.toml | 23 ++++++++++ .../hd44780-driver/examples/stm32f30x-i2c/README | 3 ++ .../hd44780-driver/examples/stm32f30x-i2c/build.rs | 15 +++++++ .../hd44780-driver/examples/stm32f30x-i2c/memory.x | 5 +++ .../examples/stm32f30x-i2c/openocd.cfg | 12 +++++ .../examples/stm32f30x-i2c/openocd.gdb | 32 +++++++++++++ .../examples/stm32f30x-i2c/src/main.rs | 52 ++++++++++++++++++++++ 9 files changed, 156 insertions(+) create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/.cargo/config create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/.gitignore create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/Cargo.toml create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/README create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/build.rs create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/memory.x create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.cfg create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.gdb create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs (limited to 'sw/deps/hd44780-driver/examples/stm32f30x-i2c') diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/.cargo/config b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/.cargo/config new file mode 100644 index 0000000..8cb4006 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/.cargo/config @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +runner = "gdb-multiarch -q -x openocd.gdb" + +rustflags = [ + "-C", "link-arg=-Tlink.x", +] + +[build] +target = "thumbv7em-none-eabihf" diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/.gitignore b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/.gitignore new file mode 100644 index 0000000..59a4524 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/.gitignore @@ -0,0 +1,5 @@ +**/*.rs.bk +.#* +.gdb_history +Cargo.lock +target/ diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/Cargo.toml b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/Cargo.toml new file mode 100644 index 0000000..3a53b47 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/Cargo.toml @@ -0,0 +1,23 @@ +[package] +authors = ["Robin Krahl ", "Nils Van Zuijlen "] +edition = "2018" +name = "stm32f30x-hd44780-i2c-example" +version = "0.1.0" +license = "MIT" +publish = false + +[dependencies] +cortex-m = "0.5.8" +cortex-m-rt = "0.6.5" +embedded-hal = "0.2.2" +panic-halt = "0.2.0" +hd44780-driver = { path = "../.." } + +[dependencies.hal] +version = "0.2.0" +package = "stm32f30x-hal" + +[profile.release] +codegen-units = 1 +debug = true +lto = true diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/README b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/README new file mode 100644 index 0000000..9fc6a18 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/README @@ -0,0 +1,3 @@ +This example is based on the cortex-m-quickstart project avaiable at +https://github.com/rust-embedded/cortex-m-quickstart under the MIT License or +the Apache License, Version 2.0. diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/build.rs b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/build.rs new file mode 100644 index 0000000..461e48f --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/build.rs @@ -0,0 +1,15 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/memory.x b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/memory.x new file mode 100644 index 0000000..2b098b1 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/memory.x @@ -0,0 +1,5 @@ +MEMORY +{ + FLASH : ORIGIN = 0x08000000, LENGTH = 512K + RAM : ORIGIN = 0x20000000, LENGTH = 64K +} diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.cfg b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.cfg new file mode 100644 index 0000000..81551c8 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.cfg @@ -0,0 +1,12 @@ +# Sample OpenOCD configuration for the STM32F3DISCOVERY development board + +# Depending on the hardware revision you got you'll have to pick ONE of these +# interfaces. At any time only one interface should be commented out. + +# Revision C (newer revision) +source [find interface/stlink-v2-1.cfg] + +# Revision A and B (older revisions) +# source [find interface/stlink-v2.cfg] + +source [find target/stm32f3x.cfg] diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.gdb b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.gdb new file mode 100644 index 0000000..a7fd5d1 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/openocd.gdb @@ -0,0 +1,32 @@ +target extended-remote :3333 + +# print demangled symbols +set print asm-demangle on + +# detect unhandled exceptions, hard faults and panics +break DefaultHandler +break UserHardFault +break rust_begin_unwind + +# *try* to stop at the user entry point (it might be gone due to inlining) +break main + +monitor arm semihosting enable + +# # send captured ITM to the file itm.fifo +# # (the microcontroller SWO pin must be connected to the programmer SWO pin) +# # 8000000 must match the core clock frequency +# monitor tpiu config internal itm.txt uart off 8000000 + +# # OR: make the microcontroller SWO pin output compatible with UART (8N1) +# # 8000000 must match the core clock frequency +# # 2000000 is the frequency of the SWO pin +# monitor tpiu config external uart off 8000000 2000000 + +# # enable ITM port 0 +# monitor itm port 0 on + +load + +# start the process but immediately halt the processor +stepi diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs new file mode 100644 index 0000000..3ecfafd --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs @@ -0,0 +1,52 @@ +#![no_std] +#![no_main] + +extern crate panic_halt; + +use core::fmt::Write; +use cortex_m_rt::entry; +use hal::prelude::*; +use hal::flash::FlashExt; +use hal::i2c::I2c; +use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780}; + +// Connections: +// VSS: GND +// VDD: 5V +// SCL: PB6 +// SDA: PB9 +// I2C address : 0x3F + +const I2C_ADDRESS: u8 = 0x3F; + +#[entry] +fn main() -> ! { + let cp = cortex_m::Peripherals::take().unwrap(); + let dp = hal::stm32f30x::Peripherals::take().unwrap(); + + let mut flash = dp.FLASH.constrain(); + let mut rcc = dp.RCC.constrain(); + let mut gpiob = dp.GPIOB.split(&mut rcc.ahb); + + let clocks = rcc.cfgr.freeze(&mut flash.acr); + let delay = hal::delay::Delay::new(cp.SYST, clocks); + + let scl = gpiob.pb6.into_af4(&mut gpiob.moder, &mut gpiob.afrl); + let sda = gpiob.pb9.into_af4(&mut gpiob.moder, &mut gpiob.afrh); + + let i2c = I2c::i2c1(dp.I2C1, (scl, sda), 400.khz(), clocks, &mut rcc.apb1); + + let mut lcd = HD44780::new_i2c(i2c, I2C_ADDRESS, delay); + lcd.reset(); + lcd.clear(); + lcd.set_display_mode( + DisplayMode { + display: Display::On, + cursor_visibility: Cursor::Visible, + cursor_blink: CursorBlink::On, + } + ); + let _ = lcd.write_str("Hello, world!"); + + loop {} +} -- cgit v1.2.3