1
Fork 0

converted codebase to pico 2

This commit is contained in:
Andy Killorin 2025-02-02 17:48:26 -05:00
parent ecd0800891
commit 1a0301ddd9
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
7 changed files with 98 additions and 21 deletions

View file

@ -1,5 +1,6 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs --deploy --serial --verbose"
#runner = "elf2uf2-rs --deploy --serial --verbose"
runner = "picotool load -u -v -x -t elf"
[build]
target = "thumbv6m-none-eabi"
target = "thumbv8m.main-none-eabihf"

View file

@ -404,6 +404,7 @@ dependencies = [
"pio",
"pio-proc",
"rand_core",
"rp-binary-info",
"rp-pac",
"rp2040-boot2",
"sha2-const-stable",
@ -1212,6 +1213,12 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "rp-binary-info"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "534e2a451671116f5b9391cb15fae43b9abdc56817bcaca9a95ed32c3e4c6b38"
[[package]]
name = "rp-pac"
version = "7.0.0"

View file

@ -13,11 +13,11 @@ embedded-storage = "0.3.1"
cortex-m-rt = "0.7.3"
embassy-executor = { version = "0.7", features = ["task-arena-size-1024", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
embassy-executor = { version = "0.7", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
embassy-sync = { version = "0.6" }
embassy-time = { version = "0.4" }
cortex-m = { version = "0.7.6" }
embassy-rp = { version = "0.3", features = ["unstable-pac", "time-driver", "critical-section-impl", "rp2040"] }
embassy-rp = { version = "0.3", features = ["unstable-pac", "time-driver", "critical-section-impl", "rp235xa", "binary-info"] }
embassy-usb-logger = "0.4.0"
log = "0.4"

View file

@ -31,5 +31,4 @@ fn main() {
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
}

View file

@ -1,7 +1,75 @@
MEMORY
{
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
RAM : ORIGIN = 0x20000000, LENGTH = 264K
MEMORY {
/*
* The RP2350 has either external or internal flash.
*
* 2 MiB is a safe default here, although a Pico 2 has 4 MiB.
*/
FLASH : ORIGIN = 0x10000000, LENGTH = 2048K
/*
* RAM consists of 8 banks, SRAM0-SRAM7, with a striped mapping.
* This is usually good for performance, as it distributes load on
* those banks evenly.
*/
RAM : ORIGIN = 0x20000000, LENGTH = 512K
/*
* RAM banks 8 and 9 use a direct mapping. They can be used to have
* memory areas dedicated for some specific job, improving predictability
* of access times.
* Example: Separate stacks for core0 and core1.
*/
SRAM4 : ORIGIN = 0x20080000, LENGTH = 4K
SRAM5 : ORIGIN = 0x20081000, LENGTH = 4K
}
SECTIONS {
/* ### Boot ROM info
*
* Goes after .vector_table, to keep it in the first 4K of flash
* where the Boot ROM (and picotool) can find it
*/
.start_block : ALIGN(4)
{
__start_block_addr = .;
KEEP(*(.start_block));
KEEP(*(.boot_info));
} > FLASH
} INSERT AFTER .vector_table;
/* move .text to start /after/ the boot info */
_stext = ADDR(.start_block) + SIZEOF(.start_block);
SECTIONS {
/* ### Picotool 'Binary Info' Entries
*
* Picotool looks through this block (as we have pointers to it in our
* header) to find interesting information.
*/
.bi_entries : ALIGN(4)
{
/* We put this in the header */
__bi_entries_start = .;
/* Here are the entries */
KEEP(*(.bi_entries));
/* Keep this block a nice round size */
. = ALIGN(4);
/* We put this in the header */
__bi_entries_end = .;
} > FLASH
} INSERT AFTER .text;
SECTIONS {
/* ### Boot ROM extra info
*
* Goes after everything in our program, so it can contain a signature.
*/
.end_block : ALIGN(4)
{
__end_block_addr = .;
KEEP(*(.end_block));
} > FLASH
} INSERT AFTER .uninit;
PROVIDE(start_to_end = __end_block_addr - __start_block_addr);
PROVIDE(end_to_start = __start_block_addr - __end_block_addr);

View file

@ -1,10 +0,0 @@
# Before upgrading check that everything is available on all tier1 targets here:
# https://rust-lang.github.io/rustup-components-history
[toolchain]
channel = "stable"
components = [ "rustfmt" ]
targets = [
"thumbv6m-none-eabi",
"thumbv7em-none-eabihf",
"riscv32imac-unknown-none-elf",
]

View file

@ -5,7 +5,7 @@ use core::{panic::PanicInfo, sync::atomic::Ordering};
use common::{Command, Response, SensorData, BAUDRATE};
use embassy_executor::Spawner;
use embassy_rp::{bind_interrupts, peripherals::{UART0, UART1, USB}, pwm::{self, Pwm}, uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, BufferedUartTx, Config}, usb::Driver};
use embassy_rp::{bind_interrupts, block::ImageDef, gpio::{Level, Output}, peripherals::{UART0, UART1, USB}, pwm::{self, Pwm}, uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, BufferedUartTx, Config}, usb::Driver};
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
use embassy_time::{with_deadline, with_timeout, Duration, Instant, Timer};
use embedded_io::Write;
@ -25,6 +25,10 @@ bind_interrupts!(struct Irqs {
pub static COMMANDS: Channel<CriticalSectionRawMutex, Command, 5> = Channel::new();
pub static SENSOR_DATA: Channel<CriticalSectionRawMutex, SensorData, 5> = Channel::new();
#[link_section = ".start_block"]
#[used]
pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe();
#[embassy_executor::task]
async fn logger_task(driver: Driver<'static, USB>) {
embassy_usb_logger::run!(1024, log::LevelFilter::Trace, driver);
@ -40,6 +44,10 @@ fn panic( info: &PanicInfo) -> ! {
async fn main(spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut led = Output::new(p.PIN_25, Level::Low);
led.set_high();
let driver = Driver::new(p.USB, Irqs);
spawner.spawn(logger_task(driver)).unwrap();
@ -74,6 +82,10 @@ async fn main(spawner: Spawner) {
let mut enable_watchdog = Instant::now();
let enable_watchdog_time = Duration::from_millis(50);
Timer::after_secs(1).await;
info!("ready");
Timer::after_secs(1).await;
loop {
if !enabled.load(Ordering::Acquire) {