|
17 | 17 | #![no_std] |
18 | 18 |
|
19 | 19 | extern crate alloc; |
20 | | -extern crate panic_semihosting; |
| 20 | +use defmt_semihosting as _; |
21 | 21 |
|
22 | 22 | use alloc::collections::LinkedList; |
23 | | -use core::mem::MaybeUninit; |
| 23 | +use core::{mem::MaybeUninit, panic::PanicInfo}; |
| 24 | +use cortex_m as _; |
24 | 25 | use cortex_m_rt::entry; |
25 | | -use cortex_m_semihosting::{debug, hprintln}; |
26 | 26 | use embedded_alloc::TlsfHeap as Heap; |
27 | 27 |
|
28 | 28 | #[global_allocator] |
29 | 29 | static HEAP: Heap = Heap::empty(); |
30 | 30 | const HEAP_SIZE: usize = 30 * 1024; |
31 | 31 |
|
| 32 | +pub type TestTable<'a> = &'a [(fn() -> (), &'static str)]; |
| 33 | + |
32 | 34 | fn test_global_heap() { |
33 | 35 | const ELEMS: usize = 250; |
34 | 36 |
|
@@ -85,20 +87,23 @@ fn main() -> ! { |
85 | 87 | embedded_alloc::init!(HEAP, HEAP_SIZE); |
86 | 88 | } |
87 | 89 |
|
88 | | - #[allow(clippy::type_complexity)] |
89 | | - let tests: &[(fn() -> (), &'static str)] = &[ |
| 90 | + let tests: TestTable = &[ |
90 | 91 | (test_global_heap, "test_global_heap"), |
91 | 92 | (test_allocator_api, "test_allocator_api"), |
92 | 93 | ]; |
93 | 94 |
|
94 | 95 | for (test_fn, test_name) in tests { |
95 | | - hprintln!("{}: start", test_name); |
| 96 | + defmt::info!("{}: start", test_name); |
96 | 97 | test_fn(); |
97 | | - hprintln!("{}: pass", test_name); |
| 98 | + defmt::info!("{}: pass", test_name); |
98 | 99 | } |
99 | 100 |
|
100 | 101 | // exit QEMU with a success status |
101 | | - debug::exit(debug::EXIT_SUCCESS); |
102 | | - #[allow(clippy::empty_loop)] |
103 | | - loop {} |
| 102 | + semihosting::process::exit(0); |
| 103 | +} |
| 104 | + |
| 105 | +#[panic_handler] |
| 106 | +fn panic(info: &PanicInfo) -> ! { |
| 107 | + defmt::error!("{}", info); |
| 108 | + semihosting::process::exit(-1); |
104 | 109 | } |
0 commit comments