Added firmware
This commit is contained in:
parent
f2fe686b0e
commit
4fb87dbae1
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
/target
|
||||
output.log
|
||||
/*/output.log
|
885
Cargo.lock
generated
885
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
25
Cargo.toml
25
Cargo.toml
|
@ -1,18 +1,9 @@
|
|||
[package]
|
||||
name = "radomctld"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
|
||||
members = [
|
||||
"daemon",
|
||||
"firmware",
|
||||
]
|
||||
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.83"
|
||||
axum = { version = "0.7.5", features = ["macros"] }
|
||||
fern = { version = "0.6.2", features = ["colored"] }
|
||||
humantime = "2.1.0"
|
||||
log = "0.4.21"
|
||||
nom = "7.1.3"
|
||||
serde_json = "1.0.118"
|
||||
tokio = {version = "1.37.0", features = ["full"]}
|
||||
tokio-macros = { version = "0.2.0-alpha.6" }
|
||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
|
|
1103
daemon/Cargo.lock
generated
Normal file
1103
daemon/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
18
daemon/Cargo.toml
Normal file
18
daemon/Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "radomctld"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.83"
|
||||
axum = { version = "0.7.5", features = ["macros"] }
|
||||
fern = { version = "0.6.2", features = ["colored"] }
|
||||
humantime = "2.1.0"
|
||||
log = "0.4.21"
|
||||
nom = "7.1.3"
|
||||
serde_json = "1.0.118"
|
||||
tokio = {version = "1.37.0", features = ["full"]}
|
||||
tokio-macros = { version = "0.2.0-alpha.6" }
|
||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
21
firmware/.cargo/config.toml
Normal file
21
firmware/.cargo/config.toml
Normal file
|
@ -0,0 +1,21 @@
|
|||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# TODO(2) replace `$CHIP` with your chip's name (see `probe-run --list-chips` output)
|
||||
runner = "probe-run --chip STM32F401CCU6"
|
||||
rustflags = [
|
||||
"-C", "linker=flip-link",
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
|
||||
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
|
||||
"-C", "link-arg=--nmagic",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv7em-none-eabihf"
|
||||
|
||||
[alias]
|
||||
rb = "run --bin"
|
||||
rrb = "run --release --bin"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "debug"
|
2
firmware/.gitignore
vendored
Normal file
2
firmware/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
Cargo.lock
|
80
firmware/Cargo.toml
Normal file
80
firmware/Cargo.toml
Normal file
|
@ -0,0 +1,80 @@
|
|||
[package]
|
||||
name = "radomctl-firmware"
|
||||
edition = "2021"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
||||
defmt = { version = "0.3", features = ["encoding-rzcobs"] }
|
||||
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
rtic = { version = "2.0.1", features = [ "thumbv7-backend" ] }
|
||||
defmt-rtt = "0.4"
|
||||
stm32f4xx-hal = { version = "0.21.0", features = ["stm32f401"] }
|
||||
embedded-hal = {version = "1.0.0"}
|
||||
nb = "1.0.0"
|
||||
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
|
||||
num = {version = "0.4", default-features = false}
|
||||
ufmt = "0.2.0"
|
||||
qmc5883l = "0.0.1"
|
||||
rtic-monotonics = {version = "2.0.2", features = ["cortex-m-systick"]}
|
||||
xca9548a = "0.2.1"
|
||||
|
||||
[features]
|
||||
# set logging levels here
|
||||
default = ["defmt-default"]
|
||||
|
||||
# do NOT modify these features
|
||||
defmt-default = []
|
||||
defmt-trace = []
|
||||
defmt-debug = []
|
||||
defmt-info = []
|
||||
defmt-warn = []
|
||||
defmt-error = []
|
||||
|
||||
# cargo build/run
|
||||
[profile.dev]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = true # <-
|
||||
incremental = false
|
||||
opt-level = 'z' # <-
|
||||
overflow-checks = true # <-
|
||||
|
||||
# cargo test
|
||||
[profile.test]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = true # <-
|
||||
incremental = false
|
||||
opt-level = 3 # <-
|
||||
overflow-checks = true # <-
|
||||
|
||||
# cargo build/run --release
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = false # <-
|
||||
incremental = false
|
||||
lto = 'fat'
|
||||
opt-level = 3 # <-
|
||||
overflow-checks = false # <-
|
||||
|
||||
# cargo test --release
|
||||
[profile.bench]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = false # <-
|
||||
incremental = false
|
||||
lto = 'fat'
|
||||
opt-level = 3 # <-
|
||||
overflow-checks = false # <-
|
||||
|
||||
|
||||
# uncomment this to switch from the crates.io version of defmt to its git version
|
||||
# check app-template's README for instructions
|
||||
# [patch.crates-io]
|
||||
# defmt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
||||
# defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
||||
# defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
||||
# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
186
firmware/src/main.rs
Normal file
186
firmware/src/main.rs
Normal file
|
@ -0,0 +1,186 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
use defmt_brtt as _; // global logger
|
||||
|
||||
use panic_probe as _;
|
||||
use stm32f4xx_hal as _;
|
||||
|
||||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
||||
#[defmt::panic_handler]
|
||||
fn panic() -> ! {
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
use rtic::app;
|
||||
|
||||
#[rtic::app(
|
||||
device = stm32f4xx_hal::pac,
|
||||
dispatchers = [SPI3]
|
||||
)]
|
||||
mod app {
|
||||
|
||||
use cortex_m::{asm, singleton};
|
||||
use stm32f4xx_hal::{
|
||||
gpio::{self, gpioa, gpiob, gpioc, Alternate, Analog, Input, OpenDrain, Output, PushPull},
|
||||
i2c,
|
||||
pac::I2C1,
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use num_traits::{Float, FloatConst};
|
||||
|
||||
use xca9548a::{Error, SlaveAddr, Xca9548a};
|
||||
|
||||
use qmc5883l::{self, OutputDataRate, OversampleRate, QMC5883L};
|
||||
|
||||
use rtic_monotonics::systick::prelude::*;
|
||||
|
||||
systick_monotonic!(Mono, 1000);
|
||||
|
||||
// Shared resources go here
|
||||
#[shared]
|
||||
struct Shared {
|
||||
// TODO: Add resources
|
||||
}
|
||||
|
||||
// Local resources go here
|
||||
#[local]
|
||||
struct Local {
|
||||
i2cmux: Xca9548a<i2c::I2c<I2C1>>,
|
||||
board_led: gpioc::PC13<Output<PushPull>>,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local) {
|
||||
defmt::info!("init");
|
||||
|
||||
let rcc = cx.device.RCC.constrain();
|
||||
|
||||
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
|
||||
// `clocks`
|
||||
let clocks = rcc
|
||||
.cfgr
|
||||
.use_hse(25.MHz())
|
||||
.require_pll48clk()
|
||||
.sysclk(84.MHz())
|
||||
.hclk(84.MHz())
|
||||
.pclk1(42.MHz())
|
||||
.pclk2(84.MHz())
|
||||
.freeze();
|
||||
|
||||
Mono::start(cx.core.SYST, clocks.sysclk().to_Hz());
|
||||
|
||||
defmt::info!("Clock Setup done");
|
||||
|
||||
defmt::info!("Clock Setup done");
|
||||
|
||||
// Acquire the GPIOC peripheral
|
||||
let mut gpiob = cx.device.GPIOB.split();
|
||||
let mut gpioc = cx.device.GPIOC.split();
|
||||
|
||||
let board_led = gpioc.pc13.into_push_pull_output();
|
||||
|
||||
let scl = gpiob.pb6.into_alternate_open_drain();
|
||||
let sda = gpiob.pb7.into_alternate_open_drain();
|
||||
let mut i2c = i2c::I2c::new(
|
||||
cx.device.I2C1,
|
||||
(scl, sda),
|
||||
i2c::Mode::Standard {
|
||||
frequency: 400.kHz(),
|
||||
},
|
||||
&clocks,
|
||||
);
|
||||
|
||||
defmt::info!("I2C Setup done");
|
||||
|
||||
let mut i2cmux = Xca9548a::new(i2c, SlaveAddr::default());
|
||||
i2cmux.select_channels(0b0000_0001).unwrap();
|
||||
|
||||
defmt::info!("I2C MUX Setup done");
|
||||
|
||||
poll_i2c::spawn().ok();
|
||||
|
||||
(
|
||||
Shared {
|
||||
// Initialization of shared resources go here
|
||||
},
|
||||
Local { i2cmux, board_led },
|
||||
)
|
||||
}
|
||||
|
||||
#[task(local = [i2cmux, board_led])]
|
||||
async fn poll_i2c(cx: poll_i2c::Context) {
|
||||
let i2cmux = cx.local.i2cmux;
|
||||
let board_led = cx.local.board_led;
|
||||
|
||||
let parts = i2cmux.split();
|
||||
|
||||
let mut compass1 = QMC5883L::new(parts.i2c0).unwrap();
|
||||
compass1.reset().unwrap();
|
||||
compass1.continuous().unwrap();
|
||||
|
||||
let mut compass2 = QMC5883L::new(parts.i2c1).unwrap();
|
||||
compass2.reset().unwrap();
|
||||
compass2.continuous().unwrap();
|
||||
|
||||
let declination_rads: f32 = 65.0 / 180.0 * f32::PI();
|
||||
|
||||
loop {
|
||||
board_led.toggle();
|
||||
|
||||
loop {
|
||||
defmt::info!("Compass 1");
|
||||
match compass1.mag() {
|
||||
Ok((x, y, z)) => {
|
||||
defmt::info!("x1: {} y1: {} z1: {}", x, y, z);
|
||||
|
||||
let mut heading = (y as f32).atan2(x as f32); //+ declination_rads;
|
||||
if heading < 0.0 {
|
||||
heading += 2.0 * f32::PI();
|
||||
} else if heading > 2.0 * f32::PI() {
|
||||
heading -= 2.0 * f32::PI();
|
||||
}
|
||||
let heading_degrees = heading * 180.0 / f32::PI();
|
||||
defmt::info!("Heading1 {}", heading_degrees);
|
||||
break;
|
||||
}
|
||||
Err(qmc5883l::Error::NotReady) => {
|
||||
Mono::delay(1000.millis()).await;
|
||||
}
|
||||
e => {
|
||||
let _ = e.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loop {
|
||||
defmt::info!("Compass 2");
|
||||
match compass2.mag() {
|
||||
Ok((x, y, z)) => {
|
||||
defmt::info!("x2: {} y2: {} z2: {}", x, y, z);
|
||||
|
||||
let mut heading = (y as f32).atan2(x as f32); //+ declination_rads;
|
||||
if heading < 0.0 {
|
||||
heading += 2.0 * f32::PI();
|
||||
} else if heading > 2.0 * f32::PI() {
|
||||
heading -= 2.0 * f32::PI();
|
||||
}
|
||||
let heading_degrees = heading * 180.0 / f32::PI();
|
||||
defmt::info!("Heading2 {}", heading_degrees);
|
||||
break;
|
||||
}
|
||||
Err(qmc5883l::Error::NotReady) => {
|
||||
Mono::delay(1000.millis()).await;
|
||||
}
|
||||
e => {
|
||||
let _ = e.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mono::delay(100.millis()).await;
|
||||
}
|
||||
}
|
||||
}
|
11
memory.x
Normal file
11
memory.x
Normal file
|
@ -0,0 +1,11 @@
|
|||
MEMORY
|
||||
{
|
||||
/* NOTE K = KiBi = 1024 bytes */
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
/* This is where the call stack will be allocated. */
|
||||
/* The stack is of the full descending type. */
|
||||
/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
|
||||
_stack_start = ORIGIN(RAM) + LENGTH(RAM);
|
Loading…
Reference in a new issue