hello world

This commit is contained in:
Sebastien Bourdeauducq 2017-05-04 17:35:26 +08:00
parent a214a1c6e0
commit 492b1e3668
11 changed files with 214 additions and 1 deletions

9
.cargo/config Normal file
View File

@ -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"

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
**/*.rs.bk

73
Cargo.lock generated Normal file
View File

@ -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)" = "<none>"
"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)" = "<none>"
"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"

16
Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "ionpak-firmware"
version = "0.1.0"
authors = ["whitequark <whitequark@whitequark.org>"]
[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" }

View File

@ -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.

6
Xargo.toml Normal file
View File

@ -0,0 +1,6 @@
[dependencies.core]
[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1

17
build.rs Normal file
View File

@ -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");
}

7
memory.x Normal file
View File

@ -0,0 +1,7 @@
MEMORY
{
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}
_stack_start = ORIGIN(RAM) + LENGTH(RAM);

65
src/main.rs Normal file
View File

@ -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<Cell<u32>, 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
};

6
support/load.gdb Normal file
View File

@ -0,0 +1,6 @@
target remote :3333
monitor arm semihosting enable
load
tbreak cortex_m_rt::reset_handler
monitor reset halt
continue

3
support/openocd.cfg Normal file
View File

@ -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