diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-05-30 13:07:18 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-05-30 13:07:18 +0200 |
| commit | c46172acac0be14b99148c2ec7aa38c9ac605fe1 (patch) | |
| tree | 2474c38ee9ee8180e6b09e1fc9544075cd711eaa | |
| parent | e9cb9badf730032be0daa65fd725fa538fc92459 (diff) | |
stm32: remove pointer-to-pointer-to-registers.
in chiptool pacs the register block struct is already a pointer, so
using pointers to it is redundant.
| -rw-r--r-- | embassy-stm32/src/can/fd/peripheral.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/can/fdcan.rs | 30 | ||||
| -rw-r--r-- | embassy-stm32/src/cryp/mod.rs | 104 | ||||
| -rw-r--r-- | embassy-stm32/src/dac/mod.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/dsihost.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/ltdc.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/f013.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/mod.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v2.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v3.rs | 8 |
10 files changed, 93 insertions, 90 deletions
diff --git a/embassy-stm32/src/can/fd/peripheral.rs b/embassy-stm32/src/can/fd/peripheral.rs index 9cd5f0785..7321ab230 100644 --- a/embassy-stm32/src/can/fd/peripheral.rs +++ b/embassy-stm32/src/can/fd/peripheral.rs | |||
| @@ -20,8 +20,9 @@ enum LoopbackMode { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub struct Registers { | 22 | pub struct Registers { |
| 23 | pub regs: &'static crate::pac::can::Fdcan, | 23 | pub regs: crate::pac::can::Fdcan, |
| 24 | pub msgram: &'static crate::pac::fdcanram::Fdcanram, | 24 | pub msgram: crate::pac::fdcanram::Fdcanram, |
| 25 | #[allow(dead_code)] | ||
| 25 | pub msg_ram_offset: usize, | 26 | pub msg_ram_offset: usize, |
| 26 | } | 27 | } |
| 27 | 28 | ||
diff --git a/embassy-stm32/src/can/fdcan.rs b/embassy-stm32/src/can/fdcan.rs index b772a3ca0..d0c8db090 100644 --- a/embassy-stm32/src/can/fdcan.rs +++ b/embassy-stm32/src/can/fdcan.rs | |||
| @@ -265,6 +265,7 @@ impl<'d, T: Instance> CanConfigurator<'d, T> { | |||
| 265 | }); | 265 | }); |
| 266 | T::registers().into_mode(self.config, mode); | 266 | T::registers().into_mode(self.config, mode); |
| 267 | Can { | 267 | Can { |
| 268 | _phantom: PhantomData, | ||
| 268 | config: self.config, | 269 | config: self.config, |
| 269 | info: self.info, | 270 | info: self.info, |
| 270 | state: self.state, | 271 | state: self.state, |
| @@ -292,10 +293,11 @@ impl<'d, T: Instance> CanConfigurator<'d, T> { | |||
| 292 | 293 | ||
| 293 | /// FDCAN Instance | 294 | /// FDCAN Instance |
| 294 | pub struct Can<'d> { | 295 | pub struct Can<'d> { |
| 296 | _phantom: PhantomData<&'d ()>, | ||
| 295 | config: crate::can::fd::config::FdCanConfig, | 297 | config: crate::can::fd::config::FdCanConfig, |
| 296 | info: &'static Info, | 298 | info: &'static Info, |
| 297 | state: &'static State, | 299 | state: &'static State, |
| 298 | instance: &'d crate::pac::can::Fdcan, | 300 | instance: crate::pac::can::Fdcan, |
| 299 | _mode: OperatingMode, | 301 | _mode: OperatingMode, |
| 300 | properties: Properties, | 302 | properties: Properties, |
| 301 | } | 303 | } |
| @@ -354,6 +356,7 @@ impl<'d> Can<'d> { | |||
| 354 | pub fn split(self) -> (CanTx<'d>, CanRx<'d>, Properties) { | 356 | pub fn split(self) -> (CanTx<'d>, CanRx<'d>, Properties) { |
| 355 | ( | 357 | ( |
| 356 | CanTx { | 358 | CanTx { |
| 359 | _phantom: PhantomData, | ||
| 357 | info: self.info, | 360 | info: self.info, |
| 358 | state: self.state, | 361 | state: self.state, |
| 359 | config: self.config, | 362 | config: self.config, |
| @@ -361,6 +364,7 @@ impl<'d> Can<'d> { | |||
| 361 | _mode: self._mode, | 364 | _mode: self._mode, |
| 362 | }, | 365 | }, |
| 363 | CanRx { | 366 | CanRx { |
| 367 | _phantom: PhantomData, | ||
| 364 | info: self.info, | 368 | info: self.info, |
| 365 | state: self.state, | 369 | state: self.state, |
| 366 | _instance: self.instance, | 370 | _instance: self.instance, |
| @@ -372,6 +376,7 @@ impl<'d> Can<'d> { | |||
| 372 | /// Join split rx and tx portions back together | 376 | /// Join split rx and tx portions back together |
| 373 | pub fn join(tx: CanTx<'d>, rx: CanRx<'d>) -> Self { | 377 | pub fn join(tx: CanTx<'d>, rx: CanRx<'d>) -> Self { |
| 374 | Can { | 378 | Can { |
| 379 | _phantom: PhantomData, | ||
| 375 | config: tx.config, | 380 | config: tx.config, |
| 376 | info: tx.info, | 381 | info: tx.info, |
| 377 | state: tx.state, | 382 | state: tx.state, |
| @@ -408,9 +413,10 @@ pub type TxBuf<const BUF_SIZE: usize> = Channel<CriticalSectionRawMutex, Frame, | |||
| 408 | 413 | ||
| 409 | /// Buffered FDCAN Instance | 414 | /// Buffered FDCAN Instance |
| 410 | pub struct BufferedCan<'d, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> { | 415 | pub struct BufferedCan<'d, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> { |
| 416 | _phantom: PhantomData<&'d ()>, | ||
| 411 | info: &'static Info, | 417 | info: &'static Info, |
| 412 | state: &'static State, | 418 | state: &'static State, |
| 413 | _instance: &'d crate::pac::can::Fdcan, | 419 | _instance: crate::pac::can::Fdcan, |
| 414 | _mode: OperatingMode, | 420 | _mode: OperatingMode, |
| 415 | tx_buf: &'static TxBuf<TX_BUF_SIZE>, | 421 | tx_buf: &'static TxBuf<TX_BUF_SIZE>, |
| 416 | rx_buf: &'static RxBuf<RX_BUF_SIZE>, | 422 | rx_buf: &'static RxBuf<RX_BUF_SIZE>, |
| @@ -421,12 +427,13 @@ impl<'c, 'd, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> BufferedCan<'d, | |||
| 421 | fn new( | 427 | fn new( |
| 422 | info: &'static Info, | 428 | info: &'static Info, |
| 423 | state: &'static State, | 429 | state: &'static State, |
| 424 | _instance: &'d crate::pac::can::Fdcan, | 430 | _instance: crate::pac::can::Fdcan, |
| 425 | _mode: OperatingMode, | 431 | _mode: OperatingMode, |
| 426 | tx_buf: &'static TxBuf<TX_BUF_SIZE>, | 432 | tx_buf: &'static TxBuf<TX_BUF_SIZE>, |
| 427 | rx_buf: &'static RxBuf<RX_BUF_SIZE>, | 433 | rx_buf: &'static RxBuf<RX_BUF_SIZE>, |
| 428 | ) -> Self { | 434 | ) -> Self { |
| 429 | BufferedCan { | 435 | BufferedCan { |
| 436 | _phantom: PhantomData, | ||
| 430 | info, | 437 | info, |
| 431 | state, | 438 | state, |
| 432 | _instance, | 439 | _instance, |
| @@ -539,9 +546,10 @@ pub type BufferedFdCanReceiver = DynamicReceiver<'static, Result<FdEnvelope, Bus | |||
| 539 | 546 | ||
| 540 | /// Buffered FDCAN Instance | 547 | /// Buffered FDCAN Instance |
| 541 | pub struct BufferedCanFd<'d, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> { | 548 | pub struct BufferedCanFd<'d, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> { |
| 549 | _phantom: PhantomData<&'d ()>, | ||
| 542 | info: &'static Info, | 550 | info: &'static Info, |
| 543 | state: &'static State, | 551 | state: &'static State, |
| 544 | _instance: &'d crate::pac::can::Fdcan, | 552 | _instance: crate::pac::can::Fdcan, |
| 545 | _mode: OperatingMode, | 553 | _mode: OperatingMode, |
| 546 | tx_buf: &'static TxFdBuf<TX_BUF_SIZE>, | 554 | tx_buf: &'static TxFdBuf<TX_BUF_SIZE>, |
| 547 | rx_buf: &'static RxFdBuf<RX_BUF_SIZE>, | 555 | rx_buf: &'static RxFdBuf<RX_BUF_SIZE>, |
| @@ -552,12 +560,13 @@ impl<'c, 'd, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> BufferedCanFd<' | |||
| 552 | fn new( | 560 | fn new( |
| 553 | info: &'static Info, | 561 | info: &'static Info, |
| 554 | state: &'static State, | 562 | state: &'static State, |
| 555 | _instance: &'d crate::pac::can::Fdcan, | 563 | _instance: crate::pac::can::Fdcan, |
| 556 | _mode: OperatingMode, | 564 | _mode: OperatingMode, |
| 557 | tx_buf: &'static TxFdBuf<TX_BUF_SIZE>, | 565 | tx_buf: &'static TxFdBuf<TX_BUF_SIZE>, |
| 558 | rx_buf: &'static RxFdBuf<RX_BUF_SIZE>, | 566 | rx_buf: &'static RxFdBuf<RX_BUF_SIZE>, |
| 559 | ) -> Self { | 567 | ) -> Self { |
| 560 | BufferedCanFd { | 568 | BufferedCanFd { |
| 569 | _phantom: PhantomData, | ||
| 561 | info, | 570 | info, |
| 562 | state, | 571 | state, |
| 563 | _instance, | 572 | _instance, |
| @@ -634,9 +643,10 @@ impl<'c, 'd, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> Drop for Buffer | |||
| 634 | 643 | ||
| 635 | /// FDCAN Rx only Instance | 644 | /// FDCAN Rx only Instance |
| 636 | pub struct CanRx<'d> { | 645 | pub struct CanRx<'d> { |
| 646 | _phantom: PhantomData<&'d ()>, | ||
| 637 | info: &'static Info, | 647 | info: &'static Info, |
| 638 | state: &'static State, | 648 | state: &'static State, |
| 639 | _instance: &'d crate::pac::can::Fdcan, | 649 | _instance: crate::pac::can::Fdcan, |
| 640 | _mode: OperatingMode, | 650 | _mode: OperatingMode, |
| 641 | } | 651 | } |
| 642 | 652 | ||
| @@ -654,10 +664,11 @@ impl<'d> CanRx<'d> { | |||
| 654 | 664 | ||
| 655 | /// FDCAN Tx only Instance | 665 | /// FDCAN Tx only Instance |
| 656 | pub struct CanTx<'d> { | 666 | pub struct CanTx<'d> { |
| 667 | _phantom: PhantomData<&'d ()>, | ||
| 657 | info: &'static Info, | 668 | info: &'static Info, |
| 658 | state: &'static State, | 669 | state: &'static State, |
| 659 | config: crate::can::fd::config::FdCanConfig, | 670 | config: crate::can::fd::config::FdCanConfig, |
| 660 | _instance: &'d crate::pac::can::Fdcan, | 671 | _instance: crate::pac::can::Fdcan, |
| 661 | _mode: OperatingMode, | 672 | _mode: OperatingMode, |
| 662 | } | 673 | } |
| 663 | 674 | ||
| @@ -966,7 +977,6 @@ trait SealedInstance { | |||
| 966 | const MSG_RAM_OFFSET: usize; | 977 | const MSG_RAM_OFFSET: usize; |
| 967 | 978 | ||
| 968 | fn info() -> &'static Info; | 979 | fn info() -> &'static Info; |
| 969 | //fn regs() -> &'static crate::pac::can::Fdcan; | ||
| 970 | fn registers() -> crate::can::fd::peripheral::Registers; | 980 | fn registers() -> crate::can::fd::peripheral::Registers; |
| 971 | fn state() -> &'static State; | 981 | fn state() -> &'static State; |
| 972 | unsafe fn mut_state() -> &'static mut State; | 982 | unsafe fn mut_state() -> &'static mut State; |
| @@ -994,7 +1004,7 @@ macro_rules! impl_fdcan { | |||
| 994 | 1004 | ||
| 995 | fn info() -> &'static Info { | 1005 | fn info() -> &'static Info { |
| 996 | static INFO: Info = Info { | 1006 | static INFO: Info = Info { |
| 997 | regs: Registers{regs: &crate::pac::$inst, msgram: &crate::pac::$msg_ram_inst, msg_ram_offset: $msg_ram_offset}, | 1007 | regs: Registers{regs: crate::pac::$inst, msgram: crate::pac::$msg_ram_inst, msg_ram_offset: $msg_ram_offset}, |
| 998 | interrupt0: crate::_generated::peripheral_interrupts::$inst::IT0::IRQ, | 1008 | interrupt0: crate::_generated::peripheral_interrupts::$inst::IT0::IRQ, |
| 999 | _interrupt1: crate::_generated::peripheral_interrupts::$inst::IT1::IRQ, | 1009 | _interrupt1: crate::_generated::peripheral_interrupts::$inst::IT1::IRQ, |
| 1000 | tx_waker: crate::_generated::peripheral_interrupts::$inst::IT0::pend, | 1010 | tx_waker: crate::_generated::peripheral_interrupts::$inst::IT0::pend, |
| @@ -1002,7 +1012,7 @@ macro_rules! impl_fdcan { | |||
| 1002 | &INFO | 1012 | &INFO |
| 1003 | } | 1013 | } |
| 1004 | fn registers() -> Registers { | 1014 | fn registers() -> Registers { |
| 1005 | Registers{regs: &crate::pac::$inst, msgram: &crate::pac::$msg_ram_inst, msg_ram_offset: Self::MSG_RAM_OFFSET} | 1015 | Registers{regs: crate::pac::$inst, msgram: crate::pac::$msg_ram_inst, msg_ram_offset: Self::MSG_RAM_OFFSET} |
| 1006 | } | 1016 | } |
| 1007 | unsafe fn mut_state() -> &'static mut State { | 1017 | unsafe fn mut_state() -> &'static mut State { |
| 1008 | static mut STATE: State = State::new(); | 1018 | static mut STATE: State = State::new(); |
diff --git a/embassy-stm32/src/cryp/mod.rs b/embassy-stm32/src/cryp/mod.rs index f19c94fda..e7808b454 100644 --- a/embassy-stm32/src/cryp/mod.rs +++ b/embassy-stm32/src/cryp/mod.rs | |||
| @@ -51,16 +51,16 @@ pub trait Cipher<'c> { | |||
| 51 | fn iv(&self) -> &[u8]; | 51 | fn iv(&self) -> &[u8]; |
| 52 | 52 | ||
| 53 | /// Sets the processor algorithm mode according to the associated cipher. | 53 | /// Sets the processor algorithm mode according to the associated cipher. |
| 54 | fn set_algomode(&self, p: &pac::cryp::Cryp); | 54 | fn set_algomode(&self, p: pac::cryp::Cryp); |
| 55 | 55 | ||
| 56 | /// Performs any key preparation within the processor, if necessary. | 56 | /// Performs any key preparation within the processor, if necessary. |
| 57 | fn prepare_key(&self, _p: &pac::cryp::Cryp) {} | 57 | fn prepare_key(&self, _p: pac::cryp::Cryp) {} |
| 58 | 58 | ||
| 59 | /// Performs any cipher-specific initialization. | 59 | /// Performs any cipher-specific initialization. |
| 60 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, _p: &pac::cryp::Cryp, _cryp: &Cryp<T, DmaIn, DmaOut>) {} | 60 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, _p: pac::cryp::Cryp, _cryp: &Cryp<T, DmaIn, DmaOut>) {} |
| 61 | 61 | ||
| 62 | /// Performs any cipher-specific initialization. | 62 | /// Performs any cipher-specific initialization. |
| 63 | async fn init_phase<T: Instance, DmaIn, DmaOut>(&self, _p: &pac::cryp::Cryp, _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>) | 63 | async fn init_phase<T: Instance, DmaIn, DmaOut>(&self, _p: pac::cryp::Cryp, _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>) |
| 64 | where | 64 | where |
| 65 | DmaIn: crate::cryp::DmaIn<T>, | 65 | DmaIn: crate::cryp::DmaIn<T>, |
| 66 | DmaOut: crate::cryp::DmaOut<T>, | 66 | DmaOut: crate::cryp::DmaOut<T>, |
| @@ -68,14 +68,14 @@ pub trait Cipher<'c> { | |||
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | /// Called prior to processing the last data block for cipher-specific operations. | 70 | /// Called prior to processing the last data block for cipher-specific operations. |
| 71 | fn pre_final(&self, _p: &pac::cryp::Cryp, _dir: Direction, _padding_len: usize) -> [u32; 4] { | 71 | fn pre_final(&self, _p: pac::cryp::Cryp, _dir: Direction, _padding_len: usize) -> [u32; 4] { |
| 72 | return [0; 4]; | 72 | return [0; 4]; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | /// Called after processing the last data block for cipher-specific operations. | 75 | /// Called after processing the last data block for cipher-specific operations. |
| 76 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( | 76 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( |
| 77 | &self, | 77 | &self, |
| 78 | _p: &pac::cryp::Cryp, | 78 | _p: pac::cryp::Cryp, |
| 79 | _cryp: &Cryp<T, DmaIn, DmaOut>, | 79 | _cryp: &Cryp<T, DmaIn, DmaOut>, |
| 80 | _dir: Direction, | 80 | _dir: Direction, |
| 81 | _int_data: &mut [u8; AES_BLOCK_SIZE], | 81 | _int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -87,7 +87,7 @@ pub trait Cipher<'c> { | |||
| 87 | /// Called after processing the last data block for cipher-specific operations. | 87 | /// Called after processing the last data block for cipher-specific operations. |
| 88 | async fn post_final<T: Instance, DmaIn, DmaOut>( | 88 | async fn post_final<T: Instance, DmaIn, DmaOut>( |
| 89 | &self, | 89 | &self, |
| 90 | _p: &pac::cryp::Cryp, | 90 | _p: pac::cryp::Cryp, |
| 91 | _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, | 91 | _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, |
| 92 | _dir: Direction, | 92 | _dir: Direction, |
| 93 | _int_data: &mut [u8; AES_BLOCK_SIZE], | 93 | _int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -142,7 +142,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for TdesEcb<'c, KEY_SIZE> { | |||
| 142 | self.iv | 142 | self.iv |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 145 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 146 | #[cfg(cryp_v1)] | 146 | #[cfg(cryp_v1)] |
| 147 | { | 147 | { |
| 148 | p.cr().modify(|w| w.set_algomode(0)); | 148 | p.cr().modify(|w| w.set_algomode(0)); |
| @@ -184,7 +184,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for TdesCbc<'c, KEY_SIZE> { | |||
| 184 | self.iv | 184 | self.iv |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 187 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 188 | #[cfg(cryp_v1)] | 188 | #[cfg(cryp_v1)] |
| 189 | { | 189 | { |
| 190 | p.cr().modify(|w| w.set_algomode(1)); | 190 | p.cr().modify(|w| w.set_algomode(1)); |
| @@ -226,7 +226,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for DesEcb<'c, KEY_SIZE> { | |||
| 226 | self.iv | 226 | self.iv |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 229 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 230 | #[cfg(cryp_v1)] | 230 | #[cfg(cryp_v1)] |
| 231 | { | 231 | { |
| 232 | p.cr().modify(|w| w.set_algomode(2)); | 232 | p.cr().modify(|w| w.set_algomode(2)); |
| @@ -267,7 +267,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for DesCbc<'c, KEY_SIZE> { | |||
| 267 | self.iv | 267 | self.iv |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 270 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 271 | #[cfg(cryp_v1)] | 271 | #[cfg(cryp_v1)] |
| 272 | { | 272 | { |
| 273 | p.cr().modify(|w| w.set_algomode(3)); | 273 | p.cr().modify(|w| w.set_algomode(3)); |
| @@ -308,7 +308,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesEcb<'c, KEY_SIZE> { | |||
| 308 | self.iv | 308 | self.iv |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | fn prepare_key(&self, p: &pac::cryp::Cryp) { | 311 | fn prepare_key(&self, p: pac::cryp::Cryp) { |
| 312 | #[cfg(cryp_v1)] | 312 | #[cfg(cryp_v1)] |
| 313 | { | 313 | { |
| 314 | p.cr().modify(|w| w.set_algomode(7)); | 314 | p.cr().modify(|w| w.set_algomode(7)); |
| @@ -322,7 +322,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesEcb<'c, KEY_SIZE> { | |||
| 322 | while p.sr().read().busy() {} | 322 | while p.sr().read().busy() {} |
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 325 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 326 | #[cfg(cryp_v1)] | 326 | #[cfg(cryp_v1)] |
| 327 | { | 327 | { |
| 328 | p.cr().modify(|w| w.set_algomode(2)); | 328 | p.cr().modify(|w| w.set_algomode(2)); |
| @@ -365,7 +365,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCbc<'c, KEY_SIZE> { | |||
| 365 | self.iv | 365 | self.iv |
| 366 | } | 366 | } |
| 367 | 367 | ||
| 368 | fn prepare_key(&self, p: &pac::cryp::Cryp) { | 368 | fn prepare_key(&self, p: pac::cryp::Cryp) { |
| 369 | #[cfg(cryp_v1)] | 369 | #[cfg(cryp_v1)] |
| 370 | { | 370 | { |
| 371 | p.cr().modify(|w| w.set_algomode(7)); | 371 | p.cr().modify(|w| w.set_algomode(7)); |
| @@ -379,7 +379,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCbc<'c, KEY_SIZE> { | |||
| 379 | while p.sr().read().busy() {} | 379 | while p.sr().read().busy() {} |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 382 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 383 | #[cfg(cryp_v1)] | 383 | #[cfg(cryp_v1)] |
| 384 | { | 384 | { |
| 385 | p.cr().modify(|w| w.set_algomode(5)); | 385 | p.cr().modify(|w| w.set_algomode(5)); |
| @@ -421,7 +421,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCtr<'c, KEY_SIZE> { | |||
| 421 | self.iv | 421 | self.iv |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 424 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 425 | #[cfg(cryp_v1)] | 425 | #[cfg(cryp_v1)] |
| 426 | { | 426 | { |
| 427 | p.cr().modify(|w| w.set_algomode(6)); | 427 | p.cr().modify(|w| w.set_algomode(6)); |
| @@ -469,29 +469,25 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> { | |||
| 469 | self.iv.as_slice() | 469 | self.iv.as_slice() |
| 470 | } | 470 | } |
| 471 | 471 | ||
| 472 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 472 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 473 | p.cr().modify(|w| w.set_algomode0(0)); | 473 | p.cr().modify(|w| w.set_algomode0(0)); |
| 474 | p.cr().modify(|w| w.set_algomode3(true)); | 474 | p.cr().modify(|w| w.set_algomode3(true)); |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, p: &pac::cryp::Cryp, _cryp: &Cryp<T, DmaIn, DmaOut>) { | 477 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, p: pac::cryp::Cryp, _cryp: &Cryp<T, DmaIn, DmaOut>) { |
| 478 | p.cr().modify(|w| w.set_gcm_ccmph(0)); | 478 | p.cr().modify(|w| w.set_gcm_ccmph(0)); |
| 479 | p.cr().modify(|w| w.set_crypen(true)); | 479 | p.cr().modify(|w| w.set_crypen(true)); |
| 480 | while p.cr().read().crypen() {} | 480 | while p.cr().read().crypen() {} |
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | async fn init_phase<T: Instance, DmaIn, DmaOut>( | 483 | async fn init_phase<T: Instance, DmaIn, DmaOut>(&self, p: pac::cryp::Cryp, _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>) { |
| 484 | &self, | ||
| 485 | p: &pac::cryp::Cryp, | ||
| 486 | _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, | ||
| 487 | ) { | ||
| 488 | p.cr().modify(|w| w.set_gcm_ccmph(0)); | 484 | p.cr().modify(|w| w.set_gcm_ccmph(0)); |
| 489 | p.cr().modify(|w| w.set_crypen(true)); | 485 | p.cr().modify(|w| w.set_crypen(true)); |
| 490 | while p.cr().read().crypen() {} | 486 | while p.cr().read().crypen() {} |
| 491 | } | 487 | } |
| 492 | 488 | ||
| 493 | #[cfg(cryp_v2)] | 489 | #[cfg(cryp_v2)] |
| 494 | fn pre_final(&self, p: &pac::cryp::Cryp, dir: Direction, _padding_len: usize) -> [u32; 4] { | 490 | fn pre_final(&self, p: pac::cryp::Cryp, dir: Direction, _padding_len: usize) -> [u32; 4] { |
| 495 | //Handle special GCM partial block process. | 491 | //Handle special GCM partial block process. |
| 496 | if dir == Direction::Encrypt { | 492 | if dir == Direction::Encrypt { |
| 497 | p.cr().modify(|w| w.set_crypen(false)); | 493 | p.cr().modify(|w| w.set_crypen(false)); |
| @@ -505,7 +501,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> { | |||
| 505 | } | 501 | } |
| 506 | 502 | ||
| 507 | #[cfg(any(cryp_v3, cryp_v4))] | 503 | #[cfg(any(cryp_v3, cryp_v4))] |
| 508 | fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { | 504 | fn pre_final(&self, p: pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { |
| 509 | //Handle special GCM partial block process. | 505 | //Handle special GCM partial block process. |
| 510 | p.cr().modify(|w| w.set_npblb(padding_len as u8)); | 506 | p.cr().modify(|w| w.set_npblb(padding_len as u8)); |
| 511 | [0; 4] | 507 | [0; 4] |
| @@ -514,7 +510,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> { | |||
| 514 | #[cfg(cryp_v2)] | 510 | #[cfg(cryp_v2)] |
| 515 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( | 511 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( |
| 516 | &self, | 512 | &self, |
| 517 | p: &pac::cryp::Cryp, | 513 | p: pac::cryp::Cryp, |
| 518 | cryp: &Cryp<T, DmaIn, DmaOut>, | 514 | cryp: &Cryp<T, DmaIn, DmaOut>, |
| 519 | dir: Direction, | 515 | dir: Direction, |
| 520 | int_data: &mut [u8; AES_BLOCK_SIZE], | 516 | int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -540,7 +536,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> { | |||
| 540 | #[cfg(cryp_v2)] | 536 | #[cfg(cryp_v2)] |
| 541 | async fn post_final<T: Instance, DmaIn, DmaOut>( | 537 | async fn post_final<T: Instance, DmaIn, DmaOut>( |
| 542 | &self, | 538 | &self, |
| 543 | p: &pac::cryp::Cryp, | 539 | p: pac::cryp::Cryp, |
| 544 | cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, | 540 | cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, |
| 545 | dir: Direction, | 541 | dir: Direction, |
| 546 | int_data: &mut [u8; AES_BLOCK_SIZE], | 542 | int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -614,29 +610,25 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> { | |||
| 614 | self.iv.as_slice() | 610 | self.iv.as_slice() |
| 615 | } | 611 | } |
| 616 | 612 | ||
| 617 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 613 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 618 | p.cr().modify(|w| w.set_algomode0(0)); | 614 | p.cr().modify(|w| w.set_algomode0(0)); |
| 619 | p.cr().modify(|w| w.set_algomode3(true)); | 615 | p.cr().modify(|w| w.set_algomode3(true)); |
| 620 | } | 616 | } |
| 621 | 617 | ||
| 622 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, p: &pac::cryp::Cryp, _cryp: &Cryp<T, DmaIn, DmaOut>) { | 618 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, p: pac::cryp::Cryp, _cryp: &Cryp<T, DmaIn, DmaOut>) { |
| 623 | p.cr().modify(|w| w.set_gcm_ccmph(0)); | 619 | p.cr().modify(|w| w.set_gcm_ccmph(0)); |
| 624 | p.cr().modify(|w| w.set_crypen(true)); | 620 | p.cr().modify(|w| w.set_crypen(true)); |
| 625 | while p.cr().read().crypen() {} | 621 | while p.cr().read().crypen() {} |
| 626 | } | 622 | } |
| 627 | 623 | ||
| 628 | async fn init_phase<T: Instance, DmaIn, DmaOut>( | 624 | async fn init_phase<T: Instance, DmaIn, DmaOut>(&self, p: pac::cryp::Cryp, _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>) { |
| 629 | &self, | ||
| 630 | p: &pac::cryp::Cryp, | ||
| 631 | _cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, | ||
| 632 | ) { | ||
| 633 | p.cr().modify(|w| w.set_gcm_ccmph(0)); | 625 | p.cr().modify(|w| w.set_gcm_ccmph(0)); |
| 634 | p.cr().modify(|w| w.set_crypen(true)); | 626 | p.cr().modify(|w| w.set_crypen(true)); |
| 635 | while p.cr().read().crypen() {} | 627 | while p.cr().read().crypen() {} |
| 636 | } | 628 | } |
| 637 | 629 | ||
| 638 | #[cfg(cryp_v2)] | 630 | #[cfg(cryp_v2)] |
| 639 | fn pre_final(&self, p: &pac::cryp::Cryp, dir: Direction, _padding_len: usize) -> [u32; 4] { | 631 | fn pre_final(&self, p: pac::cryp::Cryp, dir: Direction, _padding_len: usize) -> [u32; 4] { |
| 640 | //Handle special GCM partial block process. | 632 | //Handle special GCM partial block process. |
| 641 | if dir == Direction::Encrypt { | 633 | if dir == Direction::Encrypt { |
| 642 | p.cr().modify(|w| w.set_crypen(false)); | 634 | p.cr().modify(|w| w.set_crypen(false)); |
| @@ -650,7 +642,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> { | |||
| 650 | } | 642 | } |
| 651 | 643 | ||
| 652 | #[cfg(any(cryp_v3, cryp_v4))] | 644 | #[cfg(any(cryp_v3, cryp_v4))] |
| 653 | fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { | 645 | fn pre_final(&self, p: pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { |
| 654 | //Handle special GCM partial block process. | 646 | //Handle special GCM partial block process. |
| 655 | p.cr().modify(|w| w.set_npblb(padding_len as u8)); | 647 | p.cr().modify(|w| w.set_npblb(padding_len as u8)); |
| 656 | [0; 4] | 648 | [0; 4] |
| @@ -659,7 +651,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> { | |||
| 659 | #[cfg(cryp_v2)] | 651 | #[cfg(cryp_v2)] |
| 660 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( | 652 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( |
| 661 | &self, | 653 | &self, |
| 662 | p: &pac::cryp::Cryp, | 654 | p: pac::cryp::Cryp, |
| 663 | cryp: &Cryp<T, DmaIn, DmaOut>, | 655 | cryp: &Cryp<T, DmaIn, DmaOut>, |
| 664 | dir: Direction, | 656 | dir: Direction, |
| 665 | int_data: &mut [u8; AES_BLOCK_SIZE], | 657 | int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -685,7 +677,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> { | |||
| 685 | #[cfg(cryp_v2)] | 677 | #[cfg(cryp_v2)] |
| 686 | async fn post_final<T: Instance, DmaIn, DmaOut>( | 678 | async fn post_final<T: Instance, DmaIn, DmaOut>( |
| 687 | &self, | 679 | &self, |
| 688 | p: &pac::cryp::Cryp, | 680 | p: pac::cryp::Cryp, |
| 689 | cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, | 681 | cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, |
| 690 | dir: Direction, | 682 | dir: Direction, |
| 691 | int_data: &mut [u8; AES_BLOCK_SIZE], | 683 | int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -815,12 +807,12 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip | |||
| 815 | self.ctr.as_slice() | 807 | self.ctr.as_slice() |
| 816 | } | 808 | } |
| 817 | 809 | ||
| 818 | fn set_algomode(&self, p: &pac::cryp::Cryp) { | 810 | fn set_algomode(&self, p: pac::cryp::Cryp) { |
| 819 | p.cr().modify(|w| w.set_algomode0(1)); | 811 | p.cr().modify(|w| w.set_algomode0(1)); |
| 820 | p.cr().modify(|w| w.set_algomode3(true)); | 812 | p.cr().modify(|w| w.set_algomode3(true)); |
| 821 | } | 813 | } |
| 822 | 814 | ||
| 823 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, p: &pac::cryp::Cryp, cryp: &Cryp<T, DmaIn, DmaOut>) { | 815 | fn init_phase_blocking<T: Instance, DmaIn, DmaOut>(&self, p: pac::cryp::Cryp, cryp: &Cryp<T, DmaIn, DmaOut>) { |
| 824 | p.cr().modify(|w| w.set_gcm_ccmph(0)); | 816 | p.cr().modify(|w| w.set_gcm_ccmph(0)); |
| 825 | 817 | ||
| 826 | cryp.write_bytes_blocking(Self::BLOCK_SIZE, &self.block0); | 818 | cryp.write_bytes_blocking(Self::BLOCK_SIZE, &self.block0); |
| @@ -829,7 +821,7 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip | |||
| 829 | while p.cr().read().crypen() {} | 821 | while p.cr().read().crypen() {} |
| 830 | } | 822 | } |
| 831 | 823 | ||
| 832 | async fn init_phase<T: Instance, DmaIn, DmaOut>(&self, p: &pac::cryp::Cryp, cryp: &mut Cryp<'_, T, DmaIn, DmaOut>) | 824 | async fn init_phase<T: Instance, DmaIn, DmaOut>(&self, p: pac::cryp::Cryp, cryp: &mut Cryp<'_, T, DmaIn, DmaOut>) |
| 833 | where | 825 | where |
| 834 | DmaIn: crate::cryp::DmaIn<T>, | 826 | DmaIn: crate::cryp::DmaIn<T>, |
| 835 | DmaOut: crate::cryp::DmaOut<T>, | 827 | DmaOut: crate::cryp::DmaOut<T>, |
| @@ -847,7 +839,7 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip | |||
| 847 | } | 839 | } |
| 848 | 840 | ||
| 849 | #[cfg(cryp_v2)] | 841 | #[cfg(cryp_v2)] |
| 850 | fn pre_final(&self, p: &pac::cryp::Cryp, dir: Direction, _padding_len: usize) -> [u32; 4] { | 842 | fn pre_final(&self, p: pac::cryp::Cryp, dir: Direction, _padding_len: usize) -> [u32; 4] { |
| 851 | //Handle special CCM partial block process. | 843 | //Handle special CCM partial block process. |
| 852 | let mut temp1 = [0; 4]; | 844 | let mut temp1 = [0; 4]; |
| 853 | if dir == Direction::Decrypt { | 845 | if dir == Direction::Decrypt { |
| @@ -866,7 +858,7 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip | |||
| 866 | } | 858 | } |
| 867 | 859 | ||
| 868 | #[cfg(any(cryp_v3, cryp_v4))] | 860 | #[cfg(any(cryp_v3, cryp_v4))] |
| 869 | fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { | 861 | fn pre_final(&self, p: pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { |
| 870 | //Handle special GCM partial block process. | 862 | //Handle special GCM partial block process. |
| 871 | p.cr().modify(|w| w.set_npblb(padding_len as u8)); | 863 | p.cr().modify(|w| w.set_npblb(padding_len as u8)); |
| 872 | [0; 4] | 864 | [0; 4] |
| @@ -875,7 +867,7 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip | |||
| 875 | #[cfg(cryp_v2)] | 867 | #[cfg(cryp_v2)] |
| 876 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( | 868 | fn post_final_blocking<T: Instance, DmaIn, DmaOut>( |
| 877 | &self, | 869 | &self, |
| 878 | p: &pac::cryp::Cryp, | 870 | p: pac::cryp::Cryp, |
| 879 | cryp: &Cryp<T, DmaIn, DmaOut>, | 871 | cryp: &Cryp<T, DmaIn, DmaOut>, |
| 880 | dir: Direction, | 872 | dir: Direction, |
| 881 | int_data: &mut [u8; AES_BLOCK_SIZE], | 873 | int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -912,7 +904,7 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip | |||
| 912 | #[cfg(cryp_v2)] | 904 | #[cfg(cryp_v2)] |
| 913 | async fn post_final<T: Instance, DmaIn, DmaOut>( | 905 | async fn post_final<T: Instance, DmaIn, DmaOut>( |
| 914 | &self, | 906 | &self, |
| 915 | p: &pac::cryp::Cryp, | 907 | p: pac::cryp::Cryp, |
| 916 | cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, | 908 | cryp: &mut Cryp<'_, T, DmaIn, DmaOut>, |
| 917 | dir: Direction, | 909 | dir: Direction, |
| 918 | int_data: &mut [u8; AES_BLOCK_SIZE], | 910 | int_data: &mut [u8; AES_BLOCK_SIZE], |
| @@ -1083,9 +1075,9 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1083 | // Set data type to 8-bit. This will match software implementations. | 1075 | // Set data type to 8-bit. This will match software implementations. |
| 1084 | T::regs().cr().modify(|w| w.set_datatype(2)); | 1076 | T::regs().cr().modify(|w| w.set_datatype(2)); |
| 1085 | 1077 | ||
| 1086 | ctx.cipher.prepare_key(&T::regs()); | 1078 | ctx.cipher.prepare_key(T::regs()); |
| 1087 | 1079 | ||
| 1088 | ctx.cipher.set_algomode(&T::regs()); | 1080 | ctx.cipher.set_algomode(T::regs()); |
| 1089 | 1081 | ||
| 1090 | // Set encrypt/decrypt | 1082 | // Set encrypt/decrypt |
| 1091 | if dir == Direction::Encrypt { | 1083 | if dir == Direction::Encrypt { |
| @@ -1115,7 +1107,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1115 | // Flush in/out FIFOs | 1107 | // Flush in/out FIFOs |
| 1116 | T::regs().cr().modify(|w| w.fflush()); | 1108 | T::regs().cr().modify(|w| w.fflush()); |
| 1117 | 1109 | ||
| 1118 | ctx.cipher.init_phase_blocking(&T::regs(), self); | 1110 | ctx.cipher.init_phase_blocking(T::regs(), self); |
| 1119 | 1111 | ||
| 1120 | self.store_context(&mut ctx); | 1112 | self.store_context(&mut ctx); |
| 1121 | 1113 | ||
| @@ -1166,9 +1158,9 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1166 | // Set data type to 8-bit. This will match software implementations. | 1158 | // Set data type to 8-bit. This will match software implementations. |
| 1167 | T::regs().cr().modify(|w| w.set_datatype(2)); | 1159 | T::regs().cr().modify(|w| w.set_datatype(2)); |
| 1168 | 1160 | ||
| 1169 | ctx.cipher.prepare_key(&T::regs()); | 1161 | ctx.cipher.prepare_key(T::regs()); |
| 1170 | 1162 | ||
| 1171 | ctx.cipher.set_algomode(&T::regs()); | 1163 | ctx.cipher.set_algomode(T::regs()); |
| 1172 | 1164 | ||
| 1173 | // Set encrypt/decrypt | 1165 | // Set encrypt/decrypt |
| 1174 | if dir == Direction::Encrypt { | 1166 | if dir == Direction::Encrypt { |
| @@ -1198,7 +1190,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1198 | // Flush in/out FIFOs | 1190 | // Flush in/out FIFOs |
| 1199 | T::regs().cr().modify(|w| w.fflush()); | 1191 | T::regs().cr().modify(|w| w.fflush()); |
| 1200 | 1192 | ||
| 1201 | ctx.cipher.init_phase(&T::regs(), self).await; | 1193 | ctx.cipher.init_phase(T::regs(), self).await; |
| 1202 | 1194 | ||
| 1203 | self.store_context(&mut ctx); | 1195 | self.store_context(&mut ctx); |
| 1204 | 1196 | ||
| @@ -1462,7 +1454,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1462 | // Handle the final block, which is incomplete. | 1454 | // Handle the final block, which is incomplete. |
| 1463 | if last_block_remainder > 0 { | 1455 | if last_block_remainder > 0 { |
| 1464 | let padding_len = C::BLOCK_SIZE - last_block_remainder; | 1456 | let padding_len = C::BLOCK_SIZE - last_block_remainder; |
| 1465 | let temp1 = ctx.cipher.pre_final(&T::regs(), ctx.dir, padding_len); | 1457 | let temp1 = ctx.cipher.pre_final(T::regs(), ctx.dir, padding_len); |
| 1466 | 1458 | ||
| 1467 | let mut intermediate_data: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; | 1459 | let mut intermediate_data: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; |
| 1468 | let mut last_block: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; | 1460 | let mut last_block: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; |
| @@ -1478,7 +1470,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1478 | let mut mask: [u8; 16] = [0; 16]; | 1470 | let mut mask: [u8; 16] = [0; 16]; |
| 1479 | mask[..last_block_remainder].fill(0xFF); | 1471 | mask[..last_block_remainder].fill(0xFF); |
| 1480 | ctx.cipher | 1472 | ctx.cipher |
| 1481 | .post_final_blocking(&T::regs(), self, ctx.dir, &mut intermediate_data, temp1, mask); | 1473 | .post_final_blocking(T::regs(), self, ctx.dir, &mut intermediate_data, temp1, mask); |
| 1482 | } | 1474 | } |
| 1483 | 1475 | ||
| 1484 | ctx.payload_len += input.len() as u64; | 1476 | ctx.payload_len += input.len() as u64; |
| @@ -1559,7 +1551,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1559 | // Handle the final block, which is incomplete. | 1551 | // Handle the final block, which is incomplete. |
| 1560 | if last_block_remainder > 0 { | 1552 | if last_block_remainder > 0 { |
| 1561 | let padding_len = C::BLOCK_SIZE - last_block_remainder; | 1553 | let padding_len = C::BLOCK_SIZE - last_block_remainder; |
| 1562 | let temp1 = ctx.cipher.pre_final(&T::regs(), ctx.dir, padding_len); | 1554 | let temp1 = ctx.cipher.pre_final(T::regs(), ctx.dir, padding_len); |
| 1563 | 1555 | ||
| 1564 | let mut intermediate_data: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; | 1556 | let mut intermediate_data: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; |
| 1565 | let mut last_block: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; | 1557 | let mut last_block: [u8; AES_BLOCK_SIZE] = [0; AES_BLOCK_SIZE]; |
| @@ -1576,7 +1568,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1576 | let mut mask: [u8; 16] = [0; 16]; | 1568 | let mut mask: [u8; 16] = [0; 16]; |
| 1577 | mask[..last_block_remainder].fill(0xFF); | 1569 | mask[..last_block_remainder].fill(0xFF); |
| 1578 | ctx.cipher | 1570 | ctx.cipher |
| 1579 | .post_final(&T::regs(), self, ctx.dir, &mut intermediate_data, temp1, mask) | 1571 | .post_final(T::regs(), self, ctx.dir, &mut intermediate_data, temp1, mask) |
| 1580 | .await; | 1572 | .await; |
| 1581 | } | 1573 | } |
| 1582 | 1574 | ||
| @@ -1758,7 +1750,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> { | |||
| 1758 | self.load_key(ctx.cipher.key()); | 1750 | self.load_key(ctx.cipher.key()); |
| 1759 | 1751 | ||
| 1760 | // Prepare key if applicable. | 1752 | // Prepare key if applicable. |
| 1761 | ctx.cipher.prepare_key(&T::regs()); | 1753 | ctx.cipher.prepare_key(T::regs()); |
| 1762 | T::regs().cr().write(|w| w.0 = ctx.cr); | 1754 | T::regs().cr().write(|w| w.0 = ctx.cr); |
| 1763 | 1755 | ||
| 1764 | // Enable crypto processor. | 1756 | // Enable crypto processor. |
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 8a748ad72..489342a4a 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -508,7 +508,7 @@ impl<'d, T: Instance, DMACh1, DMACh2> Dac<'d, T, DMACh1, DMACh2> { | |||
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | trait SealedInstance { | 510 | trait SealedInstance { |
| 511 | fn regs() -> &'static crate::pac::dac::Dac; | 511 | fn regs() -> crate::pac::dac::Dac; |
| 512 | } | 512 | } |
| 513 | 513 | ||
| 514 | /// DAC instance. | 514 | /// DAC instance. |
| @@ -523,8 +523,8 @@ pub trait DacPin<T: Instance, const C: u8>: crate::gpio::Pin + 'static {} | |||
| 523 | foreach_peripheral!( | 523 | foreach_peripheral!( |
| 524 | (dac, $inst:ident) => { | 524 | (dac, $inst:ident) => { |
| 525 | impl crate::dac::SealedInstance for peripherals::$inst { | 525 | impl crate::dac::SealedInstance for peripherals::$inst { |
| 526 | fn regs() -> &'static crate::pac::dac::Dac { | 526 | fn regs() -> crate::pac::dac::Dac { |
| 527 | &crate::pac::$inst | 527 | crate::pac::$inst |
| 528 | } | 528 | } |
| 529 | } | 529 | } |
| 530 | 530 | ||
diff --git a/embassy-stm32/src/dsihost.rs b/embassy-stm32/src/dsihost.rs index f1c737fdc..253939394 100644 --- a/embassy-stm32/src/dsihost.rs +++ b/embassy-stm32/src/dsihost.rs | |||
| @@ -407,7 +407,7 @@ impl<'d, T: Instance> Drop for DsiHost<'d, T> { | |||
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | trait SealedInstance: crate::rcc::SealedRccPeripheral { | 409 | trait SealedInstance: crate::rcc::SealedRccPeripheral { |
| 410 | fn regs() -> &'static crate::pac::dsihost::Dsihost; | 410 | fn regs() -> crate::pac::dsihost::Dsihost; |
| 411 | } | 411 | } |
| 412 | 412 | ||
| 413 | /// DSI instance trait. | 413 | /// DSI instance trait. |
| @@ -419,8 +419,8 @@ pin_trait!(TePin, Instance); | |||
| 419 | foreach_peripheral!( | 419 | foreach_peripheral!( |
| 420 | (dsihost, $inst:ident) => { | 420 | (dsihost, $inst:ident) => { |
| 421 | impl crate::dsihost::SealedInstance for peripherals::$inst { | 421 | impl crate::dsihost::SealedInstance for peripherals::$inst { |
| 422 | fn regs() -> &'static crate::pac::dsihost::Dsihost { | 422 | fn regs() -> crate::pac::dsihost::Dsihost { |
| 423 | &crate::pac::$inst | 423 | crate::pac::$inst |
| 424 | } | 424 | } |
| 425 | } | 425 | } |
| 426 | 426 | ||
diff --git a/embassy-stm32/src/ltdc.rs b/embassy-stm32/src/ltdc.rs index 0cc8a0557..a2d6a3cee 100644 --- a/embassy-stm32/src/ltdc.rs +++ b/embassy-stm32/src/ltdc.rs | |||
| @@ -93,7 +93,7 @@ impl<'d, T: Instance> Drop for Ltdc<'d, T> { | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | trait SealedInstance: crate::rcc::SealedRccPeripheral { | 95 | trait SealedInstance: crate::rcc::SealedRccPeripheral { |
| 96 | fn regs() -> &'static crate::pac::ltdc::Ltdc; | 96 | fn regs() -> crate::pac::ltdc::Ltdc; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | /// DSI instance trait. | 99 | /// DSI instance trait. |
| @@ -132,8 +132,8 @@ pin_trait!(B7Pin, Instance); | |||
| 132 | foreach_peripheral!( | 132 | foreach_peripheral!( |
| 133 | (ltdc, $inst:ident) => { | 133 | (ltdc, $inst:ident) => { |
| 134 | impl crate::ltdc::SealedInstance for peripherals::$inst { | 134 | impl crate::ltdc::SealedInstance for peripherals::$inst { |
| 135 | fn regs() -> &'static crate::pac::ltdc::Ltdc { | 135 | fn regs() -> crate::pac::ltdc::Ltdc { |
| 136 | &crate::pac::$inst | 136 | crate::pac::$inst |
| 137 | } | 137 | } |
| 138 | } | 138 | } |
| 139 | 139 | ||
diff --git a/embassy-stm32/src/rcc/f013.rs b/embassy-stm32/src/rcc/f013.rs index 0946287ea..1c951a22b 100644 --- a/embassy-stm32/src/rcc/f013.rs +++ b/embassy-stm32/src/rcc/f013.rs | |||
| @@ -276,7 +276,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 276 | 276 | ||
| 277 | // Set prescalers | 277 | // Set prescalers |
| 278 | // CFGR has been written before (PLL, PLL48) don't overwrite these settings | 278 | // CFGR has been written before (PLL, PLL48) don't overwrite these settings |
| 279 | RCC.cfgr().modify(|w: &mut stm32_metapac::rcc::regs::Cfgr| { | 279 | RCC.cfgr().modify(|w| { |
| 280 | #[cfg(not(stm32f0))] | 280 | #[cfg(not(stm32f0))] |
| 281 | { | 281 | { |
| 282 | w.set_ppre1(config.apb1_pre); | 282 | w.set_ppre1(config.apb1_pre); |
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index b12a0db66..92a58ee9a 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -320,7 +320,7 @@ impl Rtc { | |||
| 320 | /// The registers retain their values during wakes from standby mode or system resets. They also | 320 | /// The registers retain their values during wakes from standby mode or system resets. They also |
| 321 | /// retain their value when Vdd is switched off as long as V_BAT is powered. | 321 | /// retain their value when Vdd is switched off as long as V_BAT is powered. |
| 322 | pub fn read_backup_register(&self, register: usize) -> Option<u32> { | 322 | pub fn read_backup_register(&self, register: usize) -> Option<u32> { |
| 323 | RTC::read_backup_register(&RTC::regs(), register) | 323 | RTC::read_backup_register(RTC::regs(), register) |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | /// Set content of the backup register. | 326 | /// Set content of the backup register. |
| @@ -328,7 +328,7 @@ impl Rtc { | |||
| 328 | /// The registers retain their values during wakes from standby mode or system resets. They also | 328 | /// The registers retain their values during wakes from standby mode or system resets. They also |
| 329 | /// retain their value when Vdd is switched off as long as V_BAT is powered. | 329 | /// retain their value when Vdd is switched off as long as V_BAT is powered. |
| 330 | pub fn write_backup_register(&self, register: usize, value: u32) { | 330 | pub fn write_backup_register(&self, register: usize, value: u32) { |
| 331 | RTC::write_backup_register(&RTC::regs(), register, value) | 331 | RTC::write_backup_register(RTC::regs(), register, value) |
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | #[cfg(feature = "low-power")] | 334 | #[cfg(feature = "low-power")] |
| @@ -482,13 +482,13 @@ trait SealedInstance { | |||
| 482 | /// | 482 | /// |
| 483 | /// The registers retain their values during wakes from standby mode or system resets. They also | 483 | /// The registers retain their values during wakes from standby mode or system resets. They also |
| 484 | /// retain their value when Vdd is switched off as long as V_BAT is powered. | 484 | /// retain their value when Vdd is switched off as long as V_BAT is powered. |
| 485 | fn read_backup_register(rtc: &crate::pac::rtc::Rtc, register: usize) -> Option<u32>; | 485 | fn read_backup_register(rtc: crate::pac::rtc::Rtc, register: usize) -> Option<u32>; |
| 486 | 486 | ||
| 487 | /// Set content of the backup register. | 487 | /// Set content of the backup register. |
| 488 | /// | 488 | /// |
| 489 | /// The registers retain their values during wakes from standby mode or system resets. They also | 489 | /// The registers retain their values during wakes from standby mode or system resets. They also |
| 490 | /// retain their value when Vdd is switched off as long as V_BAT is powered. | 490 | /// retain their value when Vdd is switched off as long as V_BAT is powered. |
| 491 | fn write_backup_register(rtc: &crate::pac::rtc::Rtc, register: usize, value: u32); | 491 | fn write_backup_register(rtc: crate::pac::rtc::Rtc, register: usize, value: u32); |
| 492 | 492 | ||
| 493 | // fn apply_config(&mut self, rtc_config: RtcConfig); | 493 | // fn apply_config(&mut self, rtc_config: RtcConfig); |
| 494 | } | 494 | } |
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index 92f9de846..cdc1cb299 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs | |||
| @@ -95,7 +95,7 @@ impl super::Rtc { | |||
| 95 | 95 | ||
| 96 | pub(super) fn write<F, R>(&self, init_mode: bool, f: F) -> R | 96 | pub(super) fn write<F, R>(&self, init_mode: bool, f: F) -> R |
| 97 | where | 97 | where |
| 98 | F: FnOnce(&crate::pac::rtc::Rtc) -> R, | 98 | F: FnOnce(crate::pac::rtc::Rtc) -> R, |
| 99 | { | 99 | { |
| 100 | let r = RTC::regs(); | 100 | let r = RTC::regs(); |
| 101 | // Disable write protection. | 101 | // Disable write protection. |
| @@ -112,7 +112,7 @@ impl super::Rtc { | |||
| 112 | while !r.isr().read().initf() {} | 112 | while !r.isr().read().initf() {} |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | let result = f(&r); | 115 | let result = f(r); |
| 116 | 116 | ||
| 117 | if init_mode { | 117 | if init_mode { |
| 118 | r.isr().modify(|w| w.set_init(false)); // Exits init mode | 118 | r.isr().modify(|w| w.set_init(false)); // Exits init mode |
| @@ -140,7 +140,7 @@ impl SealedInstance for crate::peripherals::RTC { | |||
| 140 | #[cfg(all(feature = "low-power", stm32l0))] | 140 | #[cfg(all(feature = "low-power", stm32l0))] |
| 141 | type WakeupInterrupt = crate::interrupt::typelevel::RTC; | 141 | type WakeupInterrupt = crate::interrupt::typelevel::RTC; |
| 142 | 142 | ||
| 143 | fn read_backup_register(rtc: &Rtc, register: usize) -> Option<u32> { | 143 | fn read_backup_register(rtc: Rtc, register: usize) -> Option<u32> { |
| 144 | if register < Self::BACKUP_REGISTER_COUNT { | 144 | if register < Self::BACKUP_REGISTER_COUNT { |
| 145 | Some(rtc.bkpr(register).read().bkp()) | 145 | Some(rtc.bkpr(register).read().bkp()) |
| 146 | } else { | 146 | } else { |
| @@ -148,7 +148,7 @@ impl SealedInstance for crate::peripherals::RTC { | |||
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | fn write_backup_register(rtc: &Rtc, register: usize, value: u32) { | 151 | fn write_backup_register(rtc: Rtc, register: usize, value: u32) { |
| 152 | if register < Self::BACKUP_REGISTER_COUNT { | 152 | if register < Self::BACKUP_REGISTER_COUNT { |
| 153 | rtc.bkpr(register).write(|w| w.set_bkp(value)); | 153 | rtc.bkpr(register).write(|w| w.set_bkp(value)); |
| 154 | } | 154 | } |
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index e51e09e7c..02fd5272e 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs | |||
| @@ -97,7 +97,7 @@ impl super::Rtc { | |||
| 97 | 97 | ||
| 98 | pub(super) fn write<F, R>(&self, init_mode: bool, f: F) -> R | 98 | pub(super) fn write<F, R>(&self, init_mode: bool, f: F) -> R |
| 99 | where | 99 | where |
| 100 | F: FnOnce(&crate::pac::rtc::Rtc) -> R, | 100 | F: FnOnce(crate::pac::rtc::Rtc) -> R, |
| 101 | { | 101 | { |
| 102 | let r = RTC::regs(); | 102 | let r = RTC::regs(); |
| 103 | // Disable write protection. | 103 | // Disable write protection. |
| @@ -112,7 +112,7 @@ impl super::Rtc { | |||
| 112 | while !r.icsr().read().initf() {} | 112 | while !r.icsr().read().initf() {} |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | let result = f(&r); | 115 | let result = f(r); |
| 116 | 116 | ||
| 117 | if init_mode { | 117 | if init_mode { |
| 118 | r.icsr().modify(|w| w.set_init(false)); // Exits init mode | 118 | r.icsr().modify(|w| w.set_init(false)); // Exits init mode |
| @@ -143,7 +143,7 @@ impl SealedInstance for crate::peripherals::RTC { | |||
| 143 | } | 143 | } |
| 144 | ); | 144 | ); |
| 145 | 145 | ||
| 146 | fn read_backup_register(_rtc: &Rtc, register: usize) -> Option<u32> { | 146 | fn read_backup_register(_rtc: Rtc, register: usize) -> Option<u32> { |
| 147 | #[allow(clippy::if_same_then_else)] | 147 | #[allow(clippy::if_same_then_else)] |
| 148 | if register < Self::BACKUP_REGISTER_COUNT { | 148 | if register < Self::BACKUP_REGISTER_COUNT { |
| 149 | //Some(rtc.bkpr()[register].read().bits()) | 149 | //Some(rtc.bkpr()[register].read().bits()) |
| @@ -153,7 +153,7 @@ impl SealedInstance for crate::peripherals::RTC { | |||
| 153 | } | 153 | } |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | fn write_backup_register(_rtc: &Rtc, register: usize, _value: u32) { | 156 | fn write_backup_register(_rtc: Rtc, register: usize, _value: u32) { |
| 157 | if register < Self::BACKUP_REGISTER_COUNT { | 157 | if register < Self::BACKUP_REGISTER_COUNT { |
| 158 | // RTC3 backup registers come from the TAMP peripheral, not RTC. Not() even in the L412 PAC | 158 | // RTC3 backup registers come from the TAMP peripheral, not RTC. Not() even in the L412 PAC |
| 159 | //self.rtc.bkpr()[register].write(|w| w.bits(value)) | 159 | //self.rtc.bkpr()[register].write(|w| w.bits(value)) |
