Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #75

Merged
merged 6 commits into from
Jan 21, 2025
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ jobs:
- name: Build
run: cargo build --release --verbose --target ${{ matrix.target }}

- name: Lint
run: cargo clippy --release --verbose --target ${{ matrix.target }} -- -D warnings

- name: fmt
run: cargo fmt --check

- name: Build examples
run: cargo build --verbose --examples --target ${{ matrix.target }}
if: matrix.target != 'x86_64-unknown-linux-gnu'
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ littlefs2 = { version = "0.5", optional = true }
[dev-dependencies]
aes = "0.7"
cortex-m-rt = "0.6"
# cortex-m-rtic = "0.5"
lpc55-rtic = "0.5"
rtic = { package = "cortex-m-rtic", version = "1" }
cortex-m-semihosting = "0.3"
heapless = "0.7"
panic-halt = "0.2"
Expand Down
4 changes: 3 additions & 1 deletion examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,7 @@ fn main() -> ! {
}

heprintln!("looping").unwrap();
loop {}
loop {
heprintln!("looping").unwrap();
}
}
6 changes: 3 additions & 3 deletions examples/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn main() -> ! {
//
// via software
//
let mut sw_block = block.clone();
let cipher = aes::Aes256::new(&key);
let mut sw_block = block;
let cipher = aes::Aes256::new(key);

let (sw_cyc_enc, _) = hal::count_cycles(|| {
cipher.encrypt_block(&mut sw_block);
Expand All @@ -57,7 +57,7 @@ fn main() -> ! {
//
// via hardware
//
let mut hw_block = block.clone();
let mut hw_block = block;
let cipher = hashcrypt.aes256(&raw_key);

cipher.prime_for_encryption();
Expand Down
4 changes: 2 additions & 2 deletions examples/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ fn main() -> ! {
buf[..4].copy_from_slice(&data);

flash
.write_native(WHERE, &generic_array::GenericArray::from_slice(&buf))
.write_native(WHERE, generic_array::GenericArray::from_slice(&buf))
.unwrap();
buf[0] = 37;
// // buf[3] = 37;
flash
.write_native(WHERE, &generic_array::GenericArray::from_slice(&buf))
.write_native(WHERE, generic_array::GenericArray::from_slice(&buf))
.unwrap();
flash.write_u8(0x4_000F, 69).ok();
flash.read(WHERE, &mut read_buf);
Expand Down
1 change: 0 additions & 1 deletion examples/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use hal::{
time::Hertz,
};

use ssd1306;
use ssd1306::prelude::*;

#[entry]
Expand Down
47 changes: 28 additions & 19 deletions examples/late.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! examples/late.rs

#![deny(unsafe_code)]
// something something about:
//
// error: use of deprecated item
Expand All @@ -11,34 +10,44 @@
#![no_main]
#![no_std]

use cortex_m_semihosting::hprintln;
use hal::raw::Interrupt;
use heapless::spsc::{Consumer, Producer, Queue};
use lpc55_hal as hal;
use panic_semihosting as _;

#[rtic::app(device = hal::raw)]
const APP: () = {
// Late resources
struct Resources {
#[rtic::app(device = lpc55_hal::raw)]
mod app {
use core::ptr::addr_of_mut;

use cortex_m_semihosting::hprintln;
use hal::raw::Interrupt;
use heapless::spsc::{Consumer, Producer, Queue};
use lpc55_hal as hal;

#[shared]
struct SharedResources {}

#[local]
struct LocalResources {
p: Producer<'static, u32, 4>,
c: Consumer<'static, u32, 4>,
}

#[init]
fn init(_: init::Context) -> init::LateResources {
fn init(_ctx: init::Context) -> (SharedResources, LocalResources, init::Monotonics) {
static mut Q: Queue<u32, 4> = Queue::new();

let (p, c) = Q.split();
let (p, c) = unsafe { (*addr_of_mut!(Q)).split() };

// Initialization of late resources
init::LateResources { p, c }
(
SharedResources {},
LocalResources { p, c },
init::Monotonics(),
)
}

#[idle(resources = [c])]
fn idle(c: idle::Context) -> ! {
#[idle(local = [c])]
fn idle(ctx: idle::Context) -> ! {
loop {
if let Some(byte) = c.resources.c.dequeue() {
if let Some(byte) = ctx.local.c.dequeue() {
hprintln!("received message: {}", byte).unwrap();
// cortex_m::asm::wfi();
} else {
Expand All @@ -47,8 +56,8 @@ const APP: () = {
}
}

#[task(binds = ADC0, resources = [p])]
fn adc0(c: adc0::Context) {
c.resources.p.enqueue(42).unwrap();
#[task(binds = ADC0, local = [p])]
fn adc0(ctx: adc0::Context) {
ctx.local.p.enqueue(42).unwrap();
}
};
}
2 changes: 1 addition & 1 deletion examples/pfr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() -> ! {
dump_cfpa(&cfpa);

heprintln!("Increment the version and write back cfpa!").ok();
cfpa.version = cfpa.version + 1;
cfpa.version += 1;
cfpa.secure_fw_version += 1;
cfpa.ns_fw_version += 1;
// increment a byte of customer data (with overflow)
Expand Down
14 changes: 8 additions & 6 deletions examples/prince.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> ! {
let mut syscon = hal.syscon;

// prince region 2 (128KB)
const DATA_ADDR: usize = 0x00080000 + 0;
const DATA_ADDR: usize = 0x00080000;

let _clocks = hal::ClockRequirements::default()
.system_frequency(12.MHz())
Expand All @@ -39,15 +39,15 @@ fn main() -> ! {
let flash = hal.flash.enabled(&mut syscon);
let mut flash = hal::FlashGordon::new(flash);

let mut rng = hal.rng.enabled(&mut syscon);
let rng = hal.rng.enabled(&mut syscon);

let mut prince = hal.prince.enabled(&mut rng);
let mut prince = hal.prince.enabled(&rng);

prince.enable_all_region_2();

hprintln!("writing AA's to flash data.").ok();

flash.erase_page((DATA_ADDR / 512) + 0).unwrap();
flash.erase_page(DATA_ADDR / 512).unwrap();
flash.erase_page((DATA_ADDR / 512) + 1).unwrap();

prince.write_encrypted(|_prince| {
Expand All @@ -58,19 +58,21 @@ fn main() -> ! {
hprintln!("Read bytes PRINCE ON:").ok();
let mut buf = [0u8; 1024];

#[allow(clippy::needless_range_loop)]
for i in 0..buf.len() {
let ptr = DATA_ADDR as *const u8;
buf[i] = unsafe { *ptr.offset(i as isize) };
buf[i] = unsafe { *ptr.add(i) };
}

dump_hex!(&buf[0..32]);

// Turn off PRINCE.
prince.disable_all_region_2();

#[allow(clippy::needless_range_loop)]
for i in 0..buf.len() {
let ptr = DATA_ADDR as *const u8;
buf[i] = unsafe { *ptr.offset(i as isize) };
buf[i] = unsafe { *ptr.add(i) };
}

hprintln!("Read bytes PRINCE OFF:").ok();
Expand Down
31 changes: 11 additions & 20 deletions examples/puf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn main() -> ! {
// write first 512-byte chunk
write_buf[0..4].copy_from_slice(&(State::Enrolled as u32).to_ne_bytes());
write_buf[16..].copy_from_slice(&ac[..496]);
flash.write(PUF_STATE_FLASH + 0, &write_buf).unwrap();
flash.write(PUF_STATE_FLASH, &write_buf).unwrap();

// // write 2nd chunk
write_buf.copy_from_slice(&ac[496..1008]);
Expand All @@ -117,10 +117,10 @@ fn main() -> ! {
}

for i in 0..kc1.len() {
assert!(kc1[i] == check_buf[1192 + 52 * 0 + i])
assert!(kc1[i] == check_buf[1192 + i])
}
for i in 0..kc2.len() {
assert!(kc2[i] == check_buf[1192 + 52 * 1 + i])
assert!(kc2[i] == check_buf[1192 + 52 + i])
}
for i in 0..kc3.len() {
assert!(kc3[i] == check_buf[1192 + 52 * 2 + i])
Expand All @@ -133,23 +133,12 @@ fn main() -> ! {
} else {
dbg!("The device is already enrolled.");
flash.read(PUF_STATE_FLASH + 16, &mut check_buf);
for i in 0..1192 {
ac[i] = check_buf[i];
}

for i in 0..kc1.len() {
kc1[i] = check_buf[1192 + 52 * 0 + i];
}
for i in 0..kc2.len() {
kc2[i] = check_buf[1192 + 52 * 1 + i];
}
for i in 0..kc3.len() {
kc3[i] = check_buf[1192 + 52 * 2 + i];
}
for i in 0..kc4.len() {
kc4[i] = check_buf[1192 + 52 * 3 + i];
}
ac.copy_from_slice(&check_buf[..1192]);

kc1.copy_from_slice(&check_buf[1192..][..52]);
kc2.copy_from_slice(&check_buf[1192 + 52..][..52]);
kc3.copy_from_slice(&check_buf[1192 + 52 * 2..][..52]);
kc4.copy_from_slice(&check_buf[1192 + 52 * 3..][..52]);
dump_hex!(ac[..16], 16);
dump_hex!(ac[1192 - 16..], 16);

Expand Down Expand Up @@ -203,5 +192,7 @@ fn main() -> ! {
}

dbg!("Looping");
loop {}
loop {
dbg!("Loop");
}
}
5 changes: 4 additions & 1 deletion examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extern crate panic_semihosting; // 4004 bytes
#[macro_use(block)]
extern crate nb;

use core::f32;

use cortex_m_rt::entry;

use hal::drivers::{Pins, Pwm, Timer};
Expand Down Expand Up @@ -95,8 +97,9 @@ fn main() -> ! {
}
}

#[allow(clippy::needless_range_loop)]
for i in 0..3 {
let duty = (sin(duties[i] * 3.14159265f32 / 180f32) * 255f32) as u16;
let duty = (sin(duties[i] * f32::consts::PI / 180f32) * 255f32) as u16;
match i {
0 => {
// need to tune down red some
Expand Down
43 changes: 25 additions & 18 deletions examples/rtic_led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@

extern crate panic_semihosting;
// extern crate panic_halt;
use cortex_m_semihosting::dbg;

use hal::{drivers::pins, drivers::pins::Level, prelude::*, typestates::pin};
use lpc55_hal as hal;
#[rtic::app(device = lpc55_hal::raw, peripherals = true)]
mod app {
use cortex_m_semihosting::dbg;

type RedLed = hal::Pin<pins::Pio1_6, pin::state::Gpio<pin::gpio::direction::Output>>;
use hal::{drivers::pins, drivers::pins::Level, prelude::*, typestates::pin};
use lpc55_hal as hal;

#[rtic::app(device = crate::hal::raw, peripherals = true)]
const APP: () = {
struct Resources {
type RedLed = hal::Pin<pins::Pio1_6, pin::state::Gpio<pin::gpio::direction::Output>>;
#[shared]
struct SharedResources {}

#[local]
struct LocalResources {
led: RedLed,
// delay: hal::clock::Ticks<'static, hal::syscon::Fro1MhzUtickClock<states::init_state::Enabled>>,
// sleep: hal::sleep::Busy<'static, 'static>,
}

#[init]
fn init(c: init::Context) -> init::LateResources {
fn init(c: init::Context) -> (SharedResources, LocalResources, init::Monotonics) {
// dbg!("init");
let _cp = c.core;
let dp = c.device;
Expand Down Expand Up @@ -48,18 +52,21 @@ const APP: () = {
// let mut utick = hal::utick::wrap(dp.UTICK).enabled(&mut syscon, &clock);
// // let mut sleep = hal::sleep::Busy::prepare(&mut utick);
// let mut sleep = hal::sleep::Busy::wrap(&mut utick);

init::LateResources {
led: red_led,
// delay,
// sleep,
}
(
SharedResources {},
LocalResources {
led: red_led,
// delay,
// sleep,
},
init::Monotonics(),
)
}

// #[idle(resources = [led, delay, sleep])]
#[idle(resources = [led])]
fn idle(c: idle::Context) -> ! {
let led = c.resources.led;
#[idle(local = [led])]
fn idle(ctx: idle::Context) -> ! {
let led = ctx.local.led;
loop {
dbg!("low");
led.set_low().unwrap();
Expand All @@ -70,4 +77,4 @@ const APP: () = {
// c.resources.sleep.sleep(c.resources.delay);
}
}
};
}
3 changes: 2 additions & 1 deletion examples/semihosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ fn main() -> ! {
const UUID: *mut u32 = 0x0009_FC70 as *mut u32;
// dbg!(UUID);
let mut uuid: [u32; 4] = [0; 4];
#[allow(clippy::needless_range_loop)]
for i in 0..4 {
uuid[i] = unsafe { dbg!(UUID.offset(i as isize).read_volatile()) };
uuid[i] = unsafe { dbg!(UUID.add(i).read_volatile()) };
}
// dbg!(uuid);

Expand Down
Loading
Loading