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/.cargo/config | 9 ++++ .../hd44780-driver/examples/stm32f30x/.gitignore | 5 ++ .../hd44780-driver/examples/stm32f30x/Cargo.toml | 23 +++++++++ sw/deps/hd44780-driver/examples/stm32f30x/README | 3 ++ sw/deps/hd44780-driver/examples/stm32f30x/build.rs | 15 ++++++ sw/deps/hd44780-driver/examples/stm32f30x/memory.x | 5 ++ .../hd44780-driver/examples/stm32f30x/openocd.cfg | 12 +++++ .../hd44780-driver/examples/stm32f30x/openocd.gdb | 32 +++++++++++++ .../hd44780-driver/examples/stm32f30x/src/main.rs | 55 ++++++++++++++++++++++ 9 files changed, 159 insertions(+) create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/.cargo/config create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/.gitignore create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/Cargo.toml create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/README create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/build.rs create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/memory.x create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/openocd.cfg create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/openocd.gdb create mode 100644 sw/deps/hd44780-driver/examples/stm32f30x/src/main.rs (limited to 'sw/deps/hd44780-driver/examples/stm32f30x') diff --git a/sw/deps/hd44780-driver/examples/stm32f30x/.cargo/config b/sw/deps/hd44780-driver/examples/stm32f30x/.cargo/config new file mode 100644 index 0000000..ac7edbb --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/.cargo/config @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +runner = "arm-none-eabi-gdb -q -x openocd.gdb" + +rustflags = [ + "-C", "link-arg=-Tlink.x", +] + +[build] +target = "thumbv7em-none-eabihf" diff --git a/sw/deps/hd44780-driver/examples/stm32f30x/.gitignore b/sw/deps/hd44780-driver/examples/stm32f30x/.gitignore new file mode 100644 index 0000000..59a4524 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/.gitignore @@ -0,0 +1,5 @@ +**/*.rs.bk +.#* +.gdb_history +Cargo.lock +target/ diff --git a/sw/deps/hd44780-driver/examples/stm32f30x/Cargo.toml b/sw/deps/hd44780-driver/examples/stm32f30x/Cargo.toml new file mode 100644 index 0000000..5e51866 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/Cargo.toml @@ -0,0 +1,23 @@ +[package] +authors = ["Robin Krahl "] +edition = "2018" +name = "stm32f30x-hd44780-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/README b/sw/deps/hd44780-driver/examples/stm32f30x/README new file mode 100644 index 0000000..9fc6a18 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/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/build.rs b/sw/deps/hd44780-driver/examples/stm32f30x/build.rs new file mode 100644 index 0000000..461e48f --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/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/memory.x b/sw/deps/hd44780-driver/examples/stm32f30x/memory.x new file mode 100644 index 0000000..c49e4c3 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/memory.x @@ -0,0 +1,5 @@ +MEMORY +{ + FLASH : ORIGIN = 0x08000000, LENGTH = 256K + RAM : ORIGIN = 0x20000000, LENGTH = 40K +} diff --git a/sw/deps/hd44780-driver/examples/stm32f30x/openocd.cfg b/sw/deps/hd44780-driver/examples/stm32f30x/openocd.cfg new file mode 100644 index 0000000..81551c8 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/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/openocd.gdb b/sw/deps/hd44780-driver/examples/stm32f30x/openocd.gdb new file mode 100644 index 0000000..a7fd5d1 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/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/src/main.rs b/sw/deps/hd44780-driver/examples/stm32f30x/src/main.rs new file mode 100644 index 0000000..6b3b602 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/stm32f30x/src/main.rs @@ -0,0 +1,55 @@ +#![no_std] +#![no_main] + +extern crate panic_halt; + +use cortex_m_rt::entry; +use hal::gpio::GpioExt; +use hal::flash::FlashExt; +use hal::rcc::RccExt; +use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780}; + +// Connections: +// VSS: GND +// VDD: 5V +// V0: 10k poti between 5V and GND +// RS: PD1 +// RW: GND +// E: PD2 +// D4-D7: PD4-PD7 +// A: 5V +// K: GND + +#[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 gpiod = dp.GPIOD.split(&mut rcc.ahb); + + let clocks = rcc.cfgr.freeze(&mut flash.acr); + let delay = hal::delay::Delay::new(cp.SYST, clocks); + + let rs = gpiod.pd1.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper); + let en = gpiod.pd2.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper); + let b4 = gpiod.pd4.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper); + let b5 = gpiod.pd5.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper); + let b6 = gpiod.pd6.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper); + let b7 = gpiod.pd7.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper); + + let mut lcd = HD44780::new_4bit(rs, en, b4, b5, b6, b7, delay); + lcd.reset(); + lcd.clear(); + lcd.set_display_mode( + DisplayMode { + display: Display::On, + cursor_visibility: Cursor::Visible, + cursor_blink: CursorBlink::On, + } + ); + lcd.write_str("Hello, world!"); + + loop {} +} -- cgit v1.2.3