Skip to content

Commit 2524c0e

Browse files
set panic resources and add panic messages
1 parent ac5d597 commit 2524c0e

3 files changed

Lines changed: 73 additions & 30 deletions

File tree

boards/nucleo_u545re_q/src/main.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#![no_std]
77
#![no_main]
88

9-
use kernel::capabilities;
109
use kernel::component::Component;
1110
use kernel::debug::PanicResources;
1211
use kernel::deferred_call::DeferredCallClient;
1312
use kernel::platform::chip::Chip;
1413
use kernel::platform::{KernelResources, SyscallDriverLookup};
1514
use kernel::utilities::single_thread_value::SingleThreadValue;
15+
use kernel::{capabilities, debug};
1616
use kernel::{create_capability, static_init};
1717

1818
use stm32u545::gpio::PinId;
@@ -177,6 +177,12 @@ unsafe fn start() -> (
177177
<ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
178178
>();
179179

180+
// Bind global variables to this thread.
181+
let _ = PANIC_RESOURCES
182+
.bind_to_thread::<<ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider>(
183+
PanicResources::new(),
184+
);
185+
180186
// Create Individual Drivers
181187
let exti = static_init!(
182188
stm32u545::exti::Exti<'static>,
@@ -209,6 +215,10 @@ unsafe fn start() -> (
209215
// Kernel and Muxes
210216
let processes = components::process_array::ProcessArrayComponent::new()
211217
.finalize(components::process_array_component_static!(NUM_PROCS));
218+
PANIC_RESOURCES.get().map(|resources| {
219+
resources.processes.put(processes.as_slice());
220+
});
221+
212222
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes.as_slice()));
213223

214224
let uart_mux = components::console::UartMuxComponent::new(periphs.usart1, 115200)
@@ -234,12 +244,17 @@ unsafe fn start() -> (
234244
)
235245
.finalize(components::debug_writer_component_static!());
236246

247+
let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
248+
.finalize(components::process_printer_text_component_static!());
249+
PANIC_RESOURCES.get().map(|resources| {
250+
resources.printer.put(process_printer);
251+
});
252+
237253
let process_console = components::process_console::ProcessConsoleComponent::new(
238254
board_kernel,
239255
uart_mux,
240256
alarm_mux,
241-
components::process_printer::ProcessPrinterTextComponent::new()
242-
.finalize(components::process_printer_text_component_static!()),
257+
process_printer,
243258
None,
244259
)
245260
.finalize(components::process_console_component_static!(
@@ -327,13 +342,15 @@ unsafe fn start() -> (
327342
11 => periphs.gpio_a.pin(PinId::Pin07), // D11
328343
12 => periphs.gpio_a.pin(PinId::Pin06), // D12
329344
// 13 => D13/PA5 is used by the LD2 LED capsule
330-
// D14-D15 require GPIOB
345+
14 => periphs.gpio_b.pin(PinId::Pin07), // D14
346+
15 => periphs.gpio_b.pin(PinId::Pin06), // D15
347+
331348

332349
// Analog pins exposed as GPIO
333350
16 => periphs.gpio_a.pin(PinId::Pin00), // A0
334351
17 => periphs.gpio_a.pin(PinId::Pin01), // A1
335352
18 => periphs.gpio_a.pin(PinId::Pin04), // A2
336-
// 19 => A3 requires GPIOB
353+
19 => periphs.gpio_b.pin(PinId::Pin00), // A3
337354
20 => periphs.gpio_c.pin(PinId::Pin01), // A4
338355
21 => periphs.gpio_c.pin(PinId::Pin00), // A5
339356

@@ -369,6 +386,10 @@ unsafe fn start() -> (
369386
stm32u545::chip::Stm32u5xx::new(periphs)
370387
);
371388

389+
PANIC_RESOURCES.get().map(|resources| {
390+
resources.chip.put(chip);
391+
});
392+
372393
// Symbols for linker
373394
extern "C" {
374395
/// Beginning of the ROM region containing app images.
@@ -409,6 +430,9 @@ pub unsafe fn main() {
409430
let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
410431

411432
let (board_kernel, platform, chip) = start();
433+
434+
debug!("Initialization complete. Entering main loop");
435+
412436
// Hand over control to the Tock Kernel Loop
413437
board_kernel.kernel_loop::<NucleoU545RE, ChipHw, { NUM_PROCS as u8 }>(
414438
platform,

chips/stm32u5xx/src/chip.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::usart;
2121
use crate::{dac, exti};
2222

2323
use core::fmt::Write;
24+
use cortexm33::{CortexM33, CortexMVariant};
2425
use kernel::platform::chip::Chip;
2526
use kernel::platform::chip::InterruptService;
2627

@@ -316,6 +317,6 @@ impl<'a, I: InterruptService + 'a> Chip for Stm32u5xx<'a, I> {
316317
}
317318

318319
unsafe fn print_state(_this: Option<&Self>, write: &mut dyn Write) {
319-
let _ = write.write_str("Cortex-M33 state\n");
320+
CortexM33::print_cortexm_state(write);
320321
}
321322
}

kernel/src/debug.rs

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub unsafe fn panic_print<PW: PanicWriter, C: Chip, PP: ProcessPrinter>(
172172
flush(&mut writer);
173173
panic_banner(&mut writer, panic_info);
174174

175-
panic_resources.map(|pr| {
175+
if let Some(pr) = panic_resources {
176176
let chip = pr.chip.take();
177177
panic_cpu_state(chip, &mut writer);
178178

@@ -184,10 +184,14 @@ pub unsafe fn panic_print<PW: PanicWriter, C: Chip, PP: ProcessPrinter>(
184184
use crate::platform::mpu::MPU;
185185
c.mpu().disable_app_mpu()
186186
});
187-
pr.processes.take().map(|p| {
187+
if let Some(p) = pr.processes.take() {
188188
panic_process_info(p, pr.printer.take(), &mut writer);
189-
});
190-
});
189+
} else {
190+
let _ = writer.write_str("Processes List is not available\r\n");
191+
}
192+
} else {
193+
let _ = writer.write_str("Panic Resources are not available\r\n");
194+
}
191195
}
192196
}
193197

@@ -240,7 +244,7 @@ pub unsafe fn panic_print_old<W: Write + IoWrite, C: Chip, PP: ProcessPrinter>(
240244
flush(writer);
241245
panic_banner(writer, panic_info);
242246

243-
panic_resources.map(|pr| {
247+
if let Some(pr) = panic_resources {
244248
let chip = pr.chip.take();
245249
panic_cpu_state(chip, writer);
246250

@@ -252,10 +256,14 @@ pub unsafe fn panic_print_old<W: Write + IoWrite, C: Chip, PP: ProcessPrinter>(
252256
use crate::platform::mpu::MPU;
253257
c.mpu().disable_app_mpu()
254258
});
255-
pr.processes.take().map(|p| {
259+
if let Some(p) = pr.processes.take() {
256260
panic_process_info(p, pr.printer.take(), writer);
257-
});
258-
});
261+
} else {
262+
let _ = writer.write_str("Processes List is not available\r\n");
263+
}
264+
} else {
265+
let _ = writer.write_str("Panic Resources are not available\r\n");
266+
}
259267
}
260268
}
261269

@@ -340,8 +348,12 @@ pub unsafe fn panic_banner<W: Write>(writer: &mut W, panic_info: &PanicInfo) {
340348
///
341349
/// **NOTE:** The supplied `writer` must be synchronous.
342350
pub unsafe fn panic_cpu_state<W: Write, C: Chip>(chip: Option<&'static C>, writer: &mut W) {
343-
unsafe {
344-
C::print_state(chip, writer);
351+
if chip.is_none() {
352+
let _ = writer.write_str("\r\nChip Information is not available\r\n");
353+
} else {
354+
unsafe {
355+
C::print_state(chip, writer);
356+
}
345357
}
346358
}
347359

@@ -353,21 +365,27 @@ pub unsafe fn panic_process_info<PP: ProcessPrinter, W: Write>(
353365
process_printer: Option<&'static PP>,
354366
writer: &mut W,
355367
) {
356-
process_printer.map(|printer| {
357-
// print data about each process
358-
let _ = writer.write_fmt(format_args!("\r\n---| App Status |---\r\n"));
359-
for slot in processes {
360-
slot.proc.get().map(|process| {
361-
// Print the memory map and basic process info.
362-
//
363-
// Because we are using a synchronous printer we do not need to
364-
// worry about looping on the print function.
365-
printer.print_overview(process, &mut BinaryToWriteWrapper::new(writer), None);
366-
// Print all of the process details.
367-
process.print_full_process(writer);
368-
});
368+
if processes.iter().filter(|p| p.get().is_some()).count() > 0 {
369+
if let Some(printer) = process_printer {
370+
// print data about each process
371+
let _ = writer.write_fmt(format_args!("\r\n---| App Status |---\r\n"));
372+
for slot in processes {
373+
slot.proc.get().map(|process| {
374+
// Print the memory map and basic process info.
375+
//
376+
// Because we are using a synchronous printer we do not need to
377+
// worry about looping on the print function.
378+
printer.print_overview(process, &mut BinaryToWriteWrapper::new(writer), None);
379+
// Print all of the process details.
380+
process.print_full_process(writer);
381+
});
382+
}
383+
} else {
384+
let _ = writer.write_str("\r\nProcess Printer is not available\r\n");
369385
}
370-
});
386+
} else {
387+
let _ = writer.write_str("\r\nNo loaded processes\r\n");
388+
}
371389
}
372390

373391
/// Blinks a recognizable pattern forever.

0 commit comments

Comments
 (0)