Skip to content

Commit c3a2ea8

Browse files
authored
Merge branch 'main' into time
2 parents 4a91932 + a0e92cd commit c3a2ea8

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

embassy-stm32/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased - ReleaseDate
99

1010
- chore: cleanup low-power add time
11+
- fix: Allow setting SAI peripheral `frame_length` to `256`
1112
- fix: flash erase on dual-bank STM32Gxxx
1213
- feat: Add support for STM32N657X0
1314
- feat: timer: Add 32-bit timer support to SimplePwm waveform_up method following waveform pattern ([#4717](https://github.com/embassy-rs/embassy/pull/4717))
@@ -59,6 +60,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5960
- adc: reogranize and cleanup somewhat. require sample_time to be passed on conversion
6061
- fix: stm32/i2c v2 slave: prevent misaligned reads, error false positives, and incorrect counts of bytes read/written
6162
- feat: add flash support for c0 family ([#4874](https://github.com/embassy-rs/embassy/pull/4874))
63+
- fix: fixing channel numbers on vbat and vddcore for adc on adc
64+
- adc: adding disable to vbat
6265

6366
## 0.4.0 - 2025-08-26
6467

embassy-stm32/src/adc/g4.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(stm32g4)]
2+
use pac::adc::regs::Difsel as DifselReg;
13
#[allow(unused)]
24
#[cfg(stm32h7)]
35
use pac::adc::vals::{Adcaldif, Difsel, Exten};
@@ -179,6 +181,9 @@ impl<T: Instance> super::SealedAnyInstance for T {
179181
w.set_l(sequence.len() as u8 - 1);
180182
});
181183

184+
#[cfg(stm32g4)]
185+
let mut difsel = DifselReg::default();
186+
182187
// Configure channels and ranks
183188
for (_i, ((ch, is_differential), sample_time)) in sequence.enumerate() {
184189
let sample_time = sample_time.into();
@@ -214,22 +219,25 @@ impl<T: Instance> super::SealedAnyInstance for T {
214219

215220
#[cfg(stm32g4)]
216221
{
217-
T::regs().cr().modify(|w| w.set_aden(false)); // disable adc
218-
219-
T::regs().difsel().modify(|w| {
220-
w.set_difsel(
222+
if ch < 18 {
223+
difsel.set_difsel(
221224
ch.into(),
222225
if is_differential {
223226
Difsel::DIFFERENTIAL
224227
} else {
225228
Difsel::SINGLE_ENDED
226229
},
227230
);
228-
});
229-
230-
T::regs().cr().modify(|w| w.set_aden(true)); // enable adc
231+
}
231232
}
232233
}
234+
235+
#[cfg(stm32g4)]
236+
{
237+
T::regs().cr().modify(|w| w.set_aden(false));
238+
T::regs().difsel().write_value(difsel);
239+
T::enable();
240+
}
233241
}
234242
}
235243

@@ -412,7 +420,6 @@ impl<'d, T: Instance + AnyInstance> Adc<'d, T> {
412420
NR_INJECTED_RANKS
413421
);
414422

415-
T::stop();
416423
T::enable();
417424

418425
T::regs().jsqr().modify(|w| w.set_jl(N as u8 - 1));

embassy-stm32/src/adc/v3.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<T: Instance> super::SealedSpecialConverter<super::Vbat> for T {
6565
}
6666
#[cfg(any(adc_h5, adc_h7rs))]
6767
impl<T: Instance> super::SealedSpecialConverter<super::Vbat> for T {
68-
const CHANNEL: u8 = 2;
68+
const CHANNEL: u8 = 16;
6969
}
7070
#[cfg(adc_u0)]
7171
impl<T: Instance> super::SealedSpecialConverter<super::Vbat> for T {
@@ -82,7 +82,7 @@ cfg_if! {
8282
impl<T: Instance> super::AdcChannel<T> for VddCore {}
8383
impl<T: Instance> super::SealedAdcChannel<T> for VddCore {
8484
fn channel(&self) -> u8 {
85-
6
85+
17
8686
}
8787
}
8888
}
@@ -575,6 +575,24 @@ impl<'d, T: Instance> Adc<'d, T> {
575575
Vbat {}
576576
}
577577

578+
pub fn disable_vbat(&self) {
579+
cfg_if! {
580+
if #[cfg(any(adc_g0, adc_u0))] {
581+
T::regs().ccr().modify(|reg| {
582+
reg.set_vbaten(false);
583+
});
584+
} else if #[cfg(any(adc_h5, adc_h7rs))] {
585+
T::common_regs().ccr().modify(|reg| {
586+
reg.set_vbaten(false);
587+
});
588+
} else {
589+
T::common_regs().ccr().modify(|reg| {
590+
reg.set_ch18sel(false);
591+
});
592+
}
593+
}
594+
}
595+
578596
/*
579597
/// Convert a raw sample from the `Temperature` to deg C
580598
pub fn to_degrees_centigrade(sample: u16) -> f32 {

embassy-stm32/src/sai/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub struct Config {
391391
pub frame_sync_polarity: FrameSyncPolarity,
392392
pub frame_sync_active_level_length: word::U7,
393393
pub frame_sync_definition: FrameSyncDefinition,
394-
pub frame_length: u8,
394+
pub frame_length: u16,
395395
pub clock_strobe: ClockStrobe,
396396
pub output_drive: OutputDrive,
397397
pub master_clock_divider: Option<MasterClockDivider>,
@@ -696,7 +696,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> {
696696
w.set_fspol(config.frame_sync_polarity.fspol());
697697
w.set_fsdef(config.frame_sync_definition.fsdef());
698698
w.set_fsall(config.frame_sync_active_level_length.0 as u8 - 1);
699-
w.set_frl(config.frame_length - 1);
699+
w.set_frl((config.frame_length - 1).try_into().unwrap());
700700
});
701701

702702
ch.slotr().modify(|w| {

embassy-stm32/src/timer/simple_pwm.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
309309
/// Generate a sequence of PWM waveform
310310
///
311311
/// Note:
312-
/// you will need to provide corresponding TIMx_UP DMA channel to use this method.
312+
/// You will need to provide corresponding `TIMx_UP` DMA channel to use this method.
313+
/// Also be aware that embassy timers use one of timers internally. It is possible to
314+
/// switch this timer by using `time-driver-timX` feature.
313315
pub async fn waveform_up(&mut self, dma: Peri<'_, impl super::UpDma<T>>, channel: Channel, duty: &[u16]) {
314316
#[allow(clippy::let_unit_value)] // eg. stm32f334
315317
let req = dma.request();
@@ -397,18 +399,23 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
397399
///
398400
/// For example, if using channels 1 through 4, a buffer of 4 update steps might look like:
399401
///
402+
/// ```rust,ignore
400403
/// let dma_buf: [u16; 16] = [
401404
/// ch1_duty_1, ch2_duty_1, ch3_duty_1, ch4_duty_1, // update 1
402405
/// ch1_duty_2, ch2_duty_2, ch3_duty_2, ch4_duty_2, // update 2
403406
/// ch1_duty_3, ch2_duty_3, ch3_duty_3, ch4_duty_3, // update 3
404407
/// ch1_duty_4, ch2_duty_4, ch3_duty_4, ch4_duty_4, // update 4
405408
/// ];
409+
/// ```
406410
///
407-
/// Each group of N values (where N = number of channels) is transferred on one update event,
411+
/// Each group of `N` values (where `N` is number of channels) is transferred on one update event,
408412
/// updating the duty cycles of all selected channels simultaneously.
409413
///
410414
/// Note:
411-
/// you will need to provide corresponding TIMx_UP DMA channel to use this method.
415+
/// You will need to provide corresponding `TIMx_UP` DMA channel to use this method.
416+
/// Also be aware that embassy timers use one of timers internally. It is possible to
417+
/// switch this timer by using `time-driver-timX` feature.
418+
///
412419
pub async fn waveform_up_multi_channel(
413420
&mut self,
414421
dma: Peri<'_, impl super::UpDma<T>>,

examples/stm32h723/src/bin/spdifrx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn new_sai_transmitter<'d>(
167167
sai_config.slot_count = hal::sai::word::U4(CHANNEL_COUNT as u8);
168168
sai_config.slot_enable = 0xFFFF; // All slots
169169
sai_config.data_size = sai::DataSize::Data32;
170-
sai_config.frame_length = (CHANNEL_COUNT * 32) as u8;
170+
sai_config.frame_length = (CHANNEL_COUNT * 32) as u16;
171171
sai_config.master_clock_divider = None;
172172

173173
let (sub_block_tx, _) = hal::sai::split_subblocks(sai);

0 commit comments

Comments
 (0)