From acedd7365a52b115ff1263ba2a5ee9d154f70af7 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 fc680da77..924873784 100644 --- a/firmware-binaries/clock-control-reg-cpy/src/main.rs +++ b/firmware-binaries/clock-control-reg-cpy/src/main.rs @@ -27,10 +27,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 2aeb07898..84fab9297 100644 --- a/firmware-binaries/clock-control/src/main.rs +++ b/firmware-binaries/clock-control/src/main.rs @@ -40,10 +40,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 d333b3212..935f995ea 100644 --- a/firmware-binaries/examples/smoltcp_client/src/main.rs +++ b/firmware-binaries/examples/smoltcp_client/src/main.rs @@ -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 { 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 26b6b68d988117b1a1805d6efe0f103c79f6206f 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 241a0f42a86bf63306cf815143d90d80c64865fb 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 b5e86b310935f3ae356f684bca811cd0556bacd7 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 797ba86e0364536980e4c5bdf4c765b0df77d2f2 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 0f8ec05c062ce0107568cb1b33a48bd5a7c5a45e 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 84fab9297..bd04e3e41 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 20dfdbcbd..195974372 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 28c1d323c..03aca01ae 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"]