diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 777cb4a..27b3d21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - x86_64-unknown-linux-gnu steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install build dependencies shell: bash diff --git a/Cargo.toml b/Cargo.toml index 51097d6..1db0ab3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,14 +16,14 @@ build = "build.rs" targets = [] [dependencies] -block-buffer = "0.9" -cipher = "0.3" +block-buffer = "0.10" +cipher = "0.4" cortex-m = "0.7" -digest = "0.9" +digest = "0.10" embedded-hal = { version = "0.2", features = ["unproven"] } embedded-time = "0.12" -generic-array = "0.14.2" -lpc55-pac = "0.4" +generic-array = "1.0.0" +lpc55-pac = "0.5" nb = "1" rand_core = "0.6" usb-device = "0.2" @@ -32,28 +32,26 @@ void = { version = "1", default-features = false } # optional dependencies # cortex-m-rtic = { version = "0.5", optional = true } -lpc55-rtic = { version = "0.5.7", optional = true } littlefs2 = { version = "0.5", optional = true } [dev-dependencies] -aes = "0.7" -cortex-m-rt = "0.6" +aes = "0.8" +cortex-m-rt = "0.7" rtic = { package = "cortex-m-rtic", version = "1" } -cortex-m-semihosting = "0.3" +cortex-m-semihosting = "0.5" heapless = "0.7" panic-halt = "0.2" panic-semihosting = { version = "0.5", features = ["jlink-quirks"] } rtt-target = { version = "0.3", features = ["cortex-m"] } -sha2 = { version = "0.9", default-features = false } +sha2 = { version = "0.10", default-features = false } ssd1306 = "0.3" -sha-1 = { version = "0.9", default-features = false } +sha-1 = { version = "0.10", default-features = false } usbd-serial = "0.1" [features] default = ["rt"] littlefs = ["littlefs2"] rt = ["lpc55-pac/rt"] -rtic-peripherals = ["lpc55-rtic"] # no longer a HAL feature, just for the usb examples highspeed-usb-example = [] diff --git a/Makefile b/Makefile index bbb0c56..c62637f 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,10 @@ rustup: rustup target add thumbv8m.main-none-eabihf rustup update +build-examples: + cargo build --examples + cargo build --examples --release + build-examples-verbosely: cargo build --verbose --examples cargo build --verbose --examples --release diff --git a/examples/adc.rs b/examples/adc.rs index 611e19d..d725189 100644 --- a/examples/adc.rs +++ b/examples/adc.rs @@ -39,7 +39,7 @@ fn autocal(adc: &hal::raw::ADC0) { #[entry] fn main() -> ! { - heprintln!("Hello ADC").unwrap(); + heprintln!("Hello ADC"); // Get pointer to all device peripherals. let mut hal = hal::new(); @@ -81,7 +81,7 @@ fn main() -> ! { // turn on! adc.ctrl.modify(|_, w| w.adcen().set_bit()); - heprintln!("Auto calibrating..").unwrap(); + heprintln!("Auto calibrating.."); autocal(&adc); // channel 13 (1V ref), single ended A, high res @@ -110,9 +110,9 @@ fn main() -> ! { .bits(1) }); - heprintln!("ADC CTRL. {:02X}", adc.ctrl.read().bits()).unwrap(); - heprintln!("ADC CFG. {:02X}", adc.cfg.read().bits()).unwrap(); - heprintln!("ADC stat: {:02X}", adc.stat.read().bits()).unwrap(); + heprintln!("ADC CTRL. {:02X}", adc.ctrl.read().bits()); + heprintln!("ADC CFG. {:02X}", adc.cfg.read().bits()); + heprintln!("ADC stat: {:02X}", adc.stat.read().bits()); // SW trigger the trigger event 0 adc.swtrig.write(|w| unsafe { w.bits(1) }); @@ -121,16 +121,16 @@ fn main() -> ! { let count0 = adc.fctrl[0].read().fcount().bits(); - heprintln!("FIFO0 conversions {}", count0).unwrap(); + heprintln!("FIFO0 conversions {}", count0); let result = adc.resfifo[0].read().bits(); let valid = result & 0x80000000; let sample = (result & 0xffff) as u16; if valid != 0 { - heprintln!("sample = {:02x}", sample).unwrap(); + heprintln!("sample = {:02x}", sample); } else { - heprintln!("No result from ADC!").unwrap(); + heprintln!("No result from ADC!"); } for i in 0..10 { @@ -139,11 +139,11 @@ fn main() -> ! { let result = adc.resfifo[0].read().bits(); assert!((result & 0x80000000) != 0); let sample = (result & 0xffff) as u16; - heprintln!("sample{} = {:02x}", i, sample).unwrap(); + heprintln!("sample{} = {:02x}", i, sample); } - heprintln!("looping").unwrap(); + heprintln!("looping"); loop { - heprintln!("looping").unwrap(); + heprintln!("looping"); } } diff --git a/examples/aes.rs b/examples/aes.rs index 027825e..5d4c00c 100644 --- a/examples/aes.rs +++ b/examples/aes.rs @@ -14,10 +14,9 @@ use hal::prelude::*; #[allow(unused_imports)] use lpc55_hal as hal; -use aes::cipher::NewBlockCipher; -use hal::traits::cipher::{BlockDecrypt, BlockEncrypt}; +use hal::traits::cipher::{BlockDecrypt, BlockEncrypt, KeyInit}; -use generic_array::GenericArray; +use cipher::generic_array::GenericArray; use cortex_m_semihosting::{dbg, hprintln}; @@ -31,7 +30,7 @@ fn main() -> ! { let key = GenericArray::from_slice(&raw_key); let raw_block = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let block = GenericArray::clone_from_slice(&raw_block); + let block = GenericArray::from(raw_block); // // via software @@ -42,14 +41,14 @@ fn main() -> ! { let (sw_cyc_enc, _) = hal::count_cycles(|| { cipher.encrypt_block(&mut sw_block); }); - hprintln!("encrypting with aes-soft took {} cycles", sw_cyc_enc).unwrap(); + hprintln!("encrypting with aes-soft took {} cycles", sw_cyc_enc); let sw_encrypted_block: [u8; 16] = sw_block[..].try_into().unwrap(); let (sw_cyc_dec, _) = hal::count_cycles(|| { cipher.decrypt_block(&mut sw_block); }); - hprintln!("decrypting with aes-soft took {} cycles", sw_cyc_dec).unwrap(); + hprintln!("decrypting with aes-soft took {} cycles", sw_cyc_dec); // check sw decrypt⚬encrypt = id assert_eq!(sw_block, block); @@ -65,8 +64,8 @@ fn main() -> ! { let (hw_cyc_enc, _) = hal::count_cycles(|| { cipher.encrypt_block(&mut hw_block); }); - hprintln!("encrypting with hashcrypt took {} cycles", hw_cyc_enc).unwrap(); - hprintln!("speedup: {}x", sw_cyc_enc / hw_cyc_enc).unwrap(); + hprintln!("encrypting with hashcrypt took {} cycles", hw_cyc_enc); + hprintln!("speedup: {}x", sw_cyc_enc / hw_cyc_enc); // dbg!(hw_block); let hw_encrypted_block: [u8; 16] = hw_block.as_slice().try_into().unwrap(); @@ -79,8 +78,8 @@ fn main() -> ! { let (hw_cyc_dec, _) = hal::count_cycles(|| { cipher.decrypt_block(&mut hw_block); }); - hprintln!("decrypting with hashcrypt took {} cycles", hw_cyc_dec).unwrap(); - hprintln!("speedup: {}x", sw_cyc_dec / hw_cyc_dec).unwrap(); + hprintln!("decrypting with hashcrypt took {} cycles", hw_cyc_dec); + hprintln!("speedup: {}x", sw_cyc_dec / hw_cyc_dec); // check hw decrypt⚬encrypt = id assert_eq!(hw_block, block); diff --git a/examples/ctimer.rs b/examples/ctimer.rs index abf8c93..10a61b6 100644 --- a/examples/ctimer.rs +++ b/examples/ctimer.rs @@ -20,7 +20,7 @@ use hal::drivers::Timer; #[entry] fn main() -> ! { - heprintln!("Hello ctimer").unwrap(); + heprintln!("Hello ctimer"); // Get pointer to all device peripherals. let mut hal = hal::new(); @@ -36,7 +36,7 @@ fn main() -> ! { .enabled(&mut hal.syscon, clocks.support_1mhz_fro_token().unwrap()); let mut cdriver = Timer::new(ctimer); - heprintln!("looping 1 Hz").unwrap(); + heprintln!("looping 1 Hz"); let mut c = 0; loop { cdriver.start(1_000_000.microseconds()); diff --git a/examples/external_interrupts.rs b/examples/external_interrupts.rs index bad09b5..4d0e47d 100644 --- a/examples/external_interrupts.rs +++ b/examples/external_interrupts.rs @@ -19,7 +19,7 @@ use lpc55_hal as hal; #[entry] fn main() -> ! { - heprintln!("External interrupts").unwrap(); + heprintln!("External interrupts"); let mut hal = hal::new(); @@ -58,12 +58,12 @@ fn main() -> ! { loop { if (pint.rise.read().bits() & 1) != 0 { pint.rise.write(|w| unsafe { w.bits(1) }); - heprintln!("Rising edge detected").unwrap(); + heprintln!("Rising edge detected"); } if (pint.fall.read().bits() & 1) != 0 { pint.fall.write(|w| unsafe { w.bits(1) }); - heprintln!("Falling edge detected").unwrap(); + heprintln!("Falling edge detected"); } } } diff --git a/examples/flash.rs b/examples/flash.rs index aa7a65a..c33cfd6 100644 --- a/examples/flash.rs +++ b/examples/flash.rs @@ -133,39 +133,39 @@ fn main() -> ! { // debug_assert!(flash.int_status.read().fail().bit_is_clear()); // let x: u8 = unsafe { core::ptr::read_volatile(0x0004_0000 as *const u8) } ; - // hprintln!("{:x}", x).ok(); + // hprintln!("{:x}", x); // let x: u32 = unsafe { core::ptr::read_volatile(0x0004_0004 as *const u32) } ; - // hprintln!("{:x}", x).ok(); + // hprintln!("{:x}", x); dbg!("before erasing"); - hprintln!("{:#034x}", flash.read_u128(0x4_0000)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0000)); const WHERE: usize = 0x0004_0000; // 256kB offset dbg!("after erasing"); flash.erase_page(WHERE >> 4).unwrap(); - hprintln!("{:#034x}", flash.read_u128(0x4_0000)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0000)); dbg!("after writing"); flash.write_u32(WHERE, 0x1234_5678).unwrap(); - hprintln!("{:#034x}", flash.read_u128(0x4_0000)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0000)); dbg!("after erasing again"); flash.erase_page(WHERE >> 4).unwrap(); - hprintln!("{:#034x}", flash.read_u128(0x4_0000)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0000)); dbg!("after writing with offset 4"); flash.write_u32(WHERE + 4, 0x1234_5678).unwrap(); - hprintln!("{:#034x}", flash.read_u128(0x4_0000)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0000)); - hprintln!("{:#034x}", flash.read_u128(0x4_0010)).ok(); - hprintln!("{:#034x}", flash.read_u128(0x4_0020)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0010)); + hprintln!("{:#034x}", flash.read_u128(0x4_0020)); let mut read_buf = [0u8; 16]; flash.read(WHERE, &mut read_buf); // dbg!(read_buf); flash.erase_page(0x4_0200).unwrap(); - hprintln!("supposedly erased").ok(); + hprintln!("supposedly erased"); // dbg!(flash.status()); flash.read(WHERE, &mut read_buf); // dbg!(read_buf); @@ -192,20 +192,20 @@ fn main() -> ! { // flash.read(0x4_0200, &mut read_buf); // dbg!(read_buf); // flash.write_u32(0x4_0200, 32).ok(); - // hprintln!("{:#x}", flash.read_u128(0x4_0200)).ok(); + // hprintln!("{:#x}", flash.read_u128(0x4_0200)); // flash.read(0x4_0200, &mut read_buf); // dbg!(read_buf); // // flash.write_u8(0x4_0206, 64).ok(); // flash.write_u32(0x4_0204, 128).ok(); - // hprintln!("{:#x}", flash.read_u128(0x4_0200)).ok(); + // hprintln!("{:#x}", flash.read_u128(0x4_0200)); // flash.read(0x4_0200, &mut read_buf); // dbg!(read_buf); // // flash.read(0x4_0210, &mut read_buf); // // dbg!(read_buf); - hprintln!("{:#034x}", flash.read_u128(0x4_0200)).ok(); - hprintln!("{:#034x}", flash.read_u128(0x4_0210)).ok(); - hprintln!("{:#034x}", flash.read_u128(0x4_0220)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0200)); + hprintln!("{:#034x}", flash.read_u128(0x4_0210)); + hprintln!("{:#034x}", flash.read_u128(0x4_0220)); flash.write_u128(0x4_0200, 0x1234567).unwrap(); // hal::wait_at_least(1_000_000); @@ -213,11 +213,11 @@ fn main() -> ! { // hal::wait_at_least(1_000_000); // flash.write_u128(0x4_0200, 0x1234567).unwrap(); - hprintln!("{:#034x}", flash.read_u128(0x4_0200)).ok(); - hprintln!("{:#034x}", flash.read_u128(0x4_0210)).ok(); - hprintln!("{:#034x}", flash.read_u128(0x4_0220)).ok(); + hprintln!("{:#034x}", flash.read_u128(0x4_0200)); + hprintln!("{:#034x}", flash.read_u128(0x4_0210)); + hprintln!("{:#034x}", flash.read_u128(0x4_0220)); - hprintln!("loop-continue").ok(); + hprintln!("loop-continue"); loop { continue; } diff --git a/examples/i2c.rs b/examples/i2c.rs index 5c84de2..23afad1 100644 --- a/examples/i2c.rs +++ b/examples/i2c.rs @@ -32,7 +32,7 @@ fn main() -> ! { .configure(&mut anactrl, &mut pmc, &mut syscon) .unwrap(); - // cortex_m_semihosting::hprintln!("clocks = {:?}", &clocks).ok(); + // cortex_m_semihosting::hprintln!("clocks = {:?}", &clocks); let token = clocks.support_flexcomm_token().unwrap(); @@ -60,7 +60,7 @@ fn main() -> ! { for c in (97..123).chain(65..91) { if let Err(_err) = display.write_str(unsafe { core::str::from_utf8_unchecked(&[c]) }) { // use cortex_m_semihosting::hprintln; - // hprintln!("error {}, resetting display", err).ok(); + // hprintln!("error {}, resetting display", err); // display.init().unwrap(); // display.clear().unwrap(); } diff --git a/examples/itm.rs b/examples/itm.rs index 8fc1ab2..4620b72 100644 --- a/examples/itm.rs +++ b/examples/itm.rs @@ -21,23 +21,22 @@ fn main() -> ! { let mut cp = unsafe { hal::raw::CorePeripherals::steal() }; let dp = unsafe { hal::raw::Peripherals::steal() }; - hprintln!("traceclksel = {:x?}", dp.SYSCON.traceclksel.read().bits()).ok(); - hprintln!("traceclkdiv = {:x?}", dp.SYSCON.traceclkdiv.read().bits()).ok(); + hprintln!("traceclksel = {:x?}", dp.SYSCON.traceclksel.read().bits()); + hprintln!("traceclkdiv = {:x?}", dp.SYSCON.traceclkdiv.read().bits()); hprintln!( "traceclkdiv.div = {:x?}", dp.SYSCON.traceclkdiv.read().div().bits() - ) - .ok(); + ); hprintln!( "traceclkdiv.halt = {:x?}", dp.SYSCON.traceclkdiv.read().halt().bits() - ) - .ok(); + ); // unsafe { dp.SYSCON.traceclksel.write(|w| w.sel().bits(0)); } // unsafe { dp.SYSCON.traceclkdiv.write(|w| w.div().bits(1)); } // iocon.set_pio_0_8_swo_func(); iocon.set_pio_0_10_swo_func(); + // hprintln!("pio_0_8 = {:?}", iocon.get_pio_0_8_func()); // hprintln!("pio_0_10 = {:?}", iocon.get_pio_0_10_func()); // hprintln!("traceclkdiv = {:?}", dp.SYSCON.traceclkdiv.read().bits()); diff --git a/examples/late.rs b/examples/late.rs index 7f5fc69..abd30d5 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -48,7 +48,7 @@ mod app { fn idle(ctx: idle::Context) -> ! { loop { if let Some(byte) = ctx.local.c.dequeue() { - hprintln!("received message: {}", byte).unwrap(); + hprintln!("received message: {}", byte); // cortex_m::asm::wfi(); } else { rtic::pend(Interrupt::ADC0); diff --git a/examples/measure_frequency.rs b/examples/measure_frequency.rs index 964cd7b..aade16a 100644 --- a/examples/measure_frequency.rs +++ b/examples/measure_frequency.rs @@ -59,6 +59,6 @@ fn main() -> ! { let us = timer.elapsed().0; timer.cancel().ok(); - heprintln!("{} MHz", 10_000_000 / us).ok(); + heprintln!("{} MHz", 10_000_000 / us); } } diff --git a/examples/pfr.rs b/examples/pfr.rs index bec08fc..5775cc8 100644 --- a/examples/pfr.rs +++ b/examples/pfr.rs @@ -15,11 +15,11 @@ use lpc55_hal as hal; macro_rules! dump_hex { ($array:expr, $length:expr ) => { - heprint!("{:?} = ", stringify!($array)).unwrap(); + heprint!("{:?} = ", stringify!($array)); for i in 0..$length { - heprint!("{:02X}", $array[i]).unwrap(); + heprint!("{:02X}", $array[i]); } - heprintln!("").unwrap(); + heprintln!(""); }; } @@ -36,13 +36,13 @@ fn boot_to_bootrom() -> ! { } fn dump_cfpa(cfpa: &Cfpa) { - heprintln!("header = {:08X}", cfpa.header).ok(); - heprintln!("version = {:08X}", cfpa.version).ok(); - heprintln!("secureVersion = {:08X}", cfpa.secure_fw_version).ok(); - heprintln!("notSecureVersion = {:08X}", cfpa.ns_fw_version).ok(); + heprintln!("header = {:08X}", cfpa.header); + heprintln!("version = {:08X}", cfpa.version); + heprintln!("secureVersion = {:08X}", cfpa.secure_fw_version); + heprintln!("notSecureVersion = {:08X}", cfpa.ns_fw_version); - heprintln!("imageKeyRevoke = {:08X}", cfpa.image_key_revoke).ok(); - heprintln!("rotkhRevoke = {:08X}", cfpa.rotkh_revoke).ok(); + heprintln!("imageKeyRevoke = {:08X}", cfpa.image_key_revoke); + heprintln!("rotkhRevoke = {:08X}", cfpa.rotkh_revoke); dump_hex!(cfpa.customer_data, 10); } @@ -60,13 +60,13 @@ fn main() -> ! { .unwrap(); dump_hex!(hal::uuid(), 16); - heprintln!("chip revision: {}", hal::chip_revision()).ok(); + heprintln!("chip revision: {}", hal::chip_revision()); let mut pfr = hal.pfr.enabled(&clocks).unwrap(); let mut cfpa = pfr.read_latest_cfpa().unwrap(); - heprintln!("CFPA:").ok(); + heprintln!("CFPA:"); dump_cfpa(&cfpa); - heprintln!("Increment the version and write back cfpa!").ok(); + heprintln!("Increment the version and write back cfpa!"); cfpa.version += 1; cfpa.secure_fw_version += 1; cfpa.ns_fw_version += 1; @@ -74,19 +74,19 @@ fn main() -> ! { cfpa.customer_data[0] = ((1 + (cfpa.customer_data[0] as u16)) & 0xff) as u8; pfr.write_cfpa(&cfpa).unwrap(); - heprintln!("Rerun this program and check that Version, firmware versions, and custom data byte all increment.").ok(); + heprintln!("Rerun this program and check that Version, firmware versions, and custom data byte all increment."); let cmpa = pfr.read_cmpa().unwrap(); - heprintln!("\r\nCMPA:").ok(); - heprintln!("boot_cfg = {:08X}", cmpa.boot_cfg).ok(); - heprintln!("usb.vid = {:08X}", cmpa.usb_vid).ok(); - heprintln!("usb.pid = {:08X}", cmpa.usb_pid).ok(); - heprintln!("secure_boot_cfg = {:08X}", cmpa.secure_boot_cfg).ok(); + heprintln!("\r\nCMPA:"); + heprintln!("boot_cfg = {:08X}", cmpa.boot_cfg); + heprintln!("usb.vid = {:08X}", cmpa.usb_vid); + heprintln!("usb.pid = {:08X}", cmpa.usb_pid); + heprintln!("secure_boot_cfg = {:08X}", cmpa.secure_boot_cfg); dump_hex!(cmpa.rotkh, cmpa.rotkh.len()); dump_hex!(cfpa.customer_data, 10); dump_hex!(cmpa.customer_data, cmpa.customer_data.len()); - heprintln!("\r\nKeyStore:").ok(); + heprintln!("\r\nKeyStore:"); let key_code = pfr.read_key_code(KeyType::User).unwrap(); dump_hex!(key_code, key_code.len()); @@ -95,7 +95,7 @@ fn main() -> ! { pfr.lock_all().unwrap(); - heprintln!("done. Must reboot to see CFPA changes take effect.").ok(); + heprintln!("done. Must reboot to see CFPA changes take effect."); loop { // done, insert NOP to avoid optimization weirdness diff --git a/examples/prince.rs b/examples/prince.rs index 5e15452..134607b 100644 --- a/examples/prince.rs +++ b/examples/prince.rs @@ -12,11 +12,11 @@ use lpc55_hal as hal; macro_rules! dump_hex { ($array:expr) => { - hprint!("{:?} = ", stringify!($array)).unwrap(); + hprint!("{:?} = ", stringify!($array)); for i in 0..$array.len() { - hprint!("{:02X}", $array[i]).unwrap(); + hprint!("{:02X}", $array[i]); } - hprintln!("").unwrap(); + hprintln!(""); }; } @@ -45,7 +45,7 @@ fn main() -> ! { prince.enable_all_region_2(); - hprintln!("writing AA's to flash data.").ok(); + hprintln!("writing AA's to flash data."); flash.erase_page(DATA_ADDR / 512).unwrap(); flash.erase_page((DATA_ADDR / 512) + 1).unwrap(); @@ -55,7 +55,7 @@ fn main() -> ! { flash.write(DATA_ADDR, &vector).unwrap(); }); - hprintln!("Read bytes PRINCE ON:").ok(); + hprintln!("Read bytes PRINCE ON:"); let mut buf = [0u8; 1024]; #[allow(clippy::needless_range_loop)] @@ -75,10 +75,10 @@ fn main() -> ! { buf[i] = unsafe { *ptr.add(i) }; } - hprintln!("Read bytes PRINCE OFF:").ok(); + hprintln!("Read bytes PRINCE OFF:"); dump_hex!(&buf[0..32]); - hprintln!("done.").ok(); + hprintln!("done."); loop { continue; } diff --git a/examples/puf.rs b/examples/puf.rs index c965724..a4a7df7 100644 --- a/examples/puf.rs +++ b/examples/puf.rs @@ -23,11 +23,11 @@ pub enum State { macro_rules! dump_hex { ($array:expr, $length:expr ) => { - heprint!("{:?} = ", stringify!($array)).unwrap(); + heprint!("{:?} = ", stringify!($array)); for i in 0..$length { - heprint!("{:02X}", $array[i]).unwrap(); + heprint!("{:02X}", $array[i]); } - heprintln!("").unwrap(); + heprintln!(""); }; } diff --git a/examples/pwm.rs b/examples/pwm.rs index 9465bed..37c0db1 100644 --- a/examples/pwm.rs +++ b/examples/pwm.rs @@ -32,7 +32,7 @@ fn sin(x: f32) -> f32 { fn print_type_of(_: &T) { use cortex_m_semihosting::hprintln; - hprintln!("{}", core::any::type_name::()).ok(); + hprintln!("{}", core::any::type_name::()); } #[entry] diff --git a/examples/rtc.rs b/examples/rtc.rs index f6e5660..7f9fc41 100644 --- a/examples/rtc.rs +++ b/examples/rtc.rs @@ -49,6 +49,6 @@ fn main() -> ! { loop { delay_cycles(10_000_000); - heprintln!("{:?}", rtc.uptime()).ok(); + heprintln!("{:?}", rtc.uptime()); } } diff --git a/examples/semihosting.rs b/examples/semihosting.rs index ecba457..98825b9 100644 --- a/examples/semihosting.rs +++ b/examples/semihosting.rs @@ -20,9 +20,9 @@ use lpc55_hal as hal; #[entry] fn main() -> ! { - hprint!("a").unwrap(); - hprint!("b").unwrap(); - hprintln!("c").unwrap(); + hprint!("a"); + hprint!("b"); + hprintln!("c"); const UUID: *mut u32 = 0x0009_FC70 as *mut u32; // dbg!(UUID); @@ -52,21 +52,21 @@ fn main() -> ! { let peripherals = hal::raw::Peripherals::take().unwrap(); // const SYSCON: *mut u32 = let device_id = peripherals.SYSCON.device_id0.read().bits(); - hprintln!("device_id0 = {:x?}", device_id).unwrap(); + hprintln!("device_id0 = {:x?}", device_id); let dieid = peripherals.SYSCON.dieid.read().bits(); - hprintln!("dieid = {:x?}", dieid).unwrap(); + hprintln!("dieid = {:x?}", dieid); dbg!(peripherals.SYSCON.dieid.read().rev_id().bits()); dbg!(peripherals.SYSCON.dieid.read().mco_num_in_die_id().bits()); let cpstat = peripherals.SYSCON.cpstat.read().bits(); - hprintln!("cpstat = {:x?}", cpstat).unwrap(); + hprintln!("cpstat = {:x?}", cpstat); #[allow(non_snake_case)] let DEVICE_ID0: *mut u32 = 0x4000_0ff8 as *mut u32; - hprintln!("{:x?}", unsafe { DEVICE_ID0.read_volatile() }).unwrap(); + hprintln!("{:x?}", unsafe { DEVICE_ID0.read_volatile() }); #[allow(non_snake_case)] let DIEID: *mut u32 = 0x4000_0ffc as *mut u32; - hprintln!("{:x?}", unsafe { DIEID.read_volatile() }).unwrap(); + hprintln!("{:x?}", unsafe { DIEID.read_volatile() }); dbg!(peripherals.SYSCON.device_id0.read().rom_rev_minor().bits()); diff --git a/examples/serial.rs b/examples/serial.rs index 8850209..d255520 100644 --- a/examples/serial.rs +++ b/examples/serial.rs @@ -30,7 +30,7 @@ fn main() -> ! { .configure(&mut anactrl, &mut pmc, &mut syscon) .unwrap(); - // cortex_m_semihosting::hprintln!("clocks = {:?}", &clocks).ok(); + // cortex_m_semihosting::hprintln!("clocks = {:?}", &clocks); let token = clocks.support_flexcomm_token().unwrap(); @@ -42,7 +42,7 @@ fn main() -> ! { let rx = pins.pio1_24.into_usart2_rx_pin(&mut iocon); let config = hal::drivers::serial::config::Config::default().speed(19_200.Hz()); - hprintln!("config = {:?}", config).ok(); + hprintln!("config = {:?}", config); let serial = Serial::new(usart, (tx, rx), config); @@ -55,16 +55,16 @@ fn main() -> ! { // The `block!` macro makes an operation block until it finishes block!(tx.write(sent)).ok(); - hprintln!("sent").ok(); + hprintln!("sent"); block!(tx.flush()).ok(); - hprintln!("flushed").ok(); + hprintln!("flushed"); let received = block!(rx.read()).unwrap(); - hprintln!("received").ok(); + hprintln!("received"); assert_eq!(received, sent); - hprintln!("equal").ok(); + hprintln!("equal"); loop { continue; diff --git a/src/drivers/aes.rs b/src/drivers/aes.rs index ed61bb1..4bcf7f8 100644 --- a/src/drivers/aes.rs +++ b/src/drivers/aes.rs @@ -25,6 +25,7 @@ mod sealed { impl KeySize for super::U32 {} } +use cipher::{BlockBackend, BlockSizeUser, ParBlocksSizeUser}; use sealed::KeySize; #[derive(Clone, Debug, PartialEq)] @@ -160,7 +161,8 @@ impl<'a, Size: KeySize> Aes<'a, Size> { assert!(self.status.read().needkey().is_not_need()); } - fn one_block(&self, block: &mut Block) { + fn one_block(&self, mut block: cipher::inout::InOut<'_, '_, Block>) { + let block = block.get_out(); // needs to be word-aligned let aligned_block: Aligned> = Aligned(*block); let addr: u32 = &aligned_block as *const _ as _; @@ -182,28 +184,63 @@ impl<'a, Size: KeySize> Aes<'a, Size> { // the `block-cipher` traits -impl BlockCipher for Aes<'_, Size> { +struct AesEncrypt<'a, 'b, Size: KeySize>(&'a Aes<'b, Size>); +struct AesDecrypt<'a, 'b, Size: KeySize>(&'a Aes<'b, Size>); + +impl BlockCipher for Aes<'_, Size> {} + +impl ParBlocksSizeUser for Aes<'_, Size> { + type ParBlocksSize = U1; +} + +impl BlockSizeUser for Aes<'_, Size> { type BlockSize = U16; - type ParBlocks = U1; } -impl BlockEncrypt for Aes<'_, Size> { - fn encrypt_block(&self, block: &mut Block) { +impl BlockSizeUser for AesEncrypt<'_, '_, Size> { + type BlockSize = U16; +} + +impl ParBlocksSizeUser for AesEncrypt<'_, '_, Size> { + type ParBlocksSize = U1; +} + +impl BlockSizeUser for AesDecrypt<'_, '_, Size> { + type BlockSize = U16; +} +impl ParBlocksSizeUser for AesDecrypt<'_, '_, Size> { + type ParBlocksSize = U1; +} + +impl BlockBackend for AesEncrypt<'_, '_, Size> { + fn proc_block(&mut self, block: cipher::inout::InOut<'_, '_, Block>) { // unfortunate implementation detail - if self.cryptcfg.read().aesdecrypt().is_decrypt() { - self.configure(Mode::Encrypt); + if self.0.cryptcfg.read().aesdecrypt().is_decrypt() { + self.0.configure(Mode::Encrypt); } - self.one_block(block); + self.0.one_block(block); } } -impl BlockDecrypt for Aes<'_, Size> { - fn decrypt_block(&self, block: &mut Block) { +impl BlockBackend for AesDecrypt<'_, '_, Size> { + fn proc_block(&mut self, block: cipher::inout::InOut<'_, '_, Block>) { // unfortunate implementation detail - if self.cryptcfg.read().aesdecrypt().is_encrypt() { - self.configure(Mode::Decrypt); + if self.0.cryptcfg.read().aesdecrypt().is_encrypt() { + self.0.configure(Mode::Decrypt); } - self.one_block(block); + self.0.one_block(block); + } +} + +impl BlockEncrypt for Aes<'_, Size> { + fn encrypt_with_backend(&self, f: impl cipher::BlockClosure) { + f.call(&mut AesEncrypt(self)) + } +} + +impl BlockDecrypt for Aes<'_, Size> { + fn decrypt_with_backend(&self, f: impl cipher::BlockClosure) { + f.call(&mut AesDecrypt(self)) } } diff --git a/src/drivers/flash.rs b/src/drivers/flash.rs index ad362bd..a79839d 100644 --- a/src/drivers/flash.rs +++ b/src/drivers/flash.rs @@ -234,7 +234,7 @@ impl Read for FlashGordon { // address is in bytes, whereas starta expects address in flash words // so starta = address / 16 = address >> 4 fn read_native(&self, address: usize, array: &mut GenericArray) { - // hprintln!("native read from {} of {:?} (first 16)", address, &array[..16]).ok(); + // hprintln!("native read from {} of {:?} (first 16)", address, &array[..16]); let flash = &self.flash.raw; assert!(flash.int_status.read().done().bit_is_set()); @@ -279,7 +279,7 @@ impl WriteErase for FlashGordon { fn erase_page(&mut self, page: usize) -> Result { // starta is still in flash words, of which a page has 32 let starta = page * 32; - // hprintln!("native erase page {}", page).ok(); + // hprintln!("native erase page {}", page); let flash = &self.flash.raw; assert!(flash.int_status.read().done().bit_is_set()); @@ -311,7 +311,7 @@ impl WriteErase for FlashGordon { array: &GenericArray, // cs: &CriticalSection, ) -> Result { - // hprintln!("native write to {} of {:?} (first 16)", address, &array[..16]).ok(); + // hprintln!("native write to {} of {:?} (first 16)", address, &array[..16]); let flash = &self.flash.raw; assert!(flash.int_status.read().done().bit_is_set()); self.clear_status(); diff --git a/src/drivers/serial.rs b/src/drivers/serial.rs index 58ad4ac..739724d 100644 --- a/src/drivers/serial.rs +++ b/src/drivers/serial.rs @@ -164,11 +164,7 @@ where continue; } let realized_speed = Self::CLOCK_SPEED / (osr * brg); - let diff = if speed > realized_speed { - speed - realized_speed - } else { - realized_speed - speed - }; + let diff = speed.abs_diff(realized_speed); if diff < best_diff { best_diff = diff; best_osr = osr; diff --git a/src/drivers/sha.rs b/src/drivers/sha.rs index a2dd540..17b95f4 100644 --- a/src/drivers/sha.rs +++ b/src/drivers/sha.rs @@ -1,7 +1,8 @@ use core::marker::PhantomData; use crate::traits::aligned::{Aligned, A4}; -use block_buffer::BlockBuffer; +use block_buffer::{BlockBuffer, Eager}; +use digest::{FixedOutput, Output, OutputSizeUser}; use crate::{ peripherals::hashcrypt::Hashcrypt, @@ -10,7 +11,7 @@ use crate::{ typenum::{U20, U32, U64}, GenericArray, }, - digest::{BlockInput, FixedOutputDirty, Update /*, Reset*/}, + digest::{Update /*, Reset*/}, }, typestates::init_state::Enabled, }; @@ -33,7 +34,7 @@ mod sealed { use sealed::OutputSize; pub struct Sha<'a, Size: OutputSize> { - buffer: Aligned>, + buffer: Aligned>, inner: &'a mut Hashcrypt, len: u64, size: PhantomData, @@ -88,14 +89,12 @@ impl<'a, Size: OutputSize> From<&'a mut Hashcrypt> for Sha<'a, Size> { // the `digest` traits -impl BlockInput for Sha<'_, Size> { - type BlockSize = BlockSize; -} - -impl FixedOutputDirty for Sha<'_, Size> { +impl OutputSizeUser for Sha<'_, Size> { type OutputSize = Size; +} - fn finalize_into_dirty(&mut self, out: &mut GenericArray) { +impl FixedOutput for Sha<'_, Size> { + fn finalize_into(mut self, out: &mut Output) { self.finish(); // cf `hashcrypt_get_data` ~line 315 of `fsl_hashcrypt.c` for i in 0..Size::to_usize() / 4 { @@ -106,7 +105,7 @@ impl FixedOutputDirty for Sha<'_, Size> { } impl Update for Sha<'_, Size> { - fn update(&mut self, data: impl AsRef<[u8]>) { + fn update(&mut self, data: &[u8]) { self.update(data.as_ref()); } } @@ -120,8 +119,11 @@ impl Sha<'_, Size> { // need to convince compiler we're using buffer and peripheral // independently, and not doing a double &mut let peripheral = &mut self.inner; - self.buffer - .input_block(data, |data| Self::process_block(peripheral, data)); + self.buffer.digest_blocks(data, |data| { + for b in data { + Self::process_block(peripheral, b) + } + }); } // relevant code is ~line 800 in fsl_hashcrypt.c diff --git a/src/drivers/usbd.rs b/src/drivers/usbd.rs index 58a86dd..e1b5962 100644 --- a/src/drivers/usbd.rs +++ b/src/drivers/usbd.rs @@ -174,7 +174,7 @@ where } fn enable(&mut self) { - // cortex_m_semihosting::hprintln!("Enabling UsbBus").ok(); + // cortex_m_semihosting::hprintln!("Enabling UsbBus"); interrupt::free(|cs| { let usb = self.usb_regs.borrow(cs); let eps = self.ep_regs.borrow(cs); @@ -229,7 +229,7 @@ where } fn reset(&self) { - // cortex_m_semihosting::hprintln!("Resetting UsbBus").ok(); + // cortex_m_semihosting::hprintln!("Resetting UsbBus"); interrupt::free(|cs| { // set device address to 0 let usb = self.usb_regs.borrow(cs); diff --git a/src/drivers/usbd/endpoint_registers.rs b/src/drivers/usbd/endpoint_registers.rs index 6099eb1..347a922 100644 --- a/src/drivers/usbd/endpoint_registers.rs +++ b/src/drivers/usbd/endpoint_registers.rs @@ -685,7 +685,7 @@ pub mod epr { } #[doc = "Bits 0:15 - Endpoint buffer address offset for full speed, or bits 0:10 for high speed"] #[inline] - pub fn addroff>(&mut self) -> _ADDROFFW { + pub fn addroff>(&mut self) -> _ADDROFFW<'_> { _ADDROFFW { w: self, field: AddrOffField::from(USB::SPEED), @@ -693,7 +693,7 @@ pub mod epr { } #[doc = "Bits 16:25 - Endpoint buffer NBytes for full speed, or bits 25:11 for high speed"] #[inline] - pub fn nbytes>(&mut self) -> _NBYTESW { + pub fn nbytes>(&mut self) -> _NBYTESW<'_> { _NBYTESW { w: self, field: NbytesField::from(USB::SPEED), @@ -701,7 +701,7 @@ pub mod epr { } #[doc = "Bit 26 - Endpoint type"] #[inline] - pub fn t(&mut self) -> _TW { + pub fn t(&mut self) -> _TW<'_> { _TW { w: self } } // #[doc = "Bit 27 - Rate Feedback mode / Toggle Value"] @@ -716,17 +716,17 @@ pub mod epr { // } #[doc = "Bit 29 - Stall"] #[inline] - pub fn s(&mut self) -> _SW { + pub fn s(&mut self) -> _SW<'_> { _SW { w: self } } #[doc = "Bit 30 - Disabled"] #[inline] - pub fn d(&mut self) -> _DW { + pub fn d(&mut self) -> _DW<'_> { _DW { w: self } } #[doc = "Bit 31 - Active"] #[inline] - pub fn a(&mut self) -> _AW { + pub fn a(&mut self) -> _AW<'_> { _AW { w: self } } } diff --git a/src/lib.rs b/src/lib.rs index b6fa449..f16abc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,16 +75,6 @@ pub fn take() -> Option { ))) } -#[cfg(not(feature = "rtic-peripherals"))] -pub fn from(raw: (raw::Peripherals, raw::CorePeripherals)) -> Peripherals { - Peripherals::from(raw) -} - -#[cfg(feature = "rtic-peripherals")] -pub fn from(raw: (raw::Peripherals, rtic::Peripherals)) -> Peripherals { - Peripherals::from(raw) -} - /// This is the entry point to the HAL API. /// /// Before you can do anything else, you need to get an instance of this struct, @@ -196,126 +186,10 @@ pub struct Peripherals { /// Watchdog pub wwdt: raw::WWDT, - #[cfg(not(feature = "rtic-peripherals"))] /// SysTick: System Timer - core peripheral - #[cfg(not(feature = "rtic-peripherals"))] pub SYST: raw::SYST, } -#[cfg(feature = "rtic-peripherals")] -impl From<(raw::Peripherals, rtic::Peripherals)> for Peripherals { - fn from(raw: (raw::Peripherals, rtic::Peripherals)) -> Self { - let cp = raw.1; - let p = raw.0; - Peripherals { - // HAL peripherals - adc: Adc::from(p.ADC0), - anactrl: Anactrl::from(p.ANACTRL), - casper: Casper::from(p.CASPER), - ctimer: ( - peripherals::ctimer::Ctimer0::from(p.CTIMER0), - peripherals::ctimer::Ctimer1::from(p.CTIMER1), - peripherals::ctimer::Ctimer2::from(p.CTIMER2), - peripherals::ctimer::Ctimer3::from(p.CTIMER3), - peripherals::ctimer::Ctimer4::from(p.CTIMER4), - ), - dma: Dma::from(p.DMA0), - flash: Flash::from(p.FLASH), - flexcomm: ( - peripherals::flexcomm::Flexcomm0::from(( - p.FLEXCOMM0, - p.I2C0, - p.I2S0, - p.SPI0, - p.USART0, - )), - peripherals::flexcomm::Flexcomm1::from(( - p.FLEXCOMM1, - p.I2C1, - p.I2S1, - p.SPI1, - p.USART1, - )), - peripherals::flexcomm::Flexcomm2::from(( - p.FLEXCOMM2, - p.I2C2, - p.I2S2, - p.SPI2, - p.USART2, - )), - peripherals::flexcomm::Flexcomm3::from(( - p.FLEXCOMM3, - p.I2C3, - p.I2S3, - p.SPI3, - p.USART3, - )), - peripherals::flexcomm::Flexcomm4::from(( - p.FLEXCOMM4, - p.I2C4, - p.I2S4, - p.SPI4, - p.USART4, - )), - peripherals::flexcomm::Flexcomm5::from(( - p.FLEXCOMM5, - p.I2C5, - p.I2S5, - p.SPI5, - p.USART5, - )), - peripherals::flexcomm::Flexcomm6::from(( - p.FLEXCOMM6, - p.I2C6, - p.I2S6, - p.SPI6, - p.USART6, - )), - peripherals::flexcomm::Flexcomm7::from(( - p.FLEXCOMM7, - p.I2C7, - p.I2S7, - p.SPI7, - p.USART7, - )), - peripherals::flexcomm::Flexcomm8::from((p.FLEXCOMM8, p.SPI8)), - ), - gint: Gint::from((p.GINT0, p.GINT1)), - gpio: Gpio::from(p.GPIO), - hashcrypt: Hashcrypt::from(p.HASHCRYPT), - inputmux: InputMux::from(p.INPUTMUX), - iocon: Iocon::from(p.IOCON), - pint: Pint::from(p.PINT), - pfr: Pfr::new(), - pmc: Pmc::from(p.PMC), - prince: Prince::from(p.PRINCE), - puf: Puf::from(p.PUF), - rng: Rng::from(p.RNG), - rtc: Rtc::from(p.RTC), - syscon: Syscon::from(p.SYSCON), - usbfs: Usbfs::from((p.USB0, p.USBFSH)), - usbhs: Usbhs::from((p.USBPHY, p.USB1, p.USBHSH)), - utick: Utick::from(p.UTICK0), - - // Raw peripherals - AHB_SECURE_CTRL: p.AHB_SECURE_CTRL, - CRC_ENGINE: p.CRC_ENGINE, - FLASH_CMPA: p.FLASH_CMPA, - FLASH_CFPA0: p.FLASH_CFPA0, - SAU: p.SAU, - SCT0: p.SCT0, - - // Core peripherals - CPUID: cp.CPUID, - DCB: cp.DCB, - DWT: cp.DWT, - MPU: cp.MPU, - NVIC: cp.NVIC, - SCB: cp.SCB, - } - } -} - impl From<(raw::Peripherals, raw::CorePeripherals)> for Peripherals { fn from(raw: (raw::Peripherals, raw::CorePeripherals)) -> Self { let cp = raw.1; @@ -427,14 +301,12 @@ impl From<(raw::Peripherals, raw::CorePeripherals)> for Peripherals { MPU: cp.MPU, NVIC: cp.NVIC, SCB: cp.SCB, - #[cfg(not(feature = "rtic-peripherals"))] SYST: cp.SYST, } } } impl Peripherals { - #[cfg(not(feature = "rtic-peripherals"))] pub fn take() -> Option { Some(Self::from(( raw::Peripherals::take()?, @@ -442,17 +314,6 @@ impl Peripherals { ))) } - // rtic::Peripherals::take does not exist - // - // #[cfg(feature = "rtic-peripherals")] - // pub fn take() -> Option { - // Some(Self::from(( - // raw::Peripherals::take()?, - // rtic::Peripherals::take()?, - // ))) - // } - - #[cfg(not(feature = "rtic-peripherals"))] /// # Safety /// /// Steals peripherals, must not be used if one of the peripherals diff --git a/src/peripherals/hashcrypt.rs b/src/peripherals/hashcrypt.rs index 65519b9..abe5cd7 100644 --- a/src/peripherals/hashcrypt.rs +++ b/src/peripherals/hashcrypt.rs @@ -39,12 +39,12 @@ impl Hashcrypt { impl Hashcrypt { /// SHA-1, as in RustCrypto `digest` trait - pub fn sha1(&mut self) -> Sha1 { + pub fn sha1(&mut self) -> Sha1<'_> { Sha1::from(self) } /// SHA-256, as in RustCrypto `digest` trait - pub fn sha256(&mut self) -> Sha256 { + pub fn sha256(&mut self) -> Sha256<'_> { Sha256::from(self) } @@ -70,7 +70,7 @@ impl Hashcrypt { /// /// DOES NOT PROPERLY CHECK IF PUF AES KEY IS SETUP YET! /// TODO: have user pass in some token signaling PUF AES key is setup - pub fn puf_aes(&mut self) -> aes::Aes256 { + pub fn puf_aes(&mut self) -> aes::Aes256<'_> { Aes::new(self, AesKey::Puf, aes::Mode::Encrypt) } } diff --git a/src/peripherals/pfr.rs b/src/peripherals/pfr.rs index 30157e8..18e5364 100644 --- a/src/peripherals/pfr.rs +++ b/src/peripherals/pfr.rs @@ -116,6 +116,7 @@ struct BootloaderTree { reserved_skboot_authenticate_interface: u32, } +#[allow(non_snake_case)] #[repr(C)] struct FlashDriverInterface { version: u32, diff --git a/src/traits/flash.rs b/src/traits/flash.rs index 528c6bd..17908a8 100644 --- a/src/traits/flash.rs +++ b/src/traits/flash.rs @@ -28,7 +28,7 @@ pub type Result = core::result::Result<(), Error>; // pub trait FlashOps: Locking + WriteErase + Read {} -pub trait Read> { +pub trait Read { // Address alignment? fn read_native(&self, address: usize, array: &mut GenericArray); @@ -51,7 +51,7 @@ pub trait Read> { } } -pub trait WriteErase, WriteSize: ArrayLength> { +pub trait WriteErase { /// check flash status fn status(&self) -> Result;