continue workshop

This commit is contained in:
Robin Mueller authored and Robin Mueller committed 2026-06-11 14:11:14 +02:00
1 parent 1f805e672b
commit c9d5328450
32 files changed
+1354 -5

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list`
runner = "probe-rs run --chip nRF52833_xxAA --allow-erase-all"
rustflags = [
"-C", "link-arg=-Tlink.x", # use the cortex-m-rt linker script
"-C", "linker=flip-link", # adds stack overflow protection
"-C", "link-arg=-Tdefmt.x", # defmt support
]
[build]
target = "thumbv7em-none-eabihf"
[env]
DEFMT_LOG = "info"
+1032
View File
File diff suppressed because it is too large. Load diff
+32
View File
@@ -0,0 +1,32 @@
[package]
edition = "2024"
name = "rust-app"
version = "0.1.0"
license = "MIT OR Apache-2.0"
publish = false
[dependencies]
embassy-executor = { version = "0.10.0", features = ["platform-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
embassy-time = { version = "0.5.1", features = ["defmt", "defmt-timestamp-uptime"] }
embassy-nrf = { version = "0.10.0", features = ["defmt", "nrf52833", "time-driver-rtc1", "unstable-pac", "time"] }
defmt = "1.0.1"
defmt-rtt = "1.0.0"
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.0"
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
embedded-hal = { version = "1.0" }
embedded-hal-async = { version = "1.0" }
embedded-hal-bus = { version = "0.3", features = ["async"] }
embedded-io = { version = "0.7.1", features = ["defmt"] }
embedded-io-async = { version = "0.7.0", features = ["defmt"] }
portable-atomic = "1"
[profile.release]
debug = 2
[package.metadata.embassy]
build = [
{ target = "thumbv7em-none-eabi", artifact-dir = "out/examples/nrf52840" }
]
Binary file not shown.
+31
View File
@@ -0,0 +1,31 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
}
+6
View File
@@ -0,0 +1,6 @@
MEMORY
{
/* NOTE 1 K = 1 KiBi = 1024 bytes */
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
RAM : ORIGIN = 0x20000000, LENGTH = 128K
}
+33
View File
@@ -0,0 +1,33 @@
#![no_std]
#![no_main]
use embassy_executor::Spawner;
use embassy_time::Timer;
use rust_app as _;
use embassy_nrf::gpio::Output;
#[embassy_executor::main]
async fn main(_spawner: Spawner) -> ! {
let periphs = embassy_nrf::init(embassy_nrf::config::Config::default());
defmt::println!("-- microbit v2 Blinky application --");
let mut row1 = Output::new(
periphs.P0_21,
embassy_nrf::gpio::Level::Low,
embassy_nrf::gpio::OutputDrive::Standard,
);
let mut col1 = Output::new(
periphs.P0_28,
embassy_nrf::gpio::Level::Low,
embassy_nrf::gpio::OutputDrive::Standard,
);
row1.set_high();
col1.set_low();
loop {
defmt::debug!("blinking LED");
row1.toggle();
Timer::after_millis(1000).await;
}
}
+11
View File
@@ -0,0 +1,11 @@
#![no_std]
#![no_main]
use rust_app as _;
use embassy_executor::Spawner;
#[embassy_executor::main]
async fn main(_spawner: Spawner) -> ! {
defmt::info!("Hello, world!");
loop {}
}
+47
View File
@@ -0,0 +1,47 @@
#![no_std]
#![no_main]
use embassy_executor::Spawner;
use embedded_io_async::Write;
use rust_app as _;
use embassy_nrf::{
peripherals,
uarte::{self, Baudrate},
};
embassy_nrf::bind_interrupts!(
struct Irqs {
UARTE0 => uarte::InterruptHandler<peripherals::UARTE0>;
}
);
#[embassy_executor::main]
async fn main(_spawner: Spawner) -> ! {
let periphs = embassy_nrf::init(embassy_nrf::config::Config::default());
defmt::println!("-- microbit v2 UART echo application --");
let mut uarte_config = uarte::Config::default();
uarte_config.baudrate = Baudrate::BAUD115200;
let uart = uarte::Uarte::new(
periphs.UARTE0,
periphs.P1_08,
periphs.P0_06,
Irqs,
uarte_config,
);
let (mut uart_tx, mut uart_rx) =
uart.split_with_idle(periphs.TIMER0, periphs.PPI_CH0, periphs.PPI_CH1);
let mut rx_buf: [u8; 64] = [0; 64];
loop {
match uart_rx.read_until_idle(&mut rx_buf).await {
Ok(read_bytes) => match uart_tx.write_all(&rx_buf[0..read_bytes]).await {
Ok(_) => {
defmt::trace!("read {} bytes", &read_bytes);
}
Err(e) => defmt::error!("UART transmission error: {}", e),
},
Err(e) => defmt::error!("UART reception error: {}", e),
}
}
}
+5
View File
@@ -0,0 +1,5 @@
#![no_std]
use defmt_rtt as _;
use embassy_nrf as _;
use panic_probe as _;