pub struct AesWrapClk { /* private fields */ }
Expand description

Wrapper around Aes for safely disabling the peripheral clock.

Implementations§

source§

impl AesWrapClk

source

pub fn with_clk<F>(&mut self, rcc: &mut RCC, f: F) -> Result<(), Error>where F: FnOnce(&mut Aes) -> Result<(), Error>,

Run a function that accepts the AES driver as an argument, enabling the peripheral clock with enable_clock before calling the function, and disabling the peripheral clock with disable_clock after calling the function.

This is useful for saving power in applications that need to access the AES peripheral infrequently.

Power Savings

From DS13105 Rev 9:

  • Range 1: 2.50 μA/MHz
  • Range 2: 2.13 μA/MHz
  • LPRun and LPSleep: 1.80 μA/MHz
Example
use stm32wlxx_hal::{
    aes::{Aes, AesWrapClk},
    pac,
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

// safety:
// * no need to reset because the AES memory-mapped IO has not been accessed since power-on
// * the wrapper will handle enabling clocks
let mut aeswrap: AesWrapClk = unsafe { Aes::new_no_init(dp.AES) }.into();

const KEY: [u32; 4] = [0; 4];

let mut text: [u32; 4] = [0xf34481ec, 0x3cc627ba, 0xcd5dc3fb, 0x08f273e6];
aeswrap.with_clk(&mut dp.RCC, |aes| aes.encrypt_ecb_inplace(&KEY, &mut text))?;

Trait Implementations§

source§

impl Debug for AesWrapClk

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Aes> for AesWrapClk

source§

fn from(aes: Aes) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.