Skip to content

Commit

Permalink
Add a few items:
Browse files Browse the repository at this point in the history
* converges rtt deps to endure only rtt-target v0.4.0 is used
* builds std to get more debug info
* tweaks some profile items
  • Loading branch information
jamesmunns committed Dec 12, 2023
1 parent 3b3f774 commit cc96c01
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ rustflags = [
# LLVM linker:
"-C", "link-arg=-Map=build.map",
]

[unstable]
build-std = ["core", "alloc"]
19 changes: 4 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ debug = true
debug-assertions = true # controls both our own assertions plus whether RTT enabled
overflow-checks = false
lto = 'fat' # same as true? may do nothing if codegen-units is 1
# lto = false # same as true? may do nothing if codegen-units is 1
# lto = 'thin' # same as true? may do nothing if codegen-units is 1
panic = 'abort'
incremental = true
codegen-units = 8
incremental = false
# codegen-units = 8
codegen-units = 1

#-----------------------------------
[dependencies]
Expand All @@ -46,12 +49,16 @@ critical-section = { version = "1.1", default-features = false }
nrf52840-hal = { version = "0.16.0" }

embedded-alloc = "0.5.0"
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
rtt-target = { version = "0.4.0" }
# panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
# rtt-target = { version = "0.3.1", features = ["cortex-m"] }

panic-rtt-target = { git = "https://github.com/probe-rs/rtt-target", rev = "59b236ce50e44826031adbfc12742e4a0b8d5d6c", features = ["cortex-m"] }
rtt-target = { git = "https://github.com/probe-rs/rtt-target", rev = "59b236ce50e44826031adbfc12742e4a0b8d5d6c" }

[patch.crates-io]
# Note: latest known good version is whatever comes after rev = below.
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
embassy-nrf = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
rtt-target = { git = "https://github.com/probe-rs/rtt-target", rev = "59b236ce50e44826031adbfc12742e4a0b8d5d6c" }
10 changes: 10 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set -euxo pipefail

cargo build
cargo objcopy -- -O ihex none-fault.hex
sleep 1
probe-rs download --chip nrf52840 --format hex none-fault.hex
sleep 1
probe-rs reset --chip nrf52840
RTT=$(grep _SEGGER_RTT$ build.map | cut -d' ' -f1); echo $RTT >.rttlast
rtthost --chip nrf52840 --scan-region 0x$RTT
31 changes: 24 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,23 @@ fn oom(_layout: core::alloc::Layout) -> ! {
}
}

struct Lol {
a: UnsafeCell<MaybeUninit<[u8; SIZE]>>,
}

unsafe impl Sync for Lol {}

use core::{cell::UnsafeCell, sync::atomic::{compiler_fence, Ordering}};
use ::core::mem::MaybeUninit;
const SIZE: usize = 1 * 1024;
static HEAP: Lol = Lol { a: UnsafeCell::new(MaybeUninit::uninit()) };

#[embassy_executor::main]
async fn main(spawner: Spawner) {
// Initialize the allocator BEFORE you use it
{
use ::core::mem::MaybeUninit;
const SIZE: usize = 1 * 1024;
static mut HEAP: [MaybeUninit<u8>; SIZE] = [MaybeUninit::uninit(); SIZE];
unsafe { ALLOCATOR.init(HEAP.as_ptr() as usize, SIZE) }
assert_eq!(core::mem::size_of_val(&HEAP), SIZE);
unsafe { ALLOCATOR.init(HEAP.a.get() as usize, SIZE) }
}

// initialize embassy
Expand All @@ -74,11 +82,16 @@ async fn main(spawner: Spawner) {
let _ = spawner.spawn(task2());

// sleep_secs(1).await;
rprintln!("fail now?");

// rprintln!("fail now?");
compiler_fence(Ordering::SeqCst);
let x = alloc::boxed::Box::new([0u8; 256]);
// rprintln!("fail now3?");
let x = format!("{:?}", None::<usize>);
// let x = format!("{:?}", Some(23usize));
compiler_fence(Ordering::SeqCst);
// rprintln!("fail now2?");
// // let x = format!("{:?}", Some(23usize));
rprintln!("format!: {}", x);
// rprintln!("{:?}", None::<usize>);

// let x: Option<usize> = None;
// debug!("test: {:?}", x);
Expand Down Expand Up @@ -109,7 +122,9 @@ pub async fn sleep_secs(v: u32) {
#[cfg(not(feature = "term"))]
#[embassy_executor::task]
pub async fn task1() {
// return;
sleep_secs(500).await;
compiler_fence(Ordering::SeqCst);
// core::future::pending::<()>().await; // does not fail with this instead

// Removing these lines shifts stuff around and usually prevents failure:
Expand All @@ -119,7 +134,9 @@ pub async fn task1() {

#[embassy_executor::task]
async fn task2() {
// return;
sleep_secs(500).await;
compiler_fence(Ordering::SeqCst);
// core::future::pending::<()>().await; // does not fail with this instead

// Removing these lines shifts stuff around and usually prevents failure:
Expand Down

0 comments on commit cc96c01

Please sign in to comment.