From ab0e87ca3174ab22e5ce7a4081e923b2f3ff3788 Mon Sep 17 00:00:00 2001 From: Lucas Bollen Date: Fri, 18 Oct 2024 11:33:57 +0200 Subject: [PATCH 1/6] Move `panic_handler` to `uart::log` --- .../clock-control-reg-cpy/src/main.rs | 7 ------- firmware-binaries/clock-control/src/main.rs | 7 ------- firmware-binaries/examples/hello/src/main.rs | 8 ------- .../examples/smoltcp_client/src/main.rs | 12 ----------- .../processing-element-test/src/main.rs | 10 --------- .../axi_stream_self_test/src/main.rs | 9 -------- .../test-cases/capture_ugn_test/src/main.rs | 7 ------- .../test-cases/dna_port_e2_test/src/main.rs | 7 ------- .../test-cases/time_self_test/src/main.rs | 7 ------- firmware-support/bittide-sys/src/uart/log.rs | 21 +++++++++++++++++++ 10 files changed, 21 insertions(+), 74 deletions(-) diff --git a/firmware-binaries/clock-control-reg-cpy/src/main.rs b/firmware-binaries/clock-control-reg-cpy/src/main.rs index 41a8515bc..2e9f57d82 100644 --- a/firmware-binaries/clock-control-reg-cpy/src/main.rs +++ b/firmware-binaries/clock-control-reg-cpy/src/main.rs @@ -28,10 +28,3 @@ fn main() -> ! { cc.change_speed(change); } } - -#[panic_handler] -fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop { - continue; - } -} diff --git a/firmware-binaries/clock-control/src/main.rs b/firmware-binaries/clock-control/src/main.rs index 8548ee973..15ff9127b 100644 --- a/firmware-binaries/clock-control/src/main.rs +++ b/firmware-binaries/clock-control/src/main.rs @@ -39,10 +39,3 @@ fn main() -> ! { cc.change_speed(state.b_k); } } - -#[panic_handler] -fn panic_handler(_info: &PanicInfo) -> ! { - loop { - continue; - } -} diff --git a/firmware-binaries/examples/hello/src/main.rs b/firmware-binaries/examples/hello/src/main.rs index 6ea1b6a34..543c169d6 100644 --- a/firmware-binaries/examples/hello/src/main.rs +++ b/firmware-binaries/examples/hello/src/main.rs @@ -45,11 +45,3 @@ fn main() -> ! { uart.send(c); } } - -#[panic_handler] -fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - test_failure(); - loop { - continue; - } -} diff --git a/firmware-binaries/examples/smoltcp_client/src/main.rs b/firmware-binaries/examples/smoltcp_client/src/main.rs index ef4e83380..39c8a8c7b 100644 --- a/firmware-binaries/examples/smoltcp_client/src/main.rs +++ b/firmware-binaries/examples/smoltcp_client/src/main.rs @@ -178,18 +178,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(); - info!("error: {}\n", 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 { diff --git a/firmware-binaries/processing-element-test/src/main.rs b/firmware-binaries/processing-element-test/src/main.rs index 5bd72f267..70cac6f74 100644 --- a/firmware-binaries/processing-element-test/src/main.rs +++ b/firmware-binaries/processing-element-test/src/main.rs @@ -5,8 +5,6 @@ // // SPDX-License-Identifier: Apache-2.0 -use core::panic::PanicInfo; - #[cfg(not(test))] use riscv_rt::entry; @@ -47,11 +45,3 @@ fn main() -> ! { continue; } } - -#[panic_handler] -fn panic_handler(_info: &PanicInfo) -> ! { - test_failure(); - loop { - continue; - } -} diff --git a/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs b/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs index 945899f02..6174e24d5 100644 --- a/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs +++ b/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs @@ -26,12 +26,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; - } -} diff --git a/firmware-binaries/test-cases/capture_ugn_test/src/main.rs b/firmware-binaries/test-cases/capture_ugn_test/src/main.rs index dcda62354..a659c1174 100644 --- a/firmware-binaries/test-cases/capture_ugn_test/src/main.rs +++ b/firmware-binaries/test-cases/capture_ugn_test/src/main.rs @@ -31,10 +31,3 @@ fn main() -> ! { continue; } } - -#[panic_handler] -fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop { - continue; - } -} diff --git a/firmware-binaries/test-cases/dna_port_e2_test/src/main.rs b/firmware-binaries/test-cases/dna_port_e2_test/src/main.rs index dcd47f22b..5410cdb0a 100644 --- a/firmware-binaries/test-cases/dna_port_e2_test/src/main.rs +++ b/firmware-binaries/test-cases/dna_port_e2_test/src/main.rs @@ -23,10 +23,3 @@ fn main() -> ! { continue; } } - -#[panic_handler] -fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop { - continue; - } -} diff --git a/firmware-binaries/test-cases/time_self_test/src/main.rs b/firmware-binaries/test-cases/time_self_test/src/main.rs index 07c0a5432..c6ae296de 100644 --- a/firmware-binaries/test-cases/time_self_test/src/main.rs +++ b/firmware-binaries/test-cases/time_self_test/src/main.rs @@ -30,10 +30,3 @@ fn main() -> ! { continue; } } - -#[panic_handler] -fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop { - continue; - } -} diff --git a/firmware-support/bittide-sys/src/uart/log.rs b/firmware-support/bittide-sys/src/uart/log.rs index be2be169b..66c95fb7e 100644 --- a/firmware-support/bittide-sys/src/uart/log.rs +++ b/firmware-support/bittide-sys/src/uart/log.rs @@ -7,6 +7,10 @@ use crate::{time, uart}; // compatible with (dependencies of) the log crate. use core::fmt::Write; use log::LevelFilter; +use core::panic::PanicInfo; +use log::warn; +use ufmt::uwriteln; + /// A global logger instance to be used with the `log` crate. /// @@ -87,3 +91,20 @@ impl log::Log for UartLogger { unsafe impl core::marker::Send for UartLogger {} unsafe impl core::marker::Sync for UartLogger {} + +#[panic_handler] +fn panic_handler(info: &PanicInfo) -> ! { + unsafe { + match LOGGER.uart { + Some(ref mut uart) => { + uwriteln!(uart, "Panicked!").ok(); + warn!("{}", info); + uwriteln!(uart, "Looping forever now").ok(); + } + None => panic!("Logger not set"), + } + } + loop { + continue; + } +} From d1ccf265a972c68cd5fa612636cf42617658d58b Mon Sep 17 00:00:00 2001 From: Lucas Bollen Date: Fri, 18 Oct 2024 11:34:36 +0200 Subject: [PATCH 2/6] Add `debug.json` --- .github/synthesis/debug.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/synthesis/debug.json diff --git a/.github/synthesis/debug.json b/.github/synthesis/debug.json new file mode 100644 index 000000000..8e40bd370 --- /dev/null +++ b/.github/synthesis/debug.json @@ -0,0 +1,3 @@ +[ + {"top": "vexRiscvTcpTest", "stage": "test"} +] From c707d8a6c01585ff4e245567a0f01d94da5a2365 Mon Sep 17 00:00:00 2001 From: Lucas Bollen Date: Fri, 18 Oct 2024 11:37:06 +0200 Subject: [PATCH 3/6] `uart::log` loop instead of panic if the uart peripheral is not defined --- firmware-support/bittide-sys/src/uart/log.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware-support/bittide-sys/src/uart/log.rs b/firmware-support/bittide-sys/src/uart/log.rs index 66c95fb7e..94c2bb8bc 100644 --- a/firmware-support/bittide-sys/src/uart/log.rs +++ b/firmware-support/bittide-sys/src/uart/log.rs @@ -80,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. } } } From 0794b00a1d0b83fa9701391c6e5a79e8153b975d Mon Sep 17 00:00:00 2001 From: Lucas Bollen Date: Fri, 18 Oct 2024 11:37:42 +0200 Subject: [PATCH 4/6] `uart::log` raise verbosity level of panic handler from `warn` to `error` --- firmware-support/bittide-sys/src/uart/log.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware-support/bittide-sys/src/uart/log.rs b/firmware-support/bittide-sys/src/uart/log.rs index 94c2bb8bc..1f06f427a 100644 --- a/firmware-support/bittide-sys/src/uart/log.rs +++ b/firmware-support/bittide-sys/src/uart/log.rs @@ -8,7 +8,7 @@ use crate::{time, uart}; use core::fmt::Write; use log::LevelFilter; use core::panic::PanicInfo; -use log::warn; +use log::error; use ufmt::uwriteln; @@ -98,7 +98,7 @@ fn panic_handler(info: &PanicInfo) -> ! { match LOGGER.uart { Some(ref mut uart) => { uwriteln!(uart, "Panicked!").ok(); - warn!("{}", info); + error!("{}", info); uwriteln!(uart, "Looping forever now").ok(); } None => panic!("Logger not set"), From 36d8ba988b6a4a149cf05a1dc5d7eba4cc2b5470 Mon Sep 17 00:00:00 2001 From: Lucas Bollen Date: Fri, 18 Oct 2024 11:48:21 +0200 Subject: [PATCH 5/6] fixup! Move `panic_handler` to `uart::log` --- firmware-binaries/processing-element-test/src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/firmware-binaries/processing-element-test/src/main.rs b/firmware-binaries/processing-element-test/src/main.rs index 70cac6f74..5bd72f267 100644 --- a/firmware-binaries/processing-element-test/src/main.rs +++ b/firmware-binaries/processing-element-test/src/main.rs @@ -5,6 +5,8 @@ // // SPDX-License-Identifier: Apache-2.0 +use core::panic::PanicInfo; + #[cfg(not(test))] use riscv_rt::entry; @@ -45,3 +47,11 @@ fn main() -> ! { continue; } } + +#[panic_handler] +fn panic_handler(_info: &PanicInfo) -> ! { + test_failure(); + loop { + continue; + } +} From d9af8d0eedabb7253afd469cfaa5c2a5bbc1d8c6 Mon Sep 17 00:00:00 2001 From: Lucas Bollen Date: Fri, 18 Oct 2024 14:23:20 +0200 Subject: [PATCH 6/6] WIP --- firmware-binaries/clock-control/src/main.rs | 2 -- firmware-binaries/examples/hello/src/main.rs | 8 ++++++++ firmware-binaries/examples/smoltcp_client/Cargo.toml | 2 +- .../test-cases/axi_stream_self_test/Cargo.toml | 2 +- .../test-cases/axi_stream_self_test/src/main.rs | 2 -- firmware-binaries/test-cases/capture_ugn_test/Cargo.toml | 2 +- firmware-binaries/test-cases/dna_port_e2_test/Cargo.toml | 2 +- firmware-binaries/test-cases/time_self_test/Cargo.toml | 2 +- firmware-support/bittide-sys/Cargo.toml | 1 + firmware-support/bittide-sys/src/uart/log.rs | 6 +++--- host-tools/callisto-lib/Cargo.toml | 2 +- 11 files changed, 18 insertions(+), 13 deletions(-) diff --git a/firmware-binaries/clock-control/src/main.rs b/firmware-binaries/clock-control/src/main.rs index 15ff9127b..7619f835b 100644 --- a/firmware-binaries/clock-control/src/main.rs +++ b/firmware-binaries/clock-control/src/main.rs @@ -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}, diff --git a/firmware-binaries/examples/hello/src/main.rs b/firmware-binaries/examples/hello/src/main.rs index 543c169d6..6ea1b6a34 100644 --- a/firmware-binaries/examples/hello/src/main.rs +++ b/firmware-binaries/examples/hello/src/main.rs @@ -45,3 +45,11 @@ fn main() -> ! { uart.send(c); } } + +#[panic_handler] +fn panic_handler(_info: &core::panic::PanicInfo) -> ! { + test_failure(); + loop { + continue; + } +} diff --git a/firmware-binaries/examples/smoltcp_client/Cargo.toml b/firmware-binaries/examples/smoltcp_client/Cargo.toml index a708c1dfb..536ad56bb 100644 --- a/firmware-binaries/examples/smoltcp_client/Cargo.toml +++ b/firmware-binaries/examples/smoltcp_client/Cargo.toml @@ -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} diff --git a/firmware-binaries/test-cases/axi_stream_self_test/Cargo.toml b/firmware-binaries/test-cases/axi_stream_self_test/Cargo.toml index e01415b97..091e8c5fd 100644 --- a/firmware-binaries/test-cases/axi_stream_self_test/Cargo.toml +++ b/firmware-binaries/test-cases/axi_stream_self_test/Cargo.toml @@ -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" diff --git a/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs b/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs index 6174e24d5..d04c28db6 100644 --- a/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs +++ b/firmware-binaries/test-cases/axi_stream_self_test/src/main.rs @@ -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; diff --git a/firmware-binaries/test-cases/capture_ugn_test/Cargo.toml b/firmware-binaries/test-cases/capture_ugn_test/Cargo.toml index 8a245bca3..3bb0734dd 100644 --- a/firmware-binaries/test-cases/capture_ugn_test/Cargo.toml +++ b/firmware-binaries/test-cases/capture_ugn_test/Cargo.toml @@ -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" diff --git a/firmware-binaries/test-cases/dna_port_e2_test/Cargo.toml b/firmware-binaries/test-cases/dna_port_e2_test/Cargo.toml index 9861b9733..050bed1e4 100644 --- a/firmware-binaries/test-cases/dna_port_e2_test/Cargo.toml +++ b/firmware-binaries/test-cases/dna_port_e2_test/Cargo.toml @@ -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" diff --git a/firmware-binaries/test-cases/time_self_test/Cargo.toml b/firmware-binaries/test-cases/time_self_test/Cargo.toml index b31de80a6..06690d620 100644 --- a/firmware-binaries/test-cases/time_self_test/Cargo.toml +++ b/firmware-binaries/test-cases/time_self_test/Cargo.toml @@ -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" diff --git a/firmware-support/bittide-sys/Cargo.toml b/firmware-support/bittide-sys/Cargo.toml index 34793647d..a29ac2522 100644 --- a/firmware-support/bittide-sys/Cargo.toml +++ b/firmware-support/bittide-sys/Cargo.toml @@ -14,6 +14,7 @@ resolver = "2" [features] default = [] +panic_handler_log = [] [dependencies] fdt = "0.1.0" diff --git a/firmware-support/bittide-sys/src/uart/log.rs b/firmware-support/bittide-sys/src/uart/log.rs index 1f06f427a..9a464f2ef 100644 --- a/firmware-support/bittide-sys/src/uart/log.rs +++ b/firmware-support/bittide-sys/src/uart/log.rs @@ -7,11 +7,11 @@ use crate::{time, uart}; // compatible with (dependencies of) the log crate. 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. @@ -92,8 +92,8 @@ impl log::Log for UartLogger { unsafe impl core::marker::Send for UartLogger {} unsafe impl core::marker::Sync for UartLogger {} -#[panic_handler] -fn panic_handler(info: &PanicInfo) -> ! { +#[cfg_attr(feature = "panic_handler_log", panic_handler)] +pub fn panic_handler(info: &PanicInfo) -> ! { unsafe { match LOGGER.uart { Some(ref mut uart) => { diff --git a/host-tools/callisto-lib/Cargo.toml b/host-tools/callisto-lib/Cargo.toml index 6df484b8b..0054fa517 100644 --- a/host-tools/callisto-lib/Cargo.toml +++ b/host-tools/callisto-lib/Cargo.toml @@ -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"]