Skip to content

Commit cc96c01

Browse files
committed
Add a few items:
* converges rtt deps to endure only rtt-target v0.4.0 is used * builds std to get more debug info * tweaks some profile items
1 parent 3b3f774 commit cc96c01

File tree

5 files changed

+52
-26
lines changed

5 files changed

+52
-26
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ rustflags = [
1212
# LLVM linker:
1313
"-C", "link-arg=-Map=build.map",
1414
]
15+
16+
[unstable]
17+
build-std = ["core", "alloc"]

Cargo.lock

Lines changed: 4 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ debug = true
2828
debug-assertions = true # controls both our own assertions plus whether RTT enabled
2929
overflow-checks = false
3030
lto = 'fat' # same as true? may do nothing if codegen-units is 1
31+
# lto = false # same as true? may do nothing if codegen-units is 1
32+
# lto = 'thin' # same as true? may do nothing if codegen-units is 1
3133
panic = 'abort'
32-
incremental = true
33-
codegen-units = 8
34+
incremental = false
35+
# codegen-units = 8
36+
codegen-units = 1
3437

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

4851
embedded-alloc = "0.5.0"
49-
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
50-
rtt-target = { version = "0.4.0" }
52+
# panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
53+
# rtt-target = { version = "0.3.1", features = ["cortex-m"] }
54+
55+
panic-rtt-target = { git = "https://github.com/probe-rs/rtt-target", rev = "59b236ce50e44826031adbfc12742e4a0b8d5d6c", features = ["cortex-m"] }
56+
rtt-target = { git = "https://github.com/probe-rs/rtt-target", rev = "59b236ce50e44826031adbfc12742e4a0b8d5d6c" }
5157

5258
[patch.crates-io]
5359
# Note: latest known good version is whatever comes after rev = below.
5460
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
5561
embassy-nrf = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
5662
embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
5763
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev="ce66276" }
64+
rtt-target = { git = "https://github.com/probe-rs/rtt-target", rev = "59b236ce50e44826031adbfc12742e4a0b8d5d6c" }

run.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set -euxo pipefail
2+
3+
cargo build
4+
cargo objcopy -- -O ihex none-fault.hex
5+
sleep 1
6+
probe-rs download --chip nrf52840 --format hex none-fault.hex
7+
sleep 1
8+
probe-rs reset --chip nrf52840
9+
RTT=$(grep _SEGGER_RTT$ build.map | cut -d' ' -f1); echo $RTT >.rttlast
10+
rtthost --chip nrf52840 --scan-region 0x$RTT

src/main.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,23 @@ fn oom(_layout: core::alloc::Layout) -> ! {
4848
}
4949
}
5050

51+
struct Lol {
52+
a: UnsafeCell<MaybeUninit<[u8; SIZE]>>,
53+
}
54+
55+
unsafe impl Sync for Lol {}
56+
57+
use core::{cell::UnsafeCell, sync::atomic::{compiler_fence, Ordering}};
58+
use ::core::mem::MaybeUninit;
59+
const SIZE: usize = 1 * 1024;
60+
static HEAP: Lol = Lol { a: UnsafeCell::new(MaybeUninit::uninit()) };
5161

5262
#[embassy_executor::main]
5363
async fn main(spawner: Spawner) {
5464
// Initialize the allocator BEFORE you use it
5565
{
56-
use ::core::mem::MaybeUninit;
57-
const SIZE: usize = 1 * 1024;
58-
static mut HEAP: [MaybeUninit<u8>; SIZE] = [MaybeUninit::uninit(); SIZE];
59-
unsafe { ALLOCATOR.init(HEAP.as_ptr() as usize, SIZE) }
66+
assert_eq!(core::mem::size_of_val(&HEAP), SIZE);
67+
unsafe { ALLOCATOR.init(HEAP.a.get() as usize, SIZE) }
6068
}
6169

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

7684
// sleep_secs(1).await;
77-
rprintln!("fail now?");
78-
85+
// rprintln!("fail now?");
86+
compiler_fence(Ordering::SeqCst);
87+
let x = alloc::boxed::Box::new([0u8; 256]);
88+
// rprintln!("fail now3?");
7989
let x = format!("{:?}", None::<usize>);
80-
// let x = format!("{:?}", Some(23usize));
90+
compiler_fence(Ordering::SeqCst);
91+
// rprintln!("fail now2?");
92+
// // let x = format!("{:?}", Some(23usize));
8193
rprintln!("format!: {}", x);
94+
// rprintln!("{:?}", None::<usize>);
8295

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

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

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

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

0 commit comments

Comments
 (0)