Skip to content

Commit 33e2201

Browse files
authored
Merge pull request #491 from reitermarkus/rtt-target-panic-handler
Fix `rtt_target` blocking panic handler.
2 parents 667923e + e4d533f commit 33e2201

7 files changed

Lines changed: 31 additions & 26 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
- run: cargo fmt --all -- --check
2929
- run: cargo check
30-
30+
- run: cargo check --all-features
3131
- run: cargo clippy --all-features -- -D warnings
3232

3333
compile:

Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,26 @@ usbd-serial = "0.2.2"
5151
encdec = { version = "0.10", default-features = false }
5252
crc-any = { version = "2.5.0", default-features = false }
5353
panic-persist = { version = "0.3", features = ["custom-panic-handler", "utf8"] }
54-
miniconf = { version = "0.18", features = ["json-core", "derive", "postcard"]}
55-
miniconf_mqtt = "0.18"
56-
# Note: Keep `py/pyproject.toml` version in sync with the Minimq version used in FW.
54+
miniconf = { version = "0.18.0", features = ["json-core", "derive", "postcard"]}
55+
# NOTE: Keep this in sync with `py/pyproject.toml`.
56+
miniconf_mqtt = "0.18.0"
57+
# NOTE: Keep this in sync with the version used by `miniconf_mqtt`.
5758
minimq = "0.9.0"
5859
w5500 = "0.5"
5960
smlang= "0.8"
6061
minireq = "0.5"
61-
rtt-target = "0.6"
62+
rtt-target = { version = "0.6", optional = true }
6263
enum-iterator = { version = "2.1", default-features = false }
6364
enc424j600 = "0.4"
6465
embedded-hal = "1"
6566
smoltcp-nal = { version = "0.5", features=["shared-stack"] }
6667
serial-settings = "0.2"
6768
stm32f4xx-hal = {version = "0.22.1", features = ["stm32f407", "usb_fs"] }
68-
6969
postcard = "1"
7070

71+
[features]
72+
rtt = ["dep:rtt-target"]
73+
7174
[build-dependencies]
7275
built = { version = "0.7", features = ["git2"], default-features = false }
7376

memory.x

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MEMORY
55
FLASH : ORIGIN = 0x08000000, LENGTH = 768K
66
RAM : ORIGIN = 0x20000000, LENGTH = 126K
77
PANDUMP : ORIGIN = 0x2001FC00, LENGTH = 1K
8-
BOOTFLAG_RAM: ORIGIN = 0x2001F800, LENGTH = 1K
8+
BOOTFLAG_RAM : ORIGIN = 0x2001F800, LENGTH = 1K
99
}
1010

1111
_bootflag = ORIGIN(BOOTFLAG_RAM);

py/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ authors = [
1414
{ name = "Robert Jördens", email = "rj@quartiq.de" },
1515
]
1616
dependencies = [
17-
# Note: keep this in sync with Cargo.toml
18-
"miniconf-mqtt@git+https://github.com/quartiq/miniconf@v0.16.0#subdirectory=py/miniconf-mqtt",
17+
# NOTE: Keep this in sync with `Cargo.toml`.
18+
"miniconf-mqtt@git+https://github.com/quartiq/miniconf@v0.18.0#subdirectory=py/miniconf-mqtt",
1919
]

src/hardware/platform.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,26 @@ pub const BIAS_DAC_VCC: f32 = 3.2;
2020

2121
#[panic_handler]
2222
fn panic(info: &core::panic::PanicInfo) -> ! {
23-
use core::fmt::Write;
24-
use rtt_target::{ChannelMode, UpChannel};
25-
2623
cortex_m::interrupt::disable();
2724

2825
// Shutdown all of the RF channels.
2926
shutdown_channels();
3027

31-
if let Some(mut channel) = unsafe { UpChannel::conjure(0) } {
32-
channel.set_mode(ChannelMode::BlockIfFull);
33-
writeln!(channel, "{}", info).ok();
34-
}
35-
3628
// Write panic info to RAM.
3729
panic_persist::report_panic_info(info);
3830

39-
// Reset the device in `release` configuration.
40-
#[cfg(not(debug_assertions))]
41-
cortex_m::peripheral::SCB::sys_reset();
31+
#[cfg(feature = "rtt")]
32+
if let Some(mut channel) = unsafe { rtt_target::UpChannel::conjure(0) } {
33+
use core::fmt::Write;
34+
35+
channel.set_mode(rtt_target::ChannelMode::BlockIfFull);
36+
writeln!(channel, "{}", info).ok();
37+
}
4238

4339
#[cfg(debug_assertions)]
44-
loop {}
40+
cortex_m::asm::bkpt();
41+
42+
cortex_m::peripheral::SCB::sys_reset();
4543
}
4644

4745
/// Unconditionally disable and power-off all channels.

src/hardware/setup.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ pub fn setup(
104104
device: stm32f4xx_hal::pac::Peripherals,
105105
clock: SystemTimer,
106106
) -> BoosterDevices {
107-
// Configure RTT logging.
108-
device.DBGMCU.cr().modify(|_, w| w.dbg_sleep().set_bit());
109-
rtt_target::rtt_init_print!();
107+
#[cfg(feature = "rtt")]
108+
{
109+
// Configure RTT logging.
110+
device.DBGMCU.cr().modify(|_, w| w.dbg_sleep().set_bit());
111+
rtt_target::rtt_init_print!();
112+
}
110113

111114
// Install the logger
112115
log::set_logger(&crate::LOGGER)
@@ -140,6 +143,7 @@ pub fn setup(
140143

141144
// Start the watchdog during the initialization process.
142145
let mut watchdog = hal::watchdog::IndependentWatchdog::new(device.IWDG);
146+
watchdog.stop_on_debug(&device.DBGMCU, true);
143147
watchdog.start(30.secs());
144148

145149
let mut delay = AsmDelay::new(clocks.sysclk().to_Hz());

src/logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use heapless::String;
44
use super::SerialTerminal;
55
use core::fmt::Write;
66
use log::LevelFilter;
7-
use rtt_target::rprintln;
87

98
/// A logging buffer for storing serialized logs pending transmission.
109
///
@@ -51,7 +50,8 @@ impl log::Log for BufferedLog {
5150
return;
5251
}
5352

54-
rprintln!("{} - {}", record.level(), record.args());
53+
#[cfg(feature = "rtt")]
54+
rtt_target::rprintln!("{} - {}", record.level(), record.args());
5555
let source_file = record.file().unwrap_or("Unknown");
5656
let source_line = record.line().unwrap_or(u32::MAX);
5757

0 commit comments

Comments
 (0)