Skip to content

Commit

Permalink
feat: add proper serial number programming
Browse files Browse the repository at this point in the history
Signed-off-by: Marvin Drees <[email protected]>
  • Loading branch information
MDr164 committed Feb 6, 2025
1 parent 2b8b6c8 commit 1fa96bc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
31 changes: 31 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ embassy-time = "0.3.2"
embassy-usb = { version = "0.3.0", features = ["max-handler-count-6", "max-interface-count-6"] }
embassy-usb-logger = "0.2.0"
futures = { version = "0.3.30", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
heapless = { version = "0.8.0", features = ["portable-atomic-critical-section", "ufmt"] }
log = "0.4.22"
portable-atomic = { version = "1.6.0", features = ["critical-section"] }
static_cell = "2.1.0"
ufmt = "0.2.0"

[patch.crates-io]
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "7a26e117ccd5f8669548cc8c2424be4691c1c402" }
Expand Down
19 changes: 18 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use cortex_m::peripheral::SCB;
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_rp::bind_interrupts;
use embassy_rp::flash::{Async, Flash};
use embassy_rp::gpio::{Level, Output};
use embassy_rp::peripherals::{self, UART0, USB};
use embassy_rp::spi::{Config as SpiConfig, Spi};
Expand All @@ -19,7 +20,9 @@ use embassy_rp::usb::{Driver, InterruptHandler as USBInterruptHandler};
use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
use embassy_usb::{Config as UsbConfig, UsbDevice};
use embassy_usb_logger::with_class;
use heapless::String;
use static_cell::StaticCell;
use ufmt::uwrite;

bind_interrupts!(struct UartIrqs {
UART0_IRQ => UARTInterruptHandler<UART0>;
Expand Down Expand Up @@ -49,6 +52,8 @@ assign_resources! {
}
}

const FLASH_SIZE: usize = 2 * 1024 * 1024;

// According to Serial Flasher Protocol Specification - version 1
const S_ACK: u8 = 0x06;
const S_NAK: u8 = 0x15;
Expand Down Expand Up @@ -130,11 +135,23 @@ async fn main(spawner: Spawner) {
let r = split_resources!(p);
let driver = Driver::new(p.USB, UsbIrqs);

let mut flash = Flash::<_, Async, FLASH_SIZE>::new(p.FLASH, p.DMA_CH4);
let mut uid: [u8; 8] = [0; 8];
flash.blocking_unique_id(&mut uid).unwrap_or_default();

static mut UID_STR: String<16> = String::<16>::new();
unsafe {
for byte in uid.iter() {
uwrite!(UID_STR, "{:02X}", *byte).unwrap_or_default();
}
}
let uid_str = unsafe { UID_STR.as_str() };

let config = {
let mut config = UsbConfig::new(0x1ced, 0xc0fe);
config.manufacturer = Some("9elements");
config.product = Some("Picoprog");
config.serial_number = Some("OSFC2024");
config.serial_number = Some(uid_str);
config.max_power = 100;
config.max_packet_size_0 = 64;

Expand Down

0 comments on commit 1fa96bc

Please sign in to comment.