From 492b1e366877fa43609a2283f0c9ca6093d7d7e0 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 4 May 2017 17:35:26 +0800 Subject: [PATCH] hello world --- .cargo/config | 9 ++++++ .gitignore | 2 ++ Cargo.lock | 73 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 16 ++++++++++ README.md | 11 ++++++- Xargo.toml | 6 ++++ build.rs | 17 +++++++++++ memory.x | 7 +++++ src/main.rs | 65 ++++++++++++++++++++++++++++++++++++++++ support/load.gdb | 6 ++++ support/openocd.cfg | 3 ++ 11 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 .cargo/config create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 Xargo.toml create mode 100644 build.rs create mode 100644 memory.x create mode 100644 src/main.rs create mode 100644 support/load.gdb create mode 100644 support/openocd.cfg diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..06b340b --- /dev/null +++ b/.cargo/config @@ -0,0 +1,9 @@ +[target.thumbv7em-none-eabihf] +rustflags = [ + "-C", "link-arg=-Tlink.x", + "-C", "linker=arm-none-eabi-ld", + "-Z", "linker-flavor=ld", +] + +[build] +target = "thumbv7em-none-eabihf" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..324c57f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b743562 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,73 @@ +[root] +name = "ionpak-firmware" +version = "0.1.0" +dependencies = [ + "cortex-m 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tm4c129x 0.3.0 (git+https://github.com/m-labs/dslite2svd)", +] + +[[package]] +name = "cortex-m" +version = "0.2.4" +source = "git+https://github.com/whitequark/cortex-m?rev=impl-syst#a9967c544da4ddc7575135ed522dffd21ec28c19" +dependencies = [ + "cortex-m-semihosting 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cortex-m" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +replace = "cortex-m 0.2.4 (git+https://github.com/whitequark/cortex-m?rev=impl-syst)" + +[[package]] +name = "cortex-m-rt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "r0 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cortex-m-semihosting" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "r0" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "tm4c129x" +version = "0.3.0" +source = "git+https://github.com/m-labs/dslite2svd#f01cff2384123e24b1a8e2d1f81141a1a8bafad9" +dependencies = [ + "cortex-m 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "vcell" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "volatile-register" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum cortex-m 0.2.4 (git+https://github.com/whitequark/cortex-m?rev=impl-syst)" = "" +"checksum cortex-m 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "964f183322128497a636a5d4524dfe91fa1394a15b7b2c4329ee5bb66bef1548" +"checksum cortex-m-rt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2ed494cbd15190fae60f608e6b4690e753df47b5f5e25e95d3c298f801f5c1d0" +"checksum cortex-m-semihosting 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "54a88e8fd577808637f819107f34eece1b6b45be8db1c56d1c563095b80b655e" +"checksum r0 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6e7bbed8cd0a245bbf3759ebb35c964822b7a8c15ceeeee56d4cc5f060ce518e" +"checksum tm4c129x 0.3.0 (git+https://github.com/m-labs/dslite2svd)" = "" +"checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d" +"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..89d4a50 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ionpak-firmware" +version = "0.1.0" +authors = ["whitequark "] + +[dependencies] +cortex-m = "0.2.4" +cortex-m-rt = { version = "0.2.0", features = ["linker-script"], default-features = false } +tm4c129x = { git = "https://github.com/m-labs/dslite2svd" } + +[profile.release] +lto = true +debug = true + +[replace] +"cortex-m:0.2.4" = { git = "https://github.com/whitequark/cortex-m", rev = "impl-syst" } diff --git a/README.md b/README.md index 5376ddc..ab26c2a 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,19 @@ A modern, low-cost universal controller for ionization vacuum gauges. ![Prototype picture](https://raw.githubusercontent.com/m-labs/ionpak/master/proto_rev1_small.jpg) +Building and loading the firmware +--------------------------------- + +```sh +openocd -f support/openocd.cfg +xargo build --release +arm-none-eabi-gdb -x support/load.gdb target/thumbv7em-none-eabihf/release/ionpak-firmware +``` + Flyback transformer construction -------------------------------- -TR300: Use EPCOS coilformer B66208X1010T1. Wind 5 turns on the primary and spread them across the length of the coilformer - it is important that the air gap between the cores is covered by windings. Wind 70 turns on the secondary in multiple layers. As with all flyback transformers, the polarity of the windings is critical. Assemble with EPCOS cores B66317G500X127 and B66317GX127 (one half gapped core, one half ungapped core), and corresponding clips. +TR300: Use EPCOS coilformer B66208X1010T1. Wind 5 turns on the primary and spread them across the length of the coilformer - it is particularly important that the air gap between the cores is covered by windings. Wind 70 turns on the secondary in multiple layers. As with all flyback transformers, the polarity of the windings is critical. Assemble with EPCOS cores B66317G500X127 and B66317GX127 (one half gapped core, one half ungapped core), and corresponding clips. TR350: Use EPCOS coilformer B66206W1110T1 and cores B66311G250X127 and B66311GX127. Both the primary and the secondary have 5 turns and must be wound together, interleaving the windings. The same remarks as for TR300 apply. diff --git a/Xargo.toml b/Xargo.toml new file mode 100644 index 0000000..fbaaf69 --- /dev/null +++ b/Xargo.toml @@ -0,0 +1,6 @@ +[dependencies.core] + +[dependencies.compiler_builtins] +features = ["mem"] +git = "https://github.com/rust-lang-nursery/compiler-builtins" +stage = 1 diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..88f7fef --- /dev/null +++ b/build.rs @@ -0,0 +1,17 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put the linker script somewhere the linker can find it + 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=build.rs"); + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..2116a09 --- /dev/null +++ b/memory.x @@ -0,0 +1,7 @@ +MEMORY +{ + FLASH : ORIGIN = 0x00000000, LENGTH = 512K + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} + +_stack_start = ORIGIN(RAM) + LENGTH(RAM); diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f3e79ef --- /dev/null +++ b/src/main.rs @@ -0,0 +1,65 @@ +#![feature(used, const_fn)] +#![no_std] + +#[macro_use] +extern crate cortex_m; +extern crate cortex_m_rt; +extern crate tm4c129x; + +use core::cell::Cell; +use cortex_m::ctxt::Local; +use cortex_m::exception::Handlers as ExceptionHandlers; +use tm4c129x::interrupt::Handlers as InterruptHandlers; + +fn main() { + hprintln!("Hello, world!"); + + cortex_m::interrupt::free(|cs| { + let systick = tm4c129x::SYST.borrow(cs); + let sysctl = tm4c129x::SYSCTL.borrow(cs); + let gpio_k = tm4c129x::GPIO_PORTK.borrow(cs); + + // Set up system timer + systick.set_reload(systick.get_ticks_per_10ms()); + systick.enable_counter(); + systick.enable_interrupt(); + + // Set up LED + sysctl.rcgcgpio.modify(|_, w| w.r9().bit(true)); + while !sysctl.prgpio.read().r9().bit() {} + + gpio_k.dir.write(|w| w.dir().bits(0x10)); + gpio_k.den.write(|w| w.den().bits(0x10)); + }); +} + +use cortex_m::exception::SysTick; + +extern fn sys_tick(ctxt: SysTick) { + static ELAPSED: Local, SysTick> = Local::new(Cell::new(0)); + let elapsed = ELAPSED.borrow(&ctxt); + + elapsed.set(elapsed.get() + 1); + + cortex_m::interrupt::free(|cs| { + let gpio_k = tm4c129x::GPIO_PORTK.borrow(cs); + + if elapsed.get() % 100 == 0 { + gpio_k.data.modify(|r, w| w.data().bits(r.data().bits() ^ 0x10)); + } + }) +} + +#[used] +#[link_section = ".rodata.exceptions"] +pub static EXCEPTIONS: ExceptionHandlers = ExceptionHandlers { + sys_tick: sys_tick, + ..cortex_m::exception::DEFAULT_HANDLERS +}; + +#[used] +#[link_section = ".rodata.interrupts"] +pub static INTERRUPTS: InterruptHandlers = InterruptHandlers { + ..tm4c129x::interrupt::DEFAULT_HANDLERS +}; + \ No newline at end of file diff --git a/support/load.gdb b/support/load.gdb new file mode 100644 index 0000000..068e0ae --- /dev/null +++ b/support/load.gdb @@ -0,0 +1,6 @@ +target remote :3333 +monitor arm semihosting enable +load +tbreak cortex_m_rt::reset_handler +monitor reset halt +continue diff --git a/support/openocd.cfg b/support/openocd.cfg new file mode 100644 index 0000000..f8c1fad --- /dev/null +++ b/support/openocd.cfg @@ -0,0 +1,3 @@ +source /usr/share/openocd/scripts/interface/ftdi/olimex-arm-usb-tiny-h.cfg +set CHIPNAME tm4c1294kcpd +source /usr/share/openocd/scripts/target/stellaris.cfg