diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /tests/stm32/src/bin/adc.rs | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'tests/stm32/src/bin/adc.rs')
| -rw-r--r-- | tests/stm32/src/bin/adc.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/adc.rs b/tests/stm32/src/bin/adc.rs new file mode 100644 index 000000000..6cedc6498 --- /dev/null +++ b/tests/stm32/src/bin/adc.rs | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | // required-features: dac | ||
| 5 | |||
| 6 | #[path = "../common.rs"] | ||
| 7 | mod common; | ||
| 8 | |||
| 9 | use common::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_stm32::adc::{Adc, SampleTime}; | ||
| 12 | use embassy_time::Timer; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | |||
| 15 | #[embassy_executor::main] | ||
| 16 | async fn main(_spawner: Spawner) { | ||
| 17 | // Initialize the board and obtain a Peripherals instance | ||
| 18 | let p: embassy_stm32::Peripherals = init(); | ||
| 19 | |||
| 20 | let adc = peri!(p, ADC); | ||
| 21 | let mut adc_pin = peri!(p, DAC_PIN); | ||
| 22 | |||
| 23 | let mut adc = Adc::new_adc4(adc); | ||
| 24 | |||
| 25 | // Now wait a little to obtain a stable value | ||
| 26 | Timer::after_millis(30).await; | ||
| 27 | let _ = adc.blocking_read(&mut adc_pin, SampleTime::from_bits(0)); | ||
| 28 | |||
| 29 | for _ in 0..=255 { | ||
| 30 | // Now wait a little to obtain a stable value | ||
| 31 | Timer::after_millis(30).await; | ||
| 32 | |||
| 33 | // Need to steal the peripherals here because PA4 is obviously in use already | ||
| 34 | let _ = adc.blocking_read(&mut adc_pin, SampleTime::from_bits(0)); | ||
| 35 | } | ||
| 36 | |||
| 37 | info!("Test OK"); | ||
| 38 | cortex_m::asm::bkpt(); | ||
| 39 | } | ||
