Skip to content

Commit

Permalink
Merge pull request #85 from uorocketry/panic
Browse files Browse the repository at this point in the history
Reset the board when a panic occurs.
  • Loading branch information
NoahSprenger authored Jan 30, 2024
2 parents 33206e2 + b512567 commit 481a365
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 49 deletions.
6 changes: 0 additions & 6 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ debug = true
[profile.release]
# symbols are nice and they don't increase the size on Flash
#debug = true
debug = 1
#lto = true There is an issue with this where it says the interrupts symbol is defined multiple times. Only happens for the STM32H7XX.
opt-level = 1

Expand Down
1 change: 0 additions & 1 deletion boards/camera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
cortex-m = { workspace = true }
cortex-m-rt = "^0.7.0"
cortex-m-rtic = "1.1.3"
panic-halt = "0.2.0"
systick-monotonic = "1.0.1"
defmt = "0.3.2"
postcard = "1.0.2"
Expand Down
8 changes: 7 additions & 1 deletion boards/camera/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ use hal::gpio::Pins;
use hal::gpio::{Pin, PushPullOutput, PB16, PB17};
use hal::prelude::*;
use mcan::messageram::SharedMemory;
use panic_halt as _;
use systick_monotonic::*;

/// Custom panic handler.
/// Reset the system if a panic occurs.
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
atsamd_hal::pac::SCB::sys_reset();
}

#[rtic::app(device = hal::pac, peripherals = true, dispatchers = [EVSYS_0, EVSYS_1, EVSYS_2])]
mod app {

Expand Down
1 change: 0 additions & 1 deletion boards/communication/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
cortex-m = { workspace = true }
cortex-m-rt = "^0.7.0"
cortex-m-rtic = "1.1.3"
panic-halt = "0.2.0"
systick-monotonic = "1.0.1"
defmt = "0.3.2"
postcard = "1.0.2"
Expand Down
8 changes: 4 additions & 4 deletions boards/communication/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ use atsamd_hal::pac::MCLK;
use atsamd_hal::pac::SERCOM5;
use atsamd_hal::prelude::_embedded_hal_serial_Read;
use atsamd_hal::sercom;
use atsamd_hal::sercom::uart;
use atsamd_hal::sercom::uart::Uart;
use atsamd_hal::sercom::uart::{RxDuplex, TxDuplex};
use atsamd_hal::sercom::uart;
use atsamd_hal::typelevel::Increment;
use common_arm::mcan;
use common_arm::mcan::message::{rx, Raw};
use common_arm::mcan::tx_buffers::DynTx;
use common_arm::{herror, HydraError};
use heapless::Vec;
use heapless::HistoryBuffer;
use heapless::Vec;
use mavlink::embedded::Read;
use mcan::bus::Can;
use mcan::embedded_can as ecan;
Expand Down Expand Up @@ -296,14 +296,14 @@ impl RadioManager {
self.buf.write(data);
let (_header, msg) =
mavlink::read_versioned_msg(&mut self.radio.receiver, mavlink::MavlinkVersion::V2)?;
// Do we need the header?
// Do we need the header?
match msg {
mavlink::uorocketry::MavMessage::POSTCARD_MESSAGE(msg) => {
return Ok(postcard::from_bytes::<Message>(&msg.message)?);
// weird Ok syntax to coerce to hydra error type.
}
_ => {
herror!(Error,ErrorContext::UnkownPostcardMessage);
herror!(Error, ErrorContext::UnkownPostcardMessage);
return Err(mavlink::error::MessageReadError::Io.into());
}
}
Expand Down
4 changes: 1 addition & 3 deletions boards/communication/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
//! Would've liked to have this live in common-arm-atsame but the pins and adc are not standardised
//! for all boards which poses the problem of giving an adc to a wrong pin in a generic way.
use atsamd_hal::gpio::{
Alternate, Pin, B, PB00, PB01, PB02, PB03, PB05, PB06, PB07, PB08, PB09,
};
use atsamd_hal::gpio::{Alternate, Pin, B, PB00, PB01, PB02, PB03, PB05, PB06, PB07, PB08, PB09};
use atsamd_hal::{adc::Adc, ehal::adc::OneShot, pac::ADC0, pac::ADC1};
use common_arm::HealthMonitorChannels;

Expand Down
12 changes: 9 additions & 3 deletions boards/communication/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@ use common_arm::*;
use communication::Capacities;
use communication::{RadioDevice, RadioManager};
use data_manager::DataManager;
use hal::adc::Adc;
use hal::clock::v2::pclk::Pclk;
use hal::clock::v2::Source;
use health::HealthMonitorChannelsCommunication;
use hal::adc::Adc;
use hal::gpio::Pins;
use hal::gpio::{
Alternate, Output, Pin, PushPull, PushPullOutput, C, PA05, PB12, PB13, PB14, PB15,
};
use hal::prelude::*;
use hal::sercom::{spi, spi::Config, spi::Duplex, spi::Pads, spi::Spi, IoSet1, Sercom4};
use health::HealthMonitorChannelsCommunication;
use mcan::messageram::SharedMemory;
use messages::command::RadioRate;
use messages::health::Health;
use messages::state::State;
use messages::*;
use panic_halt as _;
use systick_monotonic::*;
use types::*;

/// Custom panic handler.
/// Reset the system if a panic occurs.
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
atsamd_hal::pac::SCB::sys_reset();
}

#[rtic::app(device = hal::pac, peripherals = true, dispatchers = [EVSYS_0, EVSYS_1, EVSYS_2])]
mod app {

Expand Down
4 changes: 2 additions & 2 deletions boards/communication/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use atsamd_hal::gpio::*;
use atsamd_hal::sercom::uart::EightBit;
use atsamd_hal::sercom::{uart, IoSet1, Sercom5};
use atsamd_hal::gpio::*;
use messages::sender::Sender;
use messages::sender::Sender::CommunicationBoard;

Expand All @@ -13,4 +13,4 @@ pub static COM_ID: Sender = CommunicationBoard;
// Ground Station
// -------
pub type GroundStationPads = uart::PadsFromIds<Sercom5, IoSet1, PB17, PB16>;
pub type GroundStationUartConfig = uart::Config<GroundStationPads, EightBit>;
pub type GroundStationUartConfig = uart::Config<GroundStationPads, EightBit>;
1 change: 0 additions & 1 deletion boards/power/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
cortex-m = { workspace = true }
cortex-m-rt = "^0.7.0"
cortex-m-rtic = "1.1.3"
panic-halt = "0.2.0"
systick-monotonic = "1.0.1"
defmt = "0.3.2"
postcard = "1.0.2"
Expand Down
8 changes: 7 additions & 1 deletion boards/power/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ use hal::clock::v2::Source;
use hal::gpio::{Pin, Pins, PushPullOutput, PB16, PB17};
use hal::prelude::*;
use mcan::messageram::SharedMemory;
use panic_halt as _;
use systick_monotonic::*;

/// Custom panic handler.
/// Reset the system if a panic occurs.
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
atsamd_hal::pac::SCB::sys_reset();
}

#[rtic::app(device = hal::pac, peripherals = true, dispatchers = [EVSYS_0, EVSYS_1, EVSYS_2])]
mod app {
use super::*;
Expand Down
1 change: 0 additions & 1 deletion boards/recovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
cortex-m = { workspace = true }
cortex-m-rt = "^0.7.0"
cortex-m-rtic = "1.1.3"
panic-halt = "0.2.0"
systick-monotonic = "1.0.1"
defmt = "0.3.2"
postcard = "1.0.2"
Expand Down
20 changes: 12 additions & 8 deletions boards/recovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ use hal::gpio::{Pin, Pins, PushPullOutput, PB16, PB17};
use hal::prelude::*;
use mcan::messageram::SharedMemory;
use messages::*;
use panic_halt as _;
use state_machine::{StateMachine, StateMachineContext};
use systick_monotonic::*;
use types::COM_ID;

/// Custom panic handler.
/// Reset the system if a panic occurs.
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
atsamd_hal::pac::SCB::sys_reset();
}

#[rtic::app(device = hal::pac, peripherals = true, dispatchers = [EVSYS_0, EVSYS_1, EVSYS_2])]
mod app {
use super::*;
Expand Down Expand Up @@ -184,14 +190,12 @@ mod app {
#[task(binds = CAN0, shared = [can0, data_manager, &em])]
fn can0(mut cx: can0::Context) {
cx.shared.can0.lock(|can| {
cx.shared
.data_manager
.lock(|data_manager| {
cx.shared.em.run(|| {
can.process_data(data_manager)?;
Ok(())
});
cx.shared.data_manager.lock(|data_manager| {
cx.shared.em.run(|| {
can.process_data(data_manager)?;
Ok(())
});
});
});
}

Expand Down
1 change: 0 additions & 1 deletion boards/sensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
cortex-m = { workspace = true }
cortex-m-rt = "^0.7.0"
cortex-m-rtic = "1.1.3"
panic-halt = "0.2.0"
systick-monotonic = "1.0.1"
defmt = "0.3.2"
postcard = "1.0.2"
Expand Down
22 changes: 12 additions & 10 deletions boards/sensor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ use hal::sercom::{spi, IoSet2, Sercom4};
use mcan::messageram::SharedMemory;
use messages::sensor::Sensor;
use messages::*;
use panic_halt as _;
use sbg_manager::{sbg_dma, sbg_handle_data, sbg_sd_task, SBGManager};
//use sbg_manager::{sbg_dma, sbg_handle_data, SBGManager};

use sbg_rs::sbg::{CallbackData, SBG_BUFFER_SIZE};

use systick_monotonic::*;
use types::*;

/// Custom panic handler.
/// Reset the system if a panic occurs.
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
atsamd_hal::pac::SCB::sys_reset();
}

#[rtic::app(device = hal::pac, peripherals = true, dispatchers = [EVSYS_0, EVSYS_1, EVSYS_2])]
mod app {
use super::*;
Expand Down Expand Up @@ -182,14 +186,12 @@ mod app {
#[task(priority = 3, binds = CAN0, shared = [can, data_manager, &em])]
fn can0(mut cx: can0::Context) {
cx.shared.can.lock(|can| {
cx.shared
.data_manager
.lock(|manager| {
cx.shared.em.run(|| {
can.process_data(manager)?;
Ok(())
});
cx.shared.data_manager.lock(|manager| {
cx.shared.em.run(|| {
can.process_data(manager)?;
Ok(())
});
});
});
}

Expand Down
1 change: 0 additions & 1 deletion boards/sensor_v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
panic-halt = "0.2.0"
cortex-m = { workspace = true }
cortex-m-rt = "^0.7.0"
cortex-m-rtic = "1.1.3"
Expand Down
7 changes: 6 additions & 1 deletion boards/sensor_v2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ use stm32h7xx_hal::gpio::Input;
use stm32h7xx_hal::gpio::{Output, PushPull};
use stm32h7xx_hal::prelude::*;

use panic_halt as _;
/// Custom panic handler.
/// Reset the system if a panic occurs.
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
stm32h7xx_hal::pac::SCB::sys_reset();
}

#[rtic::app(device = stm32h7xx_hal::stm32, dispatchers = [EXTI0, EXTI1])]
mod app {
Expand Down
7 changes: 3 additions & 4 deletions libraries/common-arm/src/health/health_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ fn get_status(data: Option<u16>, nominal: &RangeInclusive<u16>) -> HealthState {
Some(x) => {
if nominal.contains(&x) {
return HealthState::Nominal;
}
else {
warn!("Unsafe Voltage");
} else {
// warn!("Unsafe Voltage");
HealthState::Error
}
},
}
None => {
warn!("No data");
return HealthState::Warning;
Expand Down

0 comments on commit 481a365

Please sign in to comment.