Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = []

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) });
Expand All @@ -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 {
Expand All @@ -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");
}
}
19 changes: 9 additions & 10 deletions examples/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/ctimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions examples/external_interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use lpc55_hal as hal;

#[entry]
fn main() -> ! {
heprintln!("External interrupts").unwrap();
heprintln!("External interrupts");

let mut hal = hal::new();

Expand Down Expand Up @@ -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");
}
}
}
38 changes: 19 additions & 19 deletions examples/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -192,32 +192,32 @@ 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);
flash.write_u128(0x4_0210, 0x7654321).unwrap();
// 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;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down
11 changes: 5 additions & 6 deletions examples/itm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/measure_frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading
Loading