Skip to content

Commit

Permalink
WIP: Test pinout compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSprenger committed Jul 8, 2024
1 parent 98f64d3 commit 675e473
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 19 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 7 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
[workspace]
resolver = "2"

members = [
"boards/*",
"examples/*",
"libraries/*"
]
members = ["boards/*", "examples/*", "libraries/*"]

# Specify which members to build by default. Some libraries, such as messages, contain dev-dependencies that will give
# compile errors if built directly.
default-members = [
"boards/*",
"examples/*"
]
default-members = ["boards/*", "examples/*"]

[workspace.dependencies.embedded-hal]
version="0.2.7"
version = "0.2.7"

[workspace.dependencies.stm32h7xx-hal]
git = "https://github.com/stm32-rs/stm32h7xx-hal"
git = "https://github.com/stm32-rs/stm32h7xx-hal"
# We use 35 even though we have the 33.
features = ["defmt", "rt", "stm32h735" ]
features = ["defmt", "rt", "stm32h735", "can"]

[workspace.dependencies.atsamd-hal]
git = "https://github.com/uorocketry/atsamd"
Expand Down Expand Up @@ -70,4 +63,5 @@ opt-level = 0

#Try to remove this
[profile.release.build-override]
#opt-level = 0
#opt-level = 0

5 changes: 3 additions & 2 deletions boards/nav/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ edition = "2021"
cortex-m = { workspace = true }
cortex-m-rt = "^0.7.0"
cortex-m-rtic = "1.1.3"
common-arm-stm32h7 = {path = "../../libraries/common-arm-stm32h7"}
common-arm = {path = "../../libraries/common-arm"}
common-arm-stm32h7 = { path = "../../libraries/common-arm-stm32h7" }
common-arm = { path = "../../libraries/common-arm" }
stm32h7xx-hal = { workspace = true }
postcard = "1.0.2"
messages = { path = "../../libraries/messages" }
systick-monotonic = "1.0.1"
defmt = "0.3.2"
fdcan = "0.2"
59 changes: 59 additions & 0 deletions boards/nav/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@
mod data_manager;

use common_arm::*;
use core::num::{NonZeroU16, NonZeroU8};
use data_manager::DataManager;
use defmt::info;
use fdcan::{
config::NominalBitTiming,
filter::{StandardFilter, StandardFilterSlot},
frame::{FrameFormat, TxFrameHeader},
id::StandardId,
};
use stm32h7xx_hal::gpio::gpioa::{PA1, PA2};
use stm32h7xx_hal::gpio::gpioc::{PC13, PC3};
use stm32h7xx_hal::gpio::Input;
use stm32h7xx_hal::gpio::Speed;
use stm32h7xx_hal::gpio::{Output, PushPull};
use stm32h7xx_hal::pac;
use stm32h7xx_hal::prelude::*;
use stm32h7xx_hal::spi;
use stm32h7xx_hal::{rcc, rcc::rec};
use systick_monotonic::*;

/// Custom panic handler.
Expand Down Expand Up @@ -52,16 +63,64 @@ mod app {
let ccdr = rcc
.use_hse(48.MHz())
.sys_ck(300.MHz())
.pll1_strategy(rcc::PllConfigStrategy::Iterative)
.pll1_q_ck(24.MHz())
.freeze(pwrcfg, &ctx.device.SYSCFG);

let btr = NominalBitTiming {
prescaler: NonZeroU16::new(12).unwrap(),
seg1: NonZeroU8::new(13).unwrap(),
seg2: NonZeroU8::new(2).unwrap(),
sync_jump_width: NonZeroU8::new(1).unwrap(),
};

// GPIO
let gpioc = ctx.device.GPIOC.split(ccdr.peripheral.GPIOC);
let gpioa = ctx.device.GPIOA.split(ccdr.peripheral.GPIOA);
let gpiod = ctx.device.GPIOD.split(ccdr.peripheral.GPIOD);
let gpiob = ctx.device.GPIOB.split(ccdr.peripheral.GPIOB);
assert_eq!(ccdr.clocks.pll1_q_ck().unwrap().raw(), 24_000_000);
let fdcan_prec = ccdr
.peripheral
.FDCAN
.kernel_clk_mux(rec::FdcanClkSel::Pll1Q);

let can1 = {
let rx = gpiob.pb12.into_alternate().speed(Speed::VeryHigh);
let tx = gpiob.pb13.into_alternate().speed(Speed::VeryHigh);
ctx.device.FDCAN2.fdcan(tx, rx, fdcan_prec)
};

let mut can = can1;
can.set_protocol_exception_handling(false);

can.set_nominal_bit_timing(btr);

can.set_standard_filter(
StandardFilterSlot::_0,
StandardFilter::accept_all_into_fifo0(),
);

let (sck, miso, mosi) = (gpioa.pa5, gpioa.pa6, gpioa.pa7);

let spi = ctx
.device
.SPI1
.spi((sck, miso, mosi), spi::MODE_0, 1.MHz(), &ccdr.clocks);

// leds
let mut led_red = gpioa.pa1.into_push_pull_output();
let mut led_green = gpioa.pa2.into_push_pull_output();

// UART for sbg
let tx = gpiod.pd1.into_alternate();
let rx = gpiod.pd0.into_alternate();

let serial = ctx
.device
.UART4
.serial((tx, rx), 9_800.bps(), ccdr.peripheral.UART4, &ccdr.clocks)
.unwrap();
blink::spawn().ok();

/* Monotonic clock */
Expand Down
4 changes: 3 additions & 1 deletion libraries/common-arm-atsame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ edition = "2021"
[dependencies]
common-arm = { path = "../common-arm" }
atsamd-hal = { workspace = true }
embedded-hal = {workspace = true }
embedded-hal = { workspace = true }
mcan = "0.3"

2 changes: 2 additions & 0 deletions libraries/common-arm-atsame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
//! This crate contains common code for HYDRA. Any code that is not board specific but is ATSAME specific should be put in
//! here.
//!
pub use mcan;
2 changes: 1 addition & 1 deletion libraries/common-arm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ derive_more = "0.99.17"
cortex-m-rt = "^0.7.0"
embedded-sdmmc = "0.3.0"
embedded-hal = "0.2.7"
mcan = "0.3"
nb = "1.1.0"
mcan = "0.3.0"
messages = { path = "../messages" }
2 changes: 0 additions & 2 deletions libraries/common-arm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! here.
//!
pub use mcan;

mod error;
mod health;
mod logging;
Expand Down

0 comments on commit 675e473

Please sign in to comment.