diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-01-07 22:06:20 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-01-07 22:06:20 +0100 |
| commit | 90cb610ef72d45526a3702c0667f2f38b096077b (patch) | |
| tree | 3af2fea7e1b3b53e417ce0cc03ba562120b04252 | |
| parent | 7c3099b9e2273b47eea397f294444d838045df78 (diff) | |
| parent | d672dc8626003002869c2d131589fafce6d07059 (diff) | |
Merge pull request #3716 from elagil/fix_stm32f4_i2s_clocks
Fix STM32F4 I2S clock calculations
| -rw-r--r-- | embassy-stm32/build.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/i2s.rs | 9 |
2 files changed, 14 insertions, 5 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 09f940d29..30c525521 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -714,6 +714,16 @@ fn main() { | |||
| 714 | // Generate RCC | 714 | // Generate RCC |
| 715 | clock_gen.clock_names.insert("sys".to_string()); | 715 | clock_gen.clock_names.insert("sys".to_string()); |
| 716 | clock_gen.clock_names.insert("rtc".to_string()); | 716 | clock_gen.clock_names.insert("rtc".to_string()); |
| 717 | |||
| 718 | // STM32F4 SPI in I2S mode receives a clock input from the dedicated I2S PLL. | ||
| 719 | // For this, there is an additional clock MUX, which is not present in other | ||
| 720 | // peripherals and does not fit the current RCC structure of stm32-data. | ||
| 721 | if chip_name.starts_with("stm32f4") && !chip_name.starts_with("stm32f410") { | ||
| 722 | clock_gen.clock_names.insert("plli2s1_p".to_string()); | ||
| 723 | clock_gen.clock_names.insert("plli2s1_q".to_string()); | ||
| 724 | clock_gen.clock_names.insert("plli2s1_r".to_string()); | ||
| 725 | } | ||
| 726 | |||
| 717 | let clock_idents: Vec<_> = clock_gen.clock_names.iter().map(|n| format_ident!("{}", n)).collect(); | 727 | let clock_idents: Vec<_> = clock_gen.clock_names.iter().map(|n| format_ident!("{}", n)).collect(); |
| 718 | g.extend(quote! { | 728 | g.extend(quote! { |
| 719 | #[derive(Clone, Copy, Debug)] | 729 | #[derive(Clone, Copy, Debug)] |
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index 79d6279f6..ce166d718 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs | |||
| @@ -458,7 +458,7 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 458 | 458 | ||
| 459 | /// Write data directly to the raw I2S ringbuffer. | 459 | /// Write data directly to the raw I2S ringbuffer. |
| 460 | /// This can be used to fill the buffer before starting the DMA transfer. | 460 | /// This can be used to fill the buffer before starting the DMA transfer. |
| 461 | pub async fn write_immediate(&mut self, data: &mut [W]) -> Result<(usize, usize), Error> { | 461 | pub async fn write_immediate(&mut self, data: &[W]) -> Result<(usize, usize), Error> { |
| 462 | match &mut self.tx_ring_buffer { | 462 | match &mut self.tx_ring_buffer { |
| 463 | Some(ring) => Ok(ring.write_immediate(data)?), | 463 | Some(ring) => Ok(ring.write_immediate(data)?), |
| 464 | _ => return Err(Error::NotATransmitter), | 464 | _ => return Err(Error::NotATransmitter), |
| @@ -491,10 +491,9 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 491 | 491 | ||
| 492 | let regs = T::info().regs; | 492 | let regs = T::info().regs; |
| 493 | 493 | ||
| 494 | // TODO move i2s to the new mux infra. | 494 | #[cfg(all(rcc_f4, not(stm32f410)))] |
| 495 | //#[cfg(all(rcc_f4, not(stm32f410)))] | 495 | let pclk = unsafe { crate::rcc::get_freqs() }.plli2s1_r.to_hertz().unwrap(); |
| 496 | //let pclk = unsafe { get_freqs() }.plli2s1_q.unwrap(); | 496 | #[cfg(not(all(rcc_f4, not(stm32f410))))] |
| 497 | //#[cfg(stm32f410)] | ||
| 498 | let pclk = T::frequency(); | 497 | let pclk = T::frequency(); |
| 499 | 498 | ||
| 500 | let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format); | 499 | let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format); |
