aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJakob <[email protected]>2025-11-07 15:49:15 +0100
committerJakob <[email protected]>2025-11-07 15:49:15 +0100
commitb67c2055a54341c4cdf366688e6ef5ad6d87c7d2 (patch)
tree307ead29fffe5a5191cf62eb24d88a61eb89f53e /examples
parent4832d175447e249028401264b224819b70a5157f (diff)
Rework how sequences ADC are specified. Update documentation in g4. Carefully chose which methods to expose publicly
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32g4/.cargo/config.toml20
-rw-r--r--examples/stm32g4/Cargo.toml2
-rw-r--r--examples/stm32g4/src/bin/adc_injected_and_regular.rs17
3 files changed, 26 insertions, 13 deletions
diff --git a/examples/stm32g4/.cargo/config.toml b/examples/stm32g4/.cargo/config.toml
index de3e5718e..52b5a7bc8 100644
--- a/examples/stm32g4/.cargo/config.toml
+++ b/examples/stm32g4/.cargo/config.toml
@@ -1,9 +1,21 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32G071C8Rx with your chip as listed in `probe-rs chip list` 2# Change this runner as required for your MCU.
3runner = "probe-rs run --chip STM32G484VETx" 3runner = [
4 "probe-rs",
5 "run",
6 "--chip",
7 "STM32G431VBTx",
8 "--speed",
9 "5000",
10 "--preverify",
11 "--log-format",
12 "{t} [{L}] {s}",
13]
14
4 15
5[build] 16[build]
6target = "thumbv7em-none-eabi" 17target = "thumbv7em-none-eabihf"
7 18
8[env] 19[env]
9DEFMT_LOG = "trace" \ No newline at end of file 20DEFMT_LOG = "info"
21DEFMT_RTT_BUFFER_SIZE = "4096"
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml
index 8bbeb594c..9089ec0d5 100644
--- a/examples/stm32g4/Cargo.toml
+++ b/examples/stm32g4/Cargo.toml
@@ -7,7 +7,7 @@ publish = false
7 7
8[dependencies] 8[dependencies]
9# Change stm32g491re to your chip name, if necessary. 9# Change stm32g491re to your chip name, if necessary.
10embassy-stm32 = { path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } 10embassy-stm32 = { path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32g431vb", "memory-x", "unstable-pac", "exti"] }
11embassy-sync = { path = "../../embassy-sync", features = ["defmt"] } 11embassy-sync = { path = "../../embassy-sync", features = ["defmt"] }
12embassy-executor = { path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 12embassy-executor = { path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
13embassy-time = { path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 13embassy-time = { path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
diff --git a/examples/stm32g4/src/bin/adc_injected_and_regular.rs b/examples/stm32g4/src/bin/adc_injected_and_regular.rs
index d0c577b4b..c929ca3bf 100644
--- a/examples/stm32g4/src/bin/adc_injected_and_regular.rs
+++ b/examples/stm32g4/src/bin/adc_injected_and_regular.rs
@@ -18,9 +18,9 @@ use embassy_stm32::timer::complementary_pwm::{ComplementaryPwm, Mms2};
18use embassy_stm32::timer::low_level::CountingMode; 18use embassy_stm32::timer::low_level::CountingMode;
19use embassy_stm32::{Config, interrupt}; 19use embassy_stm32::{Config, interrupt};
20use embassy_sync::blocking_mutex::CriticalSectionMutex; 20use embassy_sync::blocking_mutex::CriticalSectionMutex;
21use {critical_section, defmt_rtt as _, panic_probe as _}; 21use {defmt_rtt as _, panic_probe as _};
22 22
23static ADC1_HANDLE: CriticalSectionMutex<RefCell<Option<InjectedAdc<ADC1>>>> = 23static ADC1_HANDLE: CriticalSectionMutex<RefCell<Option<InjectedAdc<ADC1, 1>>>> =
24 CriticalSectionMutex::new(RefCell::new(None)); 24 CriticalSectionMutex::new(RefCell::new(None));
25 25
26/// This example showcases how to use both regular ADC conversions with DMA and injected ADC 26/// This example showcases how to use both regular ADC conversions with DMA and injected ADC
@@ -78,17 +78,17 @@ async fn main(_spawner: embassy_executor::Spawner) {
78 // Configure regular conversions with DMA 78 // Configure regular conversions with DMA
79 let adc1 = Adc::new(p.ADC1); 79 let adc1 = Adc::new(p.ADC1);
80 80
81 let mut vrefint_channel = adc1.enable_vrefint().degrade_adc(); 81 let vrefint_channel = adc1.enable_vrefint().degrade_adc();
82 let mut pa0 = p.PC1.degrade_adc(); 82 let pa0 = p.PC1.degrade_adc();
83 let regular_sequence = [ 83 let regular_sequence = [
84 (&mut vrefint_channel, SampleTime::CYCLES247_5), 84 (vrefint_channel, SampleTime::CYCLES247_5),
85 (&mut pa0, SampleTime::CYCLES247_5), 85 (pa0, SampleTime::CYCLES247_5),
86 ] 86 ]
87 .into_iter(); 87 .into_iter();
88 88
89 // Configurations of Injected ADC measurements 89 // Configurations of Injected ADC measurements
90 let mut pa2 = p.PA2.degrade_adc(); 90 let pa2 = p.PA2.degrade_adc();
91 let injected_sequence = [(&mut pa2, SampleTime::CYCLES247_5)].into_iter(); 91 let injected_sequence = [(pa2, SampleTime::CYCLES247_5)];
92 92
93 // Configure DMA for retrieving regular ADC measurements 93 // Configure DMA for retrieving regular ADC measurements
94 let dma1_ch1 = p.DMA1_CH1; 94 let dma1_ch1 = p.DMA1_CH1;
@@ -111,6 +111,7 @@ async fn main(_spawner: embassy_executor::Spawner) {
111 RegularConversionMode::Triggered(regular_trigger), 111 RegularConversionMode::Triggered(regular_trigger),
112 injected_sequence, 112 injected_sequence,
113 injected_trigger, 113 injected_trigger,
114 true,
114 ); 115 );
115 116
116 // Store ADC globally to allow access from ADC interrupt 117 // Store ADC globally to allow access from ADC interrupt