aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/src/bin/cordic.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/tests/stm32/src/bin/cordic.rs b/tests/stm32/src/bin/cordic.rs
index b580cc79b..cd2e9d6f7 100644
--- a/tests/stm32/src/bin/cordic.rs
+++ b/tests/stm32/src/bin/cordic.rs
@@ -4,13 +4,15 @@
4 4
5// Only test on STM32H563ZI, STM32U585AI and STM32U5a5JI. 5// Only test on STM32H563ZI, STM32U585AI and STM32U5a5JI.
6// STM32G491RE is not tested, since it memory.x has less memory size than it actually has, 6// STM32G491RE is not tested, since it memory.x has less memory size than it actually has,
7// and the test seems use much memory than memory.x suggest. 7// and the test seems use more memory than memory.x suggest.
8// see https://github.com/embassy-rs/stm32-data/issues/301#issuecomment-1925412561 8// see https://github.com/embassy-rs/stm32-data/issues/301#issuecomment-1925412561
9 9
10#![no_std] 10#![no_std]
11#![no_main] 11#![no_main]
12 12
13use defmt::*; 13#[path = "../common.rs"]
14mod common;
15use common::*;
14use embassy_executor::Spawner; 16use embassy_executor::Spawner;
15use embassy_stm32::{bind_interrupts, cordic, peripherals, rng}; 17use embassy_stm32::{bind_interrupts, cordic, peripherals, rng};
16use num_traits::Float; 18use num_traits::Float;
@@ -25,12 +27,12 @@ bind_interrupts!(struct Irqs {
25const ARG1_LENGTH: usize = 9; 27const ARG1_LENGTH: usize = 9;
26const ARG2_LENGTH: usize = 4; // this might not be the exact length of ARG2, since ARG2 need to be inside [0, 1] 28const ARG2_LENGTH: usize = 4; // this might not be the exact length of ARG2, since ARG2 need to be inside [0, 1]
27 29
28const INPUT_Q1_31_LENGHT: usize = ARG1_LENGTH + ARG2_LENGTH; 30const INPUT_Q1_31_LENGTH: usize = ARG1_LENGTH + ARG2_LENGTH;
29const INPUT_U8_LENGTH: usize = 4 * INPUT_Q1_31_LENGHT; 31const INPUT_U8_LENGTH: usize = 4 * INPUT_Q1_31_LENGTH;
30 32
31#[embassy_executor::main] 33#[embassy_executor::main]
32async fn main(_spawner: Spawner) { 34async fn main(_spawner: Spawner) {
33 let dp = embassy_stm32::init(Default::default()); 35 let dp = embassy_stm32::init(config());
34 36
35 // 37 //
36 // use RNG generate random Q1.31 value 38 // use RNG generate random Q1.31 value
@@ -41,12 +43,12 @@ async fn main(_spawner: Spawner) {
41 let mut rng = rng::Rng::new(dp.RNG, Irqs); 43 let mut rng = rng::Rng::new(dp.RNG, Irqs);
42 44
43 let mut input_buf_u8 = [0u8; INPUT_U8_LENGTH]; 45 let mut input_buf_u8 = [0u8; INPUT_U8_LENGTH];
44 unwrap!(rng.async_fill_bytes(&mut input_buf_u8).await); 46 defmt::unwrap!(rng.async_fill_bytes(&mut input_buf_u8).await);
45 47
46 // convert every [u8; 4] to a u32, for a Q1.31 value 48 // convert every [u8; 4] to a u32, for a Q1.31 value
47 let input_q1_31 = unsafe { core::mem::transmute::<[u8; INPUT_U8_LENGTH], [u32; INPUT_Q1_31_LENGHT]>(input_buf_u8) }; 49 let input_q1_31 = unsafe { core::mem::transmute::<[u8; INPUT_U8_LENGTH], [u32; INPUT_Q1_31_LENGTH]>(input_buf_u8) };
48 50
49 let mut input_f64_buf = [0f64; INPUT_Q1_31_LENGHT]; 51 let mut input_f64_buf = [0f64; INPUT_Q1_31_LENGTH];
50 52
51 let mut cordic_output_f64_buf = [0f64; ARG1_LENGTH * 2]; 53 let mut cordic_output_f64_buf = [0f64; ARG1_LENGTH * 2];
52 54
@@ -66,13 +68,13 @@ async fn main(_spawner: Spawner) {
66 } 68 }
67 } 69 }
68 70
69 // the actal value feed to CORDIC 71 // the actual value feed to CORDIC
70 let arg1_f64_ls = &input_f64_buf[..ARG1_LENGTH]; 72 let arg1_f64_ls = &input_f64_buf[..ARG1_LENGTH];
71 let arg2_f64_ls = &arg2_f64_buf[..arg2_f64_len]; 73 let arg2_f64_ls = &arg2_f64_buf[..arg2_f64_len];
72 74
73 let mut cordic = cordic::Cordic::new( 75 let mut cordic = cordic::Cordic::new(
74 dp.CORDIC, 76 dp.CORDIC,
75 unwrap!(cordic::Config::new( 77 defmt::unwrap!(cordic::Config::new(
76 cordic::Function::Sin, 78 cordic::Function::Sin,
77 Default::default(), 79 Default::default(),
78 Default::default(), 80 Default::default(),
@@ -138,9 +140,9 @@ async fn main(_spawner: Spawner) {
138 } 140 }
139 } 141 }
140 142
141 // This comparsion is just for fun. Since it not a equal compare: 143 // This comparison is just for fun. Since it not a equal compare:
142 // software use 64-bit floating point, but CORDIC use 32-bit fixed point. 144 // software use 64-bit floating point, but CORDIC use 32-bit fixed point.
143 trace!( 145 defmt::trace!(
144 "calculate count: {}, Cordic time: {} us, software time: {} us", 146 "calculate count: {}, Cordic time: {} us, software time: {} us",
145 ARG1_LENGTH, 147 ARG1_LENGTH,
146 (cordic_end_point - cordic_start_point).as_micros(), 148 (cordic_end_point - cordic_start_point).as_micros(),