stm32 should now work
This commit is contained in:
13
stm32u5-blinky/src/bin/bitfield.rs
Normal file
13
stm32u5-blinky/src/bin/bitfield.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use stm32u5_blinky as _; // global logger + panicking-behavior + memory layout
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
// value of the FREQUENCY register (nRF52840 device; RADIO peripheral)
|
||||
let frequency: u32 = 276;
|
||||
defmt::println!("FREQUENCY: {0=0..7}, MAP: {0=8..9}", frequency);
|
||||
|
||||
stm32u5_blinky::exit()
|
||||
}
|
||||
29
stm32u5-blinky/src/bin/format.rs
Normal file
29
stm32u5-blinky/src/bin/format.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use stm32u5_blinky as _; // global logger + panicking-behavior + memory layout
|
||||
use defmt::Format; // <- derive attribute
|
||||
|
||||
#[derive(Format)]
|
||||
struct S1<T> {
|
||||
x: u8,
|
||||
y: T,
|
||||
}
|
||||
|
||||
#[derive(Format)]
|
||||
struct S2 {
|
||||
z: u8,
|
||||
}
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
let s = S1 {
|
||||
x: 42,
|
||||
y: S2 { z: 43 },
|
||||
};
|
||||
defmt::println!("s={:?}", s);
|
||||
let x = 42;
|
||||
defmt::println!("x={=u8}", x);
|
||||
|
||||
stm32u5_blinky::exit()
|
||||
}
|
||||
11
stm32u5-blinky/src/bin/hello.rs
Normal file
11
stm32u5-blinky/src/bin/hello.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use stm32u5_blinky as _; // global logger + panicking-behavior + memory layout
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
defmt::println!("Hello, world!");
|
||||
|
||||
stm32u5_blinky::exit()
|
||||
}
|
||||
17
stm32u5-blinky/src/bin/levels.rs
Normal file
17
stm32u5-blinky/src/bin/levels.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use stm32u5_blinky as _; // global logger + panicking-behavior + memory layout
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
// try setting the DEFMT_LOG environment variable
|
||||
// e.g. `export DEFMT_LOG=info` or `DEFMT_LOG=trace cargo rb levels`
|
||||
defmt::info!("info");
|
||||
defmt::trace!("trace");
|
||||
defmt::warn!("warn");
|
||||
defmt::debug!("debug");
|
||||
defmt::error!("error");
|
||||
|
||||
stm32u5_blinky::exit()
|
||||
}
|
||||
28
stm32u5-blinky/src/bin/overflow.rs
Normal file
28
stm32u5-blinky/src/bin/overflow.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use stm32u5_blinky as _; // global logger + panicking-behavior + memory layout
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
ack(10, 10);
|
||||
stm32u5_blinky::exit()
|
||||
}
|
||||
|
||||
fn ack(m: u32, n: u32) -> u32 {
|
||||
// waste stack space to trigger a stack overflow
|
||||
let mut buffer = [0u8; 16 * 1024];
|
||||
// estimate of the Stack Pointer register
|
||||
let sp = buffer.as_mut_ptr();
|
||||
defmt::println!("ack(m={=u32}, n={=u32}, SP={:x})", m, n, sp);
|
||||
|
||||
if m == 0 {
|
||||
n + 1
|
||||
} else {
|
||||
if n == 0 {
|
||||
ack(m - 1, 1)
|
||||
} else {
|
||||
ack(m - 1, ack(m, n - 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
11
stm32u5-blinky/src/bin/panic.rs
Normal file
11
stm32u5-blinky/src/bin/panic.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use stm32u5_blinky as _; // global logger + panicking-behavior + memory layout
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
defmt::println!("main");
|
||||
|
||||
defmt::panic!()
|
||||
}
|
||||
46
stm32u5-blinky/src/lib.rs
Normal file
46
stm32u5-blinky/src/lib.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
|
||||
// TODO(5) adjust HAL import
|
||||
// use some_hal as _; // memory layout
|
||||
|
||||
use panic_probe as _;
|
||||
|
||||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
||||
#[defmt::panic_handler]
|
||||
fn panic() -> ! {
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with status code 0.
|
||||
pub fn exit() -> ! {
|
||||
semihosting::process::exit(0);
|
||||
}
|
||||
|
||||
/// Hardfault handler.
|
||||
///
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with an error. This seems better than the default, which is to spin in a
|
||||
/// loop.
|
||||
#[cortex_m_rt::exception]
|
||||
unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! {
|
||||
semihosting::process::exit(1);
|
||||
}
|
||||
|
||||
// defmt-test 0.3.0 has the limitation that this `#[tests]` attribute can only be used
|
||||
// once within a crate. the module can be in any file but there can only be at most
|
||||
// one `#[tests]` module in this library crate
|
||||
#[cfg(test)]
|
||||
#[defmt_test::tests]
|
||||
mod unit_tests {
|
||||
use defmt::assert;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert!(true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user