Compile starter project

This commit is contained in:
Invariantspace 2024-10-11 23:48:37 -07:00
parent a3030756cb
commit 661ebf6e7d
No known key found for this signature in database
GPG key ID: EBC4A20067373921
10 changed files with 1653 additions and 6 deletions

8
.cargo/config.toml Normal file
View file

@ -0,0 +1,8 @@
[build]
target = "thumbv6m-none-eabi"
[env]
DEFMT_LOG = "debug"
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"

1482
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,22 @@
[package]
name = "pico"
name = "picow"
version = "0.1.0"
edition = "2021"
[dependencies]
cortex-m-rt = "*"
cyw43 = "*"
cyw43-pio = "*"
defmt = "*"
defmt-rtt = "*"
embassy-executor = { version = "*", features = ["arch-cortex-m", "defmt", "executor-interrupt", "executor-thread", "integrated-timers"] }
embassy-rp = { version = "*", features = ["critical-section-impl", "defmt", "time-driver"] }
embassy-time = { version = "*", features = ["defmt", "defmt-timestamp-uptime"] }
panic-probe = { version = "*", features = ["print-defmt"] }
portable-atomic = { version = "*", features = ["critical-section"] }
static_cell = "*"
[profile.release]
debug = 2
lto = true
opt-level = "z"

36
build.rs Normal file
View file

@ -0,0 +1,36 @@
//! 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");
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}

View file

@ -16,13 +16,16 @@
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
fenixPkgs = fenix.packages.${system};
craneLib = crane.mkLib pkgs;
fenixToolchain = fenixPkgs.fromToolchainFile {
dir = ./.;
sha256 = "sha256-HAFn+jo7K/dwbCKRHNXQU+x9b+8LJ8xlQGL/tE0rNlE=";
};
craneLib = (crane.mkLib pkgs).overrideToolchain fenixToolchain;
in {
devShells.default = craneLib.devShell {
packages = with pkgs; [
fenixPkgs.rust-analyzer
elf2uf2-rs
fenixPkgs.rust-analyzer
];
RUST_SRC_PATH = "${fenixPkgs.complete.rust-src}/lib/rustlib/src/rust/library";
};

17
memory.x Normal file
View file

@ -0,0 +1,17 @@
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
/* Pick one of the two options for RAM layout */
/* OPTION A: Use all RAM banks as one big block */
/* Reasonable, unless you are doing something */
/* really particular with DMA or other concurrent */
/* access that would benefit from striping */
RAM : ORIGIN = 0x20000000, LENGTH = 264K
/* OPTION B: Keep the unstriped sections separate */
/* RAM: ORIGIN = 0x20000000, LENGTH = 256K */
/* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */
/* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */
}

4
rust-toolchain.toml Normal file
View file

@ -0,0 +1,4 @@
[toolchain]
channel = "nightly"
targets = ["thumbv6m-none-eabi"]
profile = "complete"

BIN
src/firmware/43439A0.bin Normal file

Binary file not shown.

Binary file not shown.

View file

@ -1,3 +1,84 @@
fn main() {
println!("Hello, world!");
#![no_std]
#![no_main]
use cyw43_pio::PioSpi;
use defmt::*;
use defmt_rtt as _;
use embassy_executor::Spawner;
use embassy_rp::{
bind_interrupts,
gpio::{Level, Output},
peripherals::{DMA_CH0, PIO0},
pio::{InterruptHandler, Pio},
};
use embassy_time::Timer;
use panic_probe as _;
use static_cell::StaticCell;
// bind interrupt request to handler
bind_interrupts!(struct Irqs {
PIO0_IRQ_0 => InterruptHandler<PIO0>;
});
// network task
#[embassy_executor::task]
async fn cyw43_task(
runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>,
) -> ! {
runner.run().await
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
// hardware abstraction layer
let hal = embassy_rp::init(Default::default());
// wireless firmware binary
let fw = include_bytes!("./firmware/43439A0.bin");
// wireless country locale matrix
let clm = include_bytes!("./firmware/43439A0_clm.bin");
// wireless power on signal
let pwr = Output::new(hal.PIN_23, Level::Low);
// wireless serial peripheral interface chip select
let cs = Output::new(hal.PIN_25, Level::High);
// programmed input/output
let mut pio = Pio::new(hal.PIO0, Irqs);
// programmed serial peripheral interface
let spi = PioSpi::new(
&mut pio.common,
pio.sm0,
pio.irq0,
cs,
hal.PIN_24,
hal.PIN_29,
hal.DMA_CH0,
);
// wireless driver state
static STATE: StaticCell<cyw43::State> = StaticCell::new();
let state = STATE.init(cyw43::State::new());
// spawn network task
let (_, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(cyw43_task(runner)));
// initialize wireless
control.init(clm).await;
control
.set_power_management(cyw43::PowerManagementMode::PowerSave)
.await;
// time to blink
let mut led = false;
loop {
info!("Blink!");
led = !led;
control.gpio_set(0, led).await;
Timer::after_secs(1).await;
}
}