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 --- sw/deps/hd44780-driver/examples/.gitignore | 2 + .../hd44780-driver/examples/metro_m0/.cargo/config | 13 ++++ sw/deps/hd44780-driver/examples/metro_m0/.gdbinit | 20 +++++ .../hd44780-driver/examples/metro_m0/Cargo.toml | 29 +++++++ .../examples/metro_m0/examples/4bit.rs | 71 +++++++++++++++++ .../examples/metro_m0/examples/basic.rs | 67 ++++++++++++++++ .../examples/metro_m0/examples/scrolling.rs | 91 ++++++++++++++++++++++ sw/deps/hd44780-driver/examples/metro_m0/memory.x | 8 ++ .../hd44780-driver/examples/raspberrypi/.gitignore | 1 + .../hd44780-driver/examples/raspberrypi/Cargo.toml | 8 ++ .../examples/raspberrypi/src/main.rs | 75 ++++++++++++++++++ .../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 +++++++++++++ .../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 +++++++++++++ 29 files changed, 700 insertions(+) create mode 100644 sw/deps/hd44780-driver/examples/.gitignore create mode 100644 sw/deps/hd44780-driver/examples/metro_m0/.cargo/config create mode 100644 sw/deps/hd44780-driver/examples/metro_m0/.gdbinit create mode 100644 sw/deps/hd44780-driver/examples/metro_m0/Cargo.toml create mode 100644 sw/deps/hd44780-driver/examples/metro_m0/examples/4bit.rs create mode 100644 sw/deps/hd44780-driver/examples/metro_m0/examples/basic.rs create mode 100644 sw/deps/hd44780-driver/examples/metro_m0/examples/scrolling.rs create mode 100644 sw/deps/hd44780-driver/examples/metro_m0/memory.x create mode 100644 sw/deps/hd44780-driver/examples/raspberrypi/.gitignore create mode 100644 sw/deps/hd44780-driver/examples/raspberrypi/Cargo.toml create mode 100644 sw/deps/hd44780-driver/examples/raspberrypi/src/main.rs 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 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') diff --git a/sw/deps/hd44780-driver/examples/.gitignore b/sw/deps/hd44780-driver/examples/.gitignore new file mode 100644 index 0000000..fd8951e --- /dev/null +++ b/sw/deps/hd44780-driver/examples/.gitignore @@ -0,0 +1,2 @@ +target +cargo.lock \ No newline at end of file diff --git a/sw/deps/hd44780-driver/examples/metro_m0/.cargo/config b/sw/deps/hd44780-driver/examples/metro_m0/.cargo/config new file mode 100644 index 0000000..ce9679d --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/.cargo/config @@ -0,0 +1,13 @@ +# samd21 is a Cortex-M0 and thus thumbv6m + +[build] +target = "thumbv6m-none-eabi" + +[target.thumbv6m-none-eabi] +runner = 'arm-none-eabi-gdb' +rustflags = [ + "-C", "link-arg=-Tlink.x", + "-C", "linker=lld", + "-Z", "linker-flavor=ld.lld", + "-Z", "thinlto=no", +] \ No newline at end of file diff --git a/sw/deps/hd44780-driver/examples/metro_m0/.gdbinit b/sw/deps/hd44780-driver/examples/metro_m0/.gdbinit new file mode 100644 index 0000000..7b9b83b --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/.gdbinit @@ -0,0 +1,20 @@ +set auto-load safe-path / + +# print demangled symbols by default +set print asm-demangle on + +# JLink +target extended-remote :2331 +monitor flash breakpoints 1 +# allow hprints to show up in gdb +monitor semihosting enable +monitor semihosting IOClient 3 + +monitor reset +load + +# OpenOCD +#target extended-remote :3333 +#monitor arm semihosting enable +#load +#step \ No newline at end of file diff --git a/sw/deps/hd44780-driver/examples/metro_m0/Cargo.toml b/sw/deps/hd44780-driver/examples/metro_m0/Cargo.toml new file mode 100644 index 0000000..bd88b22 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "metro_m0_hd44780_examples" +version = "0.2.0" +authors = ["John Doneth "] +keywords = ["no-std", "arm", "cortex-m", "embedded-hal"] +license = "MIT" + +[dependencies] +cortex-m = "~0.4" +hd44780-driver = { path = "../.." } +atsamd21-hal = "~0.1" +embedded-hal = "~0.2" +metro_m0 = { git = "https://github.com/wez/atsamd21-rs.git" } + +cortex-m-rt = "*" + +[dev-dependencies] +panic-abort = "~0.1" +panic-semihosting = "~0.1" +cortex-m-semihosting = "~0.2" +cortex-m-rtfm = "~0.3" +sx1509 = "~0.2" + +[features] +# ask the HAL to enable atsamd21g18a support +default = ["rt", "atsamd21-hal/samd21g18a"] +rt = ["atsamd21-hal/rt"] +unproven = ["atsamd21-hal/unproven"] +use_semihosting = [] diff --git a/sw/deps/hd44780-driver/examples/metro_m0/examples/4bit.rs b/sw/deps/hd44780-driver/examples/metro_m0/examples/4bit.rs new file mode 100644 index 0000000..5cf46c3 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/examples/4bit.rs @@ -0,0 +1,71 @@ +#![feature(used)] +#![no_std] + +extern crate cortex_m_semihosting; + +#[cfg(not(feature = "use_semihosting"))] +extern crate panic_abort; + +#[cfg(feature = "use_semihosting")] +extern crate panic_semihosting; + +extern crate cortex_m; +extern crate cortex_m_rt; +extern crate atsamd21_hal; +extern crate metro_m0; + +use metro_m0::clock::GenericClockController; +use metro_m0::delay::Delay; +use metro_m0::{CorePeripherals, Peripherals}; + +extern crate hd44780_driver; + +use hd44780_driver::HD44780; + +extern crate embedded_hal; + +fn main() { + let mut peripherals = Peripherals::take().unwrap(); + + let core = CorePeripherals::take().unwrap(); + + let mut clocks = GenericClockController::new( + peripherals.GCLK, + &mut peripherals.PM, + &mut peripherals.SYSCTRL, + &mut peripherals.NVMCTRL, + ); + + let mut pins = metro_m0::pins(peripherals.PORT); + let delay = Delay::new(core.SYST, &mut clocks); + + let mut lcd = HD44780::new_4bit( + + pins.d4.into_open_drain_output(&mut pins.port), // Register Select pin + pins.d3.into_open_drain_output(&mut pins.port), // Enable pin + + pins.d9.into_open_drain_output(&mut pins.port), // d4 + pins.d10.into_open_drain_output(&mut pins.port), // d5 + pins.d11.into_open_drain_output(&mut pins.port), // d6 + pins.d12.into_open_drain_output(&mut pins.port), // d7 + + delay, + ); + + // Unshift display and set cursor to 0 + lcd.reset(); + + // Clear existing characters + lcd.clear(); + + // Display the following string + lcd.write_str("Hello, world!"); + + // Move the cursor to the second line + lcd.set_cursor_pos(40); + + // Display the following string on the second line + lcd.write_str("I'm on line 2!"); + + loop { } +} diff --git a/sw/deps/hd44780-driver/examples/metro_m0/examples/basic.rs b/sw/deps/hd44780-driver/examples/metro_m0/examples/basic.rs new file mode 100644 index 0000000..2adb5b0 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/examples/basic.rs @@ -0,0 +1,67 @@ +#![feature(used)] +#![no_std] + +extern crate cortex_m_semihosting; + +#[cfg(not(feature = "use_semihosting"))] +extern crate panic_abort; + +#[cfg(feature = "use_semihosting")] +extern crate panic_semihosting; + +extern crate cortex_m; +extern crate cortex_m_rt; +extern crate atsamd21_hal; +extern crate metro_m0; + +use metro_m0::clock::GenericClockController; +use metro_m0::delay::Delay; +use metro_m0::{CorePeripherals, Peripherals}; + +extern crate hd44780_driver; + +use hd44780_driver::HD44780; + +fn main() { + let mut peripherals = Peripherals::take().unwrap(); + + let core = CorePeripherals::take().unwrap(); + + let mut clocks = GenericClockController::new( + peripherals.GCLK, + &mut peripherals.PM, + &mut peripherals.SYSCTRL, + &mut peripherals.NVMCTRL, + ); + + let mut pins = metro_m0::pins(peripherals.PORT); + let delay = Delay::new(core.SYST, &mut clocks); + + let mut lcd = HD44780::new_8bit( + + pins.d4.into_open_drain_output(&mut pins.port), // Register Select pin + pins.d3.into_open_drain_output(&mut pins.port), // Enable pin + + pins.d5.into_open_drain_output(&mut pins.port), // d0 + pins.d6.into_open_drain_output(&mut pins.port), // d1 + pins.d7.into_open_drain_output(&mut pins.port), // d2 + pins.d8.into_open_drain_output(&mut pins.port), // d3 + pins.d9.into_open_drain_output(&mut pins.port), // d4 + pins.d10.into_open_drain_output(&mut pins.port), // d5 + pins.d11.into_open_drain_output(&mut pins.port), // d6 + pins.d12.into_open_drain_output(&mut pins.port), // d7 + + delay, + ); + + // Unshift display and set cursor to 0 + lcd.reset(); + + // Clear existing characters + lcd.clear(); + + // Display the following string + lcd.write_str("Hello, world!"); + + loop { } +} diff --git a/sw/deps/hd44780-driver/examples/metro_m0/examples/scrolling.rs b/sw/deps/hd44780-driver/examples/metro_m0/examples/scrolling.rs new file mode 100644 index 0000000..f02a752 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/examples/scrolling.rs @@ -0,0 +1,91 @@ +#![feature(used)] +#![no_std] + +extern crate cortex_m_semihosting; + +#[cfg(not(feature = "use_semihosting"))] +extern crate panic_abort; + +#[cfg(feature = "use_semihosting")] +extern crate panic_semihosting; + +extern crate cortex_m; +extern crate cortex_m_rt; +extern crate atsamd21_hal; +extern crate metro_m0; + +use metro_m0::clock::GenericClockController; +use metro_m0::delay::Delay; +use metro_m0::{CorePeripherals, Peripherals}; + +extern crate hd44780_driver; + +use hd44780_driver::{HD44780, DisplayMode, Display, Cursor, CursorBlink}; + +extern crate embedded_hal; + +fn busy_loop(){ + #[allow(unused_variables)] + let mut i = 0; + + for _ in 0..50000 { + i += 1; + } +} + +fn main() { + let mut peripherals = Peripherals::take().unwrap(); + + let core = CorePeripherals::take().unwrap(); + + let mut clocks = GenericClockController::new( + peripherals.GCLK, + &mut peripherals.PM, + &mut peripherals.SYSCTRL, + &mut peripherals.NVMCTRL, + ); + + let mut pins = metro_m0::pins(peripherals.PORT); + let delay = Delay::new(core.SYST, &mut clocks); + + let mut lcd = HD44780::new_8bit( + + pins.d4.into_open_drain_output(&mut pins.port), // Register Select pin + pins.d3.into_open_drain_output(&mut pins.port), // Enable pin + + pins.d5.into_open_drain_output(&mut pins.port), // d0 + pins.d6.into_open_drain_output(&mut pins.port), // d1 + pins.d7.into_open_drain_output(&mut pins.port), // d2 + pins.d8.into_open_drain_output(&mut pins.port), // d3 + pins.d9.into_open_drain_output(&mut pins.port), // d4 + pins.d10.into_open_drain_output(&mut pins.port), // d5 + pins.d11.into_open_drain_output(&mut pins.port), // d6 + pins.d12.into_open_drain_output(&mut pins.port), // d7 + + delay, + ); + + //lcd.set_cursor_mode(CursorMode::Increment); + lcd.set_autoscroll(true); + + lcd.set_display_mode(DisplayMode { + cursor_visible : Cursor::Invisible, + cursor_blink : CursorBlink::On, + display_visible : Display::On, + }); + + let string = "Hello, world! "; + + // Display the following string + loop { + + for c in string.chars() { + lcd.write_char(c); + + busy_loop(); + } + + } + + +} diff --git a/sw/deps/hd44780-driver/examples/metro_m0/memory.x b/sw/deps/hd44780-driver/examples/metro_m0/memory.x new file mode 100644 index 0000000..859903b --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/memory.x @@ -0,0 +1,8 @@ +MEMORY +{ + /* Leave 8k for the default bootloader on the Metro M0 */ + FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K +} +_stack_start = ORIGIN(RAM) + LENGTH(RAM); + diff --git a/sw/deps/hd44780-driver/examples/raspberrypi/.gitignore b/sw/deps/hd44780-driver/examples/raspberrypi/.gitignore new file mode 100644 index 0000000..2bf0f84 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/raspberrypi/.gitignore @@ -0,0 +1 @@ +.cargo \ No newline at end of file diff --git a/sw/deps/hd44780-driver/examples/raspberrypi/Cargo.toml b/sw/deps/hd44780-driver/examples/raspberrypi/Cargo.toml new file mode 100644 index 0000000..db5d98f --- /dev/null +++ b/sw/deps/hd44780-driver/examples/raspberrypi/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "raspberrypi-hd44780-example" +version = "0.2.0" +authors = ["John Doneth "] + +[dependencies] +linux-embedded-hal = "0.2" +hd44780-driver = { path = "../.." } diff --git a/sw/deps/hd44780-driver/examples/raspberrypi/src/main.rs b/sw/deps/hd44780-driver/examples/raspberrypi/src/main.rs new file mode 100644 index 0000000..2fefcbe --- /dev/null +++ b/sw/deps/hd44780-driver/examples/raspberrypi/src/main.rs @@ -0,0 +1,75 @@ +extern crate linux_embedded_hal; +extern crate hd44780_driver; + +use linux_embedded_hal::{Delay, Pin}; +use linux_embedded_hal::sysfs_gpio::Direction; + +use hd44780_driver::{HD44780, DisplayMode, Cursor, CursorBlink, Display}; + +fn main() { + + let rs = Pin::new(26); + let en = Pin::new(22); + + let db0 = Pin::new(19); + let db1 = Pin::new(13); + let db2 = Pin::new(6); + let db3 = Pin::new(5); + let db4 = Pin::new(21); + let db5 = Pin::new(20); + let db6 = Pin::new(16); + let db7 = Pin::new(12); + + rs.export().unwrap(); + en.export().unwrap(); + + db0.export().unwrap(); + db1.export().unwrap(); + db2.export().unwrap(); + db3.export().unwrap(); + db4.export().unwrap(); + db5.export().unwrap(); + db6.export().unwrap(); + db7.export().unwrap(); + + rs.set_direction(Direction::Low).unwrap(); + en.set_direction(Direction::Low).unwrap(); + + db0.set_direction(Direction::Low).unwrap(); + db1.set_direction(Direction::Low).unwrap(); + db2.set_direction(Direction::Low).unwrap(); + db3.set_direction(Direction::Low).unwrap(); + db4.set_direction(Direction::Low).unwrap(); + db5.set_direction(Direction::Low).unwrap(); + db6.set_direction(Direction::Low).unwrap(); + db7.set_direction(Direction::Low).unwrap(); + + let mut lcd = HD44780::new_8bit( + rs, + en, + db0, + db1, + db2, + db3, + db4, + db5, + db6, + db7, + 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!"); + +} 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 {} +} 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