Skip to content

Commit

Permalink
in progress rust, flashes and LEDs work
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed Oct 11, 2024
1 parent 58498c7 commit 3042712
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 128 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["msb-fw-rs", "cerberus", "wheel", "crates/*"]
members = ["msb-fw-rs","crates/*"]
resolver = "2"

[workspace.dependencies]
Expand All @@ -19,7 +19,7 @@ embedded-hal = { version = "1.0.0", features = ["defmt-03"] }
embedded-hal-bus = { version = "0.2", features = ["async", "defmt-03"] }
embedded-io = { version = "0.6.0", features = ["defmt-03"] }
embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
panic-probe = { version = "0.3", features = ["print-defmt"] }
panic-probe = { version = "0.3", features = ["print-defmt", "defmt-error"] }
heapless = { version = "0.8", default-features = false }
static_cell = "2.1.0"
#chrono = { version = "^0.4", default-features = false}
Expand All @@ -43,4 +43,4 @@ lto = "fat"
incremental = false
codegen-units = 1
# note: debug = true is okay - debuginfo isn't flashed to the device!
debug = true
debug = true
41 changes: 41 additions & 0 deletions Embed.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
[default.general]
chip = "STM32F405RGTx"

[default.rtt]
enabled = false

[default.probe]
# USB vendor ID
# usb_vid = "0403"
protocol = "Jtag"

[default.flashing]
# Whether or not the target should be flashed.
enabled = true

[default.reset]
# Whether or not the target should be reset.
# When flashing is enabled as well, the target will be reset after flashing regardless of this setting.
enabled = true
# Whether or not the target should be halted after reset.


[default.gdb]
# Whether or not a GDB server should be opened after flashing.
enabled = false

# GDB + RTT
[gdb.gdb]
enabled = true
[gdb.rtt]
enabled = true
[gdb.flashing]
halt_afterwards = true

# JUST RTT
[with_rtt.rtt]
enabled = true

# JUST RTT, NO FLASH
[rtt.rtt]
enabled = true
[rtt.flashing]
enabled = false
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ To format, run `cargo format`.

To lint and check stuff, run `cargo clippy`.

### On car stuff

To run a RTT terminal dedicated:
`cargo embed --release --config rtt`

To run a GDB terminal dedicated:
`cargo embed --release --config gdb`

To flash and leave code:
`cargo embed --release --config `



### Coding tips and tricks

Expand All @@ -32,11 +44,11 @@ This is a mega-repo configured as a normal embassy-styled project with multiple

Various files:

Top level `Cargo.toml`, `Embed.toml`, `build.rs`, and `rust-toolchain.toml` define the various parts of the embassy project. See comments inside for how these were structure, but most follow embassy specification.
Top level `Cargo.toml`, `Embed.toml`, and `rust-toolchain.toml` define the various parts of the embassy project. See comments inside for how these were structure, but most follow embassy specification.

The `crates` folder defines drivers or other code shared between projects.

Top level folders like `msb-fw-rs`, and any other project, define projects which inherit explicity defined `Cargo.toml` dependencies, `build.rs` and `Embed.toml` settings, and more. They can also depend on a crate in the `crates` folder.
Top level folders like `msb-fw-rs`, and any other project, define projects which inherit explicity defined `Cargo.toml` dependencies and `Embed.toml` settings, and more. They can also depend on a crate in the `crates` folder.

This structure has multiple benefits, including:
- Static versioning of all embassy and other dependencies, eliminating version conflicts for in-tree code
Expand Down
67 changes: 67 additions & 0 deletions derivation.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{ lib
, stdenv
, rustPlatform
, fetchFromGitHub
, cmake
, gitMinimal
, pkg-config
, libusb1
, openssl
}:

rustPlatform.buildRustPackage rec {
pname = "probe-rs-tools";
version = "0.24.1";

src = fetchFromGitHub {
owner = "probe-rs";
repo = "probe-rs";
rev = "b58d8e0a6fd6922044b9be676da6ea42f6018c7a";
hash = "sha256-LKVxGWD8/NVe0VgpoH4JZ1r01FwJc6P1vS39jnW3KVU=";
};

cargoHash = "sha256-REnXGLpIxnHG62Pge37Fnf3ovWJwd2LWjr/RisS+Gog=";

buildAndTestSubdir = pname;

nativeBuildInputs = [
# required by libz-sys, no option for dynamic linking
# https://github.com/rust-lang/libz-sys/issues/158
cmake
# build.rs fails without git
# https://github.com/probe-rs/probe-rs/pull/2492
gitMinimal
pkg-config
];

buildInputs = [ libusb1 openssl ];

checkFlags = [
# require a physical probe
"--skip=cmd::dap_server::server::debugger::test::attach_request"
"--skip=cmd::dap_server::server::debugger::test::attach_with_flashing"
"--skip=cmd::dap_server::server::debugger::test::launch_and_threads"
"--skip=cmd::dap_server::server::debugger::test::launch_with_config_error"
"--skip=cmd::dap_server::server::debugger::test::test_initalize_request"
"--skip=cmd::dap_server::server::debugger::test::test_launch_and_terminate"
"--skip=cmd::dap_server::server::debugger::test::test_launch_no_probes"
"--skip=cmd::dap_server::server::debugger::test::wrong_request_after_init"
# compiles an image for an embedded target which we do not have a toolchain for
"--skip=util::cargo::test::get_binary_artifact_with_cargo_config"
"--skip=util::cargo::test::get_binary_artifact_with_cargo_config_toml"
# requires other crates in the workspace
"--skip=util::cargo::test::get_binary_artifact"
"--skip=util::cargo::test::library_with_example_specified"
"--skip=util::cargo::test::multiple_binaries_in_crate_select_binary"
"--skip=util::cargo::test::workspace_binary_package"
"--skip=util::cargo::test::workspace_root"
];

meta = with lib; {
description = "CLI tool for on-chip debugging and flashing of ARM chips";
homepage = "https://probe.rs/";
changelog = "https://github.com/probe-rs/probe-rs/blob/v${version}/CHANGELOG.md";
license = with licenses; [ asl20 /* or */ mit ];
maintainers = with maintainers; [ xgroleau newam ];
};
}
1 change: 1 addition & 0 deletions build.rs → msb-fw-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ fn main() {
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
println!("cargo:rerun-if-changed=memory.x");
}
3 changes: 2 additions & 1 deletion msb-fw-rs/src/can_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ use crate::DeviceLocation;

const CAN_BITRATE: u32 = 500_000;


#[embassy_executor::task]
pub async fn can_handler(
mut can: Can<'static>,
recv: Receiver<'static, ThreadModeRawMutex, Frame, 25>,
loc: DeviceLocation,
) {
can.set_bitrate(CAN_BITRATE);
trace!("Attempting to enable CAN..");
can.enable().await;
trace!("CAN enabled");

loop {
let frame = recv.receive().await;
Expand Down
57 changes: 40 additions & 17 deletions msb-fw-rs/src/controllers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,56 @@ use embassy_time::{Duration, Timer};

use crate::DeviceLocation;

const LED_REFRESH_TIME: Duration = Duration::from_secs(2);
const LED_REFRESH_TIME: Duration = Duration::from_millis(250);

#[embassy_executor::task]
pub async fn control_leds(
mut led1: Output<'static>,
mut led2: Output<'static>,
device_loc: DeviceLocation,
) {
let mut i = 0u8;
loop {
Timer::after(LED_REFRESH_TIME).await;
match device_loc {
DeviceLocation::FrontLeft => {
led1.set_high();
led2.set_high();
}
DeviceLocation::BackLeft => {
led1.set_low();
led2.set_high();
if i % 8 == 0 {
match device_loc {
DeviceLocation::FrontLeft => {
led1.set_low();
led2.set_low();
}
DeviceLocation::FrontRight => {
led1.set_low();
led2.set_high();
}
DeviceLocation::BackLeft => {
led1.set_high();
led2.set_low();
}
DeviceLocation::BackRight => {
led1.set_high();
led2.set_high();
}
}
DeviceLocation::BackRight => {
led1.set_low();
led2.set_low();
}
DeviceLocation::FrontRight => {
led1.set_high();
led2.set_low();
} else {
match device_loc {
DeviceLocation::FrontLeft => {
led1.set_high();
led2.set_high();
}
DeviceLocation::FrontRight => {
led1.set_high();
led2.set_low();
}
DeviceLocation::BackLeft => {
led1.set_low();
led2.set_high();
}
DeviceLocation::BackRight => {
led1.set_low();
led2.set_low();
}
}
}
i = i.wrapping_add(1);
Timer::after(LED_REFRESH_TIME).await;
}
}
3 changes: 2 additions & 1 deletion msb-fw-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![feature(impl_trait_in_assoc_type)]
#![feature(const_option)]


// declare all files in this project except main
pub mod can_handler;
pub mod controllers;
Expand All @@ -15,7 +16,7 @@ pub type SharedI2c3 = embassy_sync::mutex::Mutex<
embassy_sync::blocking_mutex::raw::NoopRawMutex,
embassy_stm32::i2c::I2c<'static, embassy_stm32::mode::Async>,
>;
#[derive(Clone)]
#[derive(Clone, defmt::Format)]
pub enum DeviceLocation {
FrontLeft,
BackLeft,
Expand Down
Loading

0 comments on commit 3042712

Please sign in to comment.