aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-03-12 19:30:20 +0000
committerGitHub <[email protected]>2024-03-12 19:30:20 +0000
commit35f284ec22848d7085e00f377136fd66067ca756 (patch)
treefc86df7234ecca8ac8609b34cc907f5ab74f3cf0 /examples
parent9101b9eb012332888512982b943f6141adb15f06 (diff)
parentb1ba2729878a1553145f215dff40281c65b75983 (diff)
Merge pull request #2691 from caleb-garrett/cryp-dma
STM32 CRYP DMA
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f7/src/bin/cryp.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/examples/stm32f7/src/bin/cryp.rs b/examples/stm32f7/src/bin/cryp.rs
index 04927841a..235853cb9 100644
--- a/examples/stm32f7/src/bin/cryp.rs
+++ b/examples/stm32f7/src/bin/cryp.rs
@@ -6,11 +6,15 @@ use aes_gcm::aead::{AeadInPlace, KeyInit};
6use aes_gcm::Aes128Gcm; 6use aes_gcm::Aes128Gcm;
7use defmt::info; 7use defmt::info;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::cryp::*; 9use embassy_stm32::cryp::{self, *};
10use embassy_stm32::Config; 10use embassy_stm32::{bind_interrupts, peripherals, Config};
11use embassy_time::Instant; 11use embassy_time::Instant;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14bind_interrupts!(struct Irqs {
15 CRYP => cryp::InterruptHandler<peripherals::CRYP>;
16});
17
14#[embassy_executor::main] 18#[embassy_executor::main]
15async fn main(_spawner: Spawner) -> ! { 19async fn main(_spawner: Spawner) -> ! {
16 let config = Config::default(); 20 let config = Config::default();
@@ -19,7 +23,7 @@ async fn main(_spawner: Spawner) -> ! {
19 let payload: &[u8] = b"hello world"; 23 let payload: &[u8] = b"hello world";
20 let aad: &[u8] = b"additional data"; 24 let aad: &[u8] = b"additional data";
21 25
22 let hw_cryp = Cryp::new(p.CRYP); 26 let mut hw_cryp = Cryp::new(p.CRYP, p.DMA2_CH6, p.DMA2_CH5, Irqs);
23 let key: [u8; 16] = [0; 16]; 27 let key: [u8; 16] = [0; 16];
24 let mut ciphertext: [u8; 11] = [0; 11]; 28 let mut ciphertext: [u8; 11] = [0; 11];
25 let mut plaintext: [u8; 11] = [0; 11]; 29 let mut plaintext: [u8; 11] = [0; 11];
@@ -29,16 +33,18 @@ async fn main(_spawner: Spawner) -> ! {
29 33
30 // Encrypt in hardware using AES-GCM 128-bit 34 // Encrypt in hardware using AES-GCM 128-bit
31 let aes_gcm = AesGcm::new(&key, &iv); 35 let aes_gcm = AesGcm::new(&key, &iv);
32 let mut gcm_encrypt = hw_cryp.start(&aes_gcm, Direction::Encrypt); 36 let mut gcm_encrypt = hw_cryp.start(&aes_gcm, Direction::Encrypt).await;
33 hw_cryp.aad_blocking(&mut gcm_encrypt, aad, true); 37 hw_cryp.aad(&mut gcm_encrypt, aad, true).await;
34 hw_cryp.payload_blocking(&mut gcm_encrypt, payload, &mut ciphertext, true); 38 hw_cryp.payload(&mut gcm_encrypt, payload, &mut ciphertext, true).await;
35 let encrypt_tag = hw_cryp.finish_blocking(gcm_encrypt); 39 let encrypt_tag = hw_cryp.finish(gcm_encrypt).await;
36 40
37 // Decrypt in hardware using AES-GCM 128-bit 41 // Decrypt in hardware using AES-GCM 128-bit
38 let mut gcm_decrypt = hw_cryp.start(&aes_gcm, Direction::Decrypt); 42 let mut gcm_decrypt = hw_cryp.start(&aes_gcm, Direction::Decrypt).await;
39 hw_cryp.aad_blocking(&mut gcm_decrypt, aad, true); 43 hw_cryp.aad(&mut gcm_decrypt, aad, true).await;
40 hw_cryp.payload_blocking(&mut gcm_decrypt, &ciphertext, &mut plaintext, true); 44 hw_cryp
41 let decrypt_tag = hw_cryp.finish_blocking(gcm_decrypt); 45 .payload(&mut gcm_decrypt, &ciphertext, &mut plaintext, true)
46 .await;
47 let decrypt_tag = hw_cryp.finish(gcm_decrypt).await;
42 48
43 let hw_end_time = Instant::now(); 49 let hw_end_time = Instant::now();
44 let hw_execution_time = hw_end_time - hw_start_time; 50 let hw_execution_time = hw_end_time - hw_start_time;