Skip to content

Commit 613bf9e

Browse files
committed
Update dependencies: rtfm->rtic, rustcrypto
1 parent 3022280 commit 613bf9e

16 files changed

+81
-85
lines changed

.cargo/config

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[target.thumbv8m.main-none-eabi]
2-
runner = "gdb-multiarch -q -x jlink.gdb"
2+
runner = "arm-none-eabi-gdb -q -x jlink.gdb"
33
rustflags = [
44
"-C", "link-arg=-Tlink.x",
55
]
66

77
[target.thumbv8m.main-none-eabihf]
8-
runner = "gdb-multiarch -q -x jlink.gdb"
8+
runner = "arm-none-eabi-gdb -q -x jlink.gdb"
99
rustflags = [
1010
"-C", "link-arg=-Tlink.x",
1111
]

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Architectural changes:
2828
- move from "single file per peripheral" to split between
2929
HAL wrappers for peripherals, and actual drivers
3030
- get rid of a lot of references/lifetimes which don't
31-
cooperate with RTFM
31+
cooperate with RTIC
3232

3333
The clock tree will definitely need some more work.
3434
It's a conundrum between compile-time vs runtime checks,

Cargo.toml

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ build = "build.rs"
1616
circle-ci = { repository = "nickray/lpc55-hal" }
1717

1818
[dependencies]
19-
bare-metal = "0.2"
20-
block-buffer = "0.7.3"
21-
block-cipher = "0.7.0"
19+
bare-metal = "1"
20+
block-buffer = "0.9.0"
21+
block-cipher = "0.8.0"
2222
cortex-m = "0.6"
2323
cortex-m-semihosting = "0.3"
24-
digest = "0.8.1"
24+
digest = "0.9.0"
2525
embedded-hal = { version = "0.2", features = ["unproven"] }
26-
generic-array = "0.13.2"
26+
generic-array = "0.14.3"
2727
lpc55-pac = "0.1.0"
2828

29-
nb = "0.1"
29+
nb = "1"
3030
# no-panic = "0.1.12"
3131
# nom = { version = "^5", default-features = false }
3232
cortex-m-funnel = { version = "0.1.0-alpha.1", optional = true }
33-
cortex-m-rtfm = { version = "0.5.1", optional = true }
33+
cortex-m-rtic = { version = "0.5.1", optional = true }
3434
# littlefs2 = { path = "../littlefs2", optional = true }
3535
littlefs2 = { git = "https://github.com/nickray/littlefs2", branch = "closures-instead-of-ub", optional = true }
3636
ufmt = { version = "0.1.0", optional = true }
@@ -43,20 +43,20 @@ aligned = "0.3.2"
4343
# salty = { path = "../salty", features = ["haase"] }
4444

4545
[dev-dependencies]
46-
aes-soft = "0.3"
46+
aes-soft = "0.4"
4747
cortex-m-rt = "0.6"
48-
cortex-m-rtfm = "0.5.1"
48+
cortex-m-rtic = "0.5.1"
4949
cortex-m-semihosting = "0.3"
50-
ga14 = { package = "generic-array", version = "0.14" }
50+
# ga14 = { package = "generic-array", version = "0.14" }
5151
# digest = { version = "0.8", default-features = false }
5252
heapless = "0.5"
5353
panic-halt = "0.2"
5454
panic-semihosting = { version = "0.5", features = ["jlink-quirks"] }
5555
# salty = { path = "../salty", features = ["haase"] }
5656
# salty = { path = "../salty", features = ["tweetnacl"] }
57-
sha2 = { version = "0.8.2", default-features = false }
57+
sha2 = { version = "0.9.1", default-features = false }
5858
ssd1306 = "0.3.0-alpha.2"
59-
sha-1 = { version = "0.8.2", default-features = false }
59+
sha-1 = { version = "0.9.1", default-features = false }
6060
# ssd1306 = { git = "https://github.com/jamwaffles/ssd1306.git", branch = "70x42-ish" }
6161
# ssd1306 = { path = "../ssd1306-tiny" }
6262

@@ -70,7 +70,7 @@ default = ["rt"]
7070
littlefs = ["littlefs2"]
7171
logging = ["cortex-m-funnel", "ufmt"]
7272
rt = ["lpc55-pac/rt"]
73-
rtfm-peripherals = ["cortex-m-rtfm"]
73+
rtic-peripherals = ["cortex-m-rtic"]
7474
# no longer a HAL feature, just for the usb examples
7575
highspeed-usb-example = []
7676
# # Boards

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ build-both:
55
clean:
66
rm -rf venv
77

8-
view-rtfm-expansion:
9-
rustfmt target/rtfm-expansion.rs
10-
vi target/rtfm-expansion.rs
8+
view-rtic-expansion:
9+
rustfmt target/rtic-expansion.rs
10+
vi target/rtic-expansion.rs
1111

1212
# turn off the LEDs and whatnot
1313
darkness:

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ over platform-dependencies, allowing firmware and drivers to be quite portable.
1717

1818
It also implements the [`usb-device`][usb-device] framework.
1919

20-
Moreover, this library is compatible with the Cortex-M implementation of [RTFM][cortex-m-rtfm],
20+
Moreover, this library is compatible with the Cortex-M implementation of [RTIC][cortex-m-rtic],
2121
a concurrency framework supporting preemptive multitasking with minimal footprint.
2222

2323
## Status
@@ -34,7 +34,7 @@ Next up will be:
3434

3535
See also the low-level companion library [LPC55S6x PAC][lpc55s6x-pac].
3636

37-
This HAL is intended to work with `cortex-m-rtfm` v0.5.
37+
This HAL is intended to work with `cortex-m-rtic` v0.5.
3838

3939
## Documentation
4040

@@ -61,7 +61,7 @@ After flashing [J-Link firmware][jlink-fw] on the on-board LPCXpresso V2 debugge
6161
make jlink
6262

6363
# in another terminal
64-
make run-example EXAMPLE=rtfm_led # or any other example
64+
make run-example EXAMPLE=rtic_led # or any other example
6565
```
6666

6767
## Setup
@@ -92,7 +92,7 @@ from the various [STM32 HALs][stm32-rs].
9292
[cortex-m33]: https://developer.arm.com/ip-products/processors/cortex-m/cortex-m33
9393
[embedded-hal]: https://lib.rs/embedded-hal
9494
[usb-device]: https://lib.rs/usb-device
95-
[cortex-m-rtfm]: https://lib.rs/cortex-m-rtfm
95+
[cortex-m-rtic]: https://lib.rs/cortex-m-rtic
9696
[lpc55s6x-pac]: https://lib.rs/lpc55s6x-pac
9797
[lpc8xx-hal]: https://github.com/lpc-rs/lpc8xx-hal
9898
[stm32-rs]: https://github.com/stm32-rs

examples/aes.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ use hal::prelude::*;
1414
#[allow(unused_imports)]
1515
use lpc55_hal as hal;
1616

17-
use aes_soft::block_cipher_trait::BlockCipher as _;
18-
use aes_soft::block_cipher_trait::generic_array::GenericArray as GA12;
17+
use aes_soft::block_cipher::{BlockCipher, NewBlockCipher};
1918

2019
use block_cipher::BlockCipher as _;
21-
use ga14::GenericArray as GA14;
20+
use generic_array::GenericArray;
2221

2322
use cortex_m_semihosting::{dbg, hprintln};
2423

@@ -29,37 +28,36 @@ fn main() -> ! {
2928
let mut hashcrypt = hal::Hashcrypt::from(dp.HASHCRYPT).enabled(&mut syscon);
3029

3130
let raw_key = [0u8; 32];
32-
let key12 = GA12::from_slice(&raw_key);
31+
let key = GenericArray::from_slice(&raw_key);
3332

3433
let raw_block = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
35-
let block12 = GA12::clone_from_slice(&raw_block);
36-
let block14 = GA14::clone_from_slice(&raw_block);
34+
let block = GenericArray::clone_from_slice(&raw_block);
3735

3836
//
3937
// via software
4038
//
41-
let mut sw_block = block12.clone();
42-
let cipher = aes_soft::Aes256::new(&key12);
39+
let mut sw_block = block.clone();
40+
let cipher = aes_soft::Aes256::new(&key);
4341

4442
let (sw_cyc_enc, _) = hal::count_cycles(|| {
4543
cipher.encrypt_block(&mut sw_block);
4644
});
4745
hprintln!("encrypting with aes-soft took {} cycles", sw_cyc_enc).unwrap();
4846

49-
let sw_encrypted_block: [u8; 16] = sw_block.as_ref().try_into().unwrap();
47+
let sw_encrypted_block: [u8; 16] = sw_block[..].try_into().unwrap();
5048

5149
let (sw_cyc_dec, _) = hal::count_cycles(|| {
5250
cipher.decrypt_block(&mut sw_block);
5351
});
5452
hprintln!("decrypting with aes-soft took {} cycles", sw_cyc_dec).unwrap();
5553

5654
// check sw decrypt⚬encrypt = id
57-
assert_eq!(sw_block, block12);
55+
assert_eq!(sw_block, block);
5856

5957
//
6058
// via hardware
6159
//
62-
let mut hw_block = block14.clone();
60+
let mut hw_block = block.clone();
6361
let cipher = hashcrypt.aes256(&raw_key);
6462

6563
cipher.prime_for_encryption();
@@ -85,7 +83,7 @@ fn main() -> ! {
8583
hprintln!("speedup: {}x", sw_cyc_dec / hw_cyc_dec).unwrap();
8684

8785
// check hw decrypt⚬encrypt = id
88-
assert_eq!(hw_block, block14);
86+
assert_eq!(hw_block, block);
8987

9088

9189
// // Finally, PUF key

examples/late.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use heapless::{
2121
use lpc55_hal as hal;
2222
use panic_semihosting as _;
2323

24-
#[rtfm::app(device = hal::raw)]
24+
#[rtic::app(device = hal::raw)]
2525
const APP: () = {
2626
// Late resources
2727
struct Resources {
@@ -46,7 +46,7 @@ const APP: () = {
4646
hprintln!("received message: {}", byte).unwrap();
4747
// cortex_m::asm::wfi();
4848
} else {
49-
rtfm::pend(Interrupt::ADC0);
49+
rtic::pend(Interrupt::ADC0);
5050
}
5151
}
5252
}

examples/rtfm_led.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hal::{
1515

1616
type RedLed = hal::Pin<pins::Pio1_6, pin::state::Gpio<pin::gpio::direction::Output>>;
1717

18-
#[rtfm::app(device = crate::hal::raw, peripherals = true)]
18+
#[rtic::app(device = crate::hal::raw, peripherals = true)]
1919
const APP: () = {
2020
struct Resources {
2121
led: RedLed,

examples/sha.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cortex_m_rt::entry;
77
use cortex_m_semihosting::dbg;
88

99
use lpc55_hal as hal;
10-
use hal::traits::digest::{FixedOutput, Input};
10+
use hal::traits::digest::{FixedOutput, Update};
1111

1212
#[entry]
1313
fn main() -> ! {
@@ -32,15 +32,15 @@ fn main() -> ! {
3232

3333
let (hw_cyc, hw_result) = hal::count_cycles(|| {
3434
let mut hw_sha1 = hashcrypt.sha1();
35-
hw_sha1.input(msg);
36-
hw_sha1.fixed_result()
35+
hw_sha1.update(msg);
36+
hw_sha1.finalize_fixed()
3737
});
3838
hw_cycles = hw_cyc;
3939

4040
let (sw_cyc, sw_result) = hal::count_cycles(|| {
4141
let mut sw_sha1: sha1::Sha1 = Default::default();
42-
sw_sha1.input(msg);
43-
sw_sha1.fixed_result()
42+
sw_sha1.update(msg);
43+
sw_sha1.finalize_fixed()
4444
});
4545
sw_cycles = sw_cyc;
4646
assert_eq!(hw_result, sw_result);
@@ -55,15 +55,15 @@ fn main() -> ! {
5555

5656
let (hw_cyc, hw_result) = hal::count_cycles(|| {
5757
let mut hw_sha256 = hashcrypt.sha256();
58-
hw_sha256.input(msg);
59-
hw_sha256.fixed_result()
58+
hw_sha256.update(msg);
59+
hw_sha256.finalize_fixed()
6060
});
6161
hw_cycles = hw_cyc;
6262

6363
let (sw_cyc, sw_result) = hal::count_cycles(|| {
6464
let mut sw_sha256: sha2::Sha256 = Default::default();
65-
sw_sha256.input(msg);
66-
sw_sha256.fixed_result()
65+
sw_sha256.update(msg);
66+
sw_sha256.finalize_fixed()
6767
});
6868
sw_cycles = sw_cyc;
6969

src/drivers/aes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core::convert::TryInto;
22

33
use aligned::{A4, Aligned};
4-
use block_buffer::byteorder::{ByteOrder, BE};
54

65
use crate::{
76
peripherals::hashcrypt::Hashcrypt,
@@ -169,7 +168,7 @@ impl<'a, Size: KeySize> Aes<'a, Size> {
169168
}
170169

171170
for i in 0..4 {
172-
BE::write_u32_into(&[self.digest0[i].read().bits()], &mut block.as_mut_slice()[4*i..4*i + 4]);
171+
block.as_mut_slice()[4*i..4*i + 4].copy_from_slice(&self.digest0[i].read().bits().to_be_bytes());
173172
}
174173
}
175174
}

src/drivers/flash.rs

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ enum FlashCommands {
236236
ReportEcc= 0xD,
237237
}
238238

239+
#[cfg(feature = "littlefs")]
239240
// const BASE_OFFSET: usize = 0x0007_d000;
240241
const BASE_OFFSET: usize = 0x0008_9800;
241242

src/drivers/sha.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use core::marker::PhantomData;
22

33
use aligned::{A4, Aligned};
4-
use block_buffer::{byteorder::{ByteOrder, BE}, BlockBuffer};
4+
use block_buffer::BlockBuffer;
55

66
use crate::{
77
peripherals::hashcrypt::Hashcrypt,
88
traits::{
9-
digest::{BlockInput, FixedOutput, Input /*, Reset*/},
9+
digest::{BlockInput, FixedOutputDirty, Update /*, Reset*/},
1010
digest::generic_array::{GenericArray, typenum::{U20, U32, U64}},
1111
},
1212
typestates::init_state::Enabled,
@@ -78,36 +78,34 @@ impl<Size: OutputSize> BlockInput for Sha<'_, Size> {
7878
type BlockSize = BlockSize;
7979
}
8080

81-
impl<Size: OutputSize> FixedOutput for Sha<'_, Size> {
81+
impl<Size: OutputSize> FixedOutputDirty for Sha<'_, Size> {
8282
type OutputSize = Size;
8383

84-
fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
84+
fn finalize_into_dirty(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) {
8585
self.finish();
8686
// cf `hashcrypt_get_data` ~line 315 of `fsl_hashcrypt.c`
87-
let mut out = GenericArray::<u8, Self::OutputSize>::default();
8887
for i in 0..Size::to_usize() / 4 {
89-
BE::write_u32_into(&[self.inner.raw.digest0[i].read().bits()], &mut out.as_mut_slice()[4*i..4*i + 4]);
88+
out.as_mut_slice()[4*i..4*i + 4].copy_from_slice(&self.inner.raw.digest0[i].read().bits().to_be_bytes());
9089
}
91-
out
9290
}
9391
}
9492

95-
impl<Size: OutputSize> Input for Sha<'_, Size> {
96-
fn input<B: AsRef<[u8]>>(&mut self, input: B) {
97-
self.input(input.as_ref());
93+
impl<Size: OutputSize> Update for Sha<'_, Size> {
94+
fn update(&mut self, data: impl AsRef<[u8]>) {
95+
self.update(data.as_ref());
9896
}
9997
}
10098

10199
// the actual implementation
102100

103101
impl<Size: OutputSize> Sha<'_, Size> {
104-
fn input(&mut self, input: &[u8]) {
102+
fn update(&mut self, data: &[u8]) {
105103
// Assumes that input.len() can be converted to u64 without overflow
106-
self.len += (input.len() as u64) << 3;
104+
self.len += (data.len() as u64) << 3;
107105
// need to convince compiler we're using buffer and peripheral
108106
// independently, and not doing a double &mut
109107
let peripheral = &mut self.inner;
110-
self.buffer.input(input, |input| Self::process_block(peripheral, input));
108+
self.buffer.input_block(data, |data| Self::process_block(peripheral, data));
111109
}
112110

113111
// relevant code is ~line 800 in fsl_hashcrypt.c
@@ -130,7 +128,7 @@ impl<Size: OutputSize> Sha<'_, Size> {
130128
fn finish(&mut self) {
131129
let peripheral = &mut self.inner;
132130
let l = self.len;
133-
self.buffer.len64_padding::<BE, _>(l, |block| Self::process_block(peripheral, block));
131+
self.buffer.len64_padding_be(l, |block| Self::process_block(peripheral, block));
134132
while peripheral.raw.status.read().digest().is_not_ready() {
135133
continue;
136134
}

src/drivers/usbd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ where
119119

120120
pub fn clear_interrupt(&mut self) {
121121
// clear interrupt, otherwise in an interrupt-driven setting
122-
// like RTFM the idle loop will get starved.
122+
// like RTIC the idle loop will get starved.
123123
interrupt::free(|cs| {
124124
// set device address to 0
125125
let usb = self.usb_regs.borrow(cs);

src/drivers/usbd/endpoint_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct Instance {
4848
pub(crate) _marker: PhantomData<*const EndpointList>,
4949
}
5050

51-
// #[cfg(feature = "rtfm")]
51+
// #[cfg(feature = "rtic")]
5252
unsafe impl Send for Instance {}
5353
unsafe impl Send for EndpointList {}
5454

0 commit comments

Comments
 (0)