Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add panic handler #655

Draft
wants to merge 6 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/synthesis/debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"top": "vexRiscvTcpTest", "stage": "test"}
]
7 changes: 0 additions & 7 deletions firmware-binaries/clock-control-reg-cpy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,3 @@ fn main() -> ! {
cc.change_speed(change);
}
}

#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
loop {
continue;
}
}
9 changes: 0 additions & 9 deletions firmware-binaries/clock-control/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//
// SPDX-License-Identifier: Apache-2.0

use core::panic::PanicInfo;

use bittide_sys::{
callisto::{self, ControlConfig, ControlSt, ReframingState},
clock_control::{ClockControl, SpeedChange},
Expand Down Expand Up @@ -40,10 +38,3 @@ fn main() -> ! {
cc.change_speed(state.b_k);
}
}

#[panic_handler]
fn panic_handler(_info: &PanicInfo) -> ! {
loop {
continue;
}
}
2 changes: 1 addition & 1 deletion firmware-binaries/examples/smoltcp_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Google LLC"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bittide-sys = { path = "../../../firmware-support/bittide-sys" }
bittide-sys = { path = "../../../firmware-support/bittide-sys", features = ["panic_handler_log"]}
riscv-rt = "0.11.0"
riscv = "^0.10"
heapless = { version = "0.8", default-features = false}
Expand Down
12 changes: 0 additions & 12 deletions firmware-binaries/examples/smoltcp_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,6 @@ fn exception_handler(_trap_frame: &riscv_rt::TrapFrame) -> ! {
}
}

#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
let mut uart = unsafe { Uart::new(UART_ADDR) };

uwriteln!(uart, "Panicked!").unwrap();
debug!("{}", info);
uwriteln!(uart, "Looping forever now").unwrap();
loop {
continue;
}
}

fn update_dhcp(iface: &mut Interface, socket: &mut dhcpv4::Socket) {
let event = socket.poll();
match event {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ authors = ["Google LLC"]

[dependencies]
riscv-rt = "0.11.0"
bittide-sys = { path = "../../../firmware-support/bittide-sys" }
bittide-sys = { path = "../../../firmware-support/bittide-sys", features = ["panic_handler_log"]}
ufmt = "0.2.0"
11 changes: 0 additions & 11 deletions firmware-binaries/test-cases/axi_stream_self_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//
// SPDX-License-Identifier: Apache-2.0

use ufmt::uwriteln;

use bittide_sys::axi::self_test::self_test;
use bittide_sys::axi::{AxiRx, AxiTx};
use bittide_sys::uart::Uart;
Expand All @@ -26,12 +24,3 @@ fn main() -> ! {
continue;
}
}

#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
let mut uart = unsafe { Uart::new(UART_ADDR) };
uwriteln!(uart, "Woops, I panicked!").unwrap();
loop {
continue;
}
}
2 changes: 1 addition & 1 deletion firmware-binaries/test-cases/capture_ugn_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ authors = ["Google LLC"]

[dependencies]
riscv-rt = "0.11.0"
bittide-sys = { path = "../../../firmware-support/bittide-sys" }
bittide-sys = { path = "../../../firmware-support/bittide-sys", features = ["panic_handler_log"]}
ufmt = "0.2.0"
7 changes: 0 additions & 7 deletions firmware-binaries/test-cases/capture_ugn_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,3 @@ fn main() -> ! {
continue;
}
}

#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
loop {
continue;
}
}
2 changes: 1 addition & 1 deletion firmware-binaries/test-cases/dna_port_e2_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ authors = ["Google LLC"]

[dependencies]
riscv-rt = "0.11.0"
bittide-sys = { path = "../../../firmware-support/bittide-sys" }
bittide-sys = { path = "../../../firmware-support/bittide-sys", features = ["panic_handler_log"]}
ufmt = "0.2.0"
7 changes: 0 additions & 7 deletions firmware-binaries/test-cases/dna_port_e2_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,3 @@ fn main() -> ! {
continue;
}
}

#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
loop {
continue;
}
}
2 changes: 1 addition & 1 deletion firmware-binaries/test-cases/time_self_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ authors = ["Google LLC"]

[dependencies]
riscv-rt = "0.11.0"
bittide-sys = { path = "../../../firmware-support/bittide-sys" }
bittide-sys = { path = "../../../firmware-support/bittide-sys", default-features = false }
ufmt = "0.2.0"
7 changes: 0 additions & 7 deletions firmware-binaries/test-cases/time_self_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,3 @@ fn main() -> ! {
continue;
}
}

#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
loop {
continue;
}
}
1 change: 1 addition & 0 deletions firmware-support/bittide-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resolver = "2"

[features]
default = []
panic_handler_log = []

[dependencies]
fdt = "0.1.0"
Expand Down
23 changes: 22 additions & 1 deletion firmware-support/bittide-sys/src/uart/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use crate::{time, uart};
use core::fmt::Write;
use log::LevelFilter;

use core::panic::PanicInfo;
use log::error;
use ufmt::uwriteln;

/// A global logger instance to be used with the `log` crate.
///
/// Use `set_logger` to set the `Uart` instance to be used for logging.
Expand Down Expand Up @@ -76,7 +80,7 @@ impl log::Log for UartLogger {
}
writeln!(l, "{}", record.args()).unwrap();
}
None => panic!("Logger not set"),
None => loop {}, // The panic handler uses the same logger, so we can't panic here.
}
}
}
Expand All @@ -87,3 +91,20 @@ impl log::Log for UartLogger {

unsafe impl core::marker::Send for UartLogger {}
unsafe impl core::marker::Sync for UartLogger {}

#[cfg_attr(feature = "panic_handler_log", panic_handler)]
pub fn panic_handler(info: &PanicInfo) -> ! {
unsafe {
match LOGGER.uart {
Some(ref mut uart) => {
uwriteln!(uart, "Panicked!").ok();
error!("{}", info);
uwriteln!(uart, "Looping forever now").ok();
}
None => panic!("Logger not set"),
}
}
loop {
continue;
}
}
2 changes: 1 addition & 1 deletion host-tools/callisto-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bittide-sys = { path = "../../firmware-support/bittide-sys" }
bittide-sys = { path = "../../firmware-support/bittide-sys", default-features = false, features = []}

[lib]
crate-type = ["staticlib"]
Loading