diff options
| author | elagil <[email protected]> | 2025-01-03 22:57:31 +0100 |
|---|---|---|
| committer | elagil <[email protected]> | 2025-01-03 22:57:31 +0100 |
| commit | cf606a161f9bed59f912f3e521bc48a8cda11d6f (patch) | |
| tree | b1b75e7cb69f6d6ae1474d9dcf54c9ed7b5416ce | |
| parent | e68efc2d7cdea195aec112ecb61231e148a282c2 (diff) | |
fix: STM32F4 I2S clock calculations
| -rw-r--r-- | embassy-stm32/build.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/i2s.rs | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index e293cf965..a70524916 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -712,6 +712,16 @@ fn main() { | |||
| 712 | // Generate RCC | 712 | // Generate RCC |
| 713 | clock_gen.clock_names.insert("sys".to_string()); | 713 | clock_gen.clock_names.insert("sys".to_string()); |
| 714 | clock_gen.clock_names.insert("rtc".to_string()); | 714 | clock_gen.clock_names.insert("rtc".to_string()); |
| 715 | |||
| 716 | // STM32F4 SPI in I2S mode receives a clock input from the dedicated I2S PLL. | ||
| 717 | // For this, there is an additional clock MUX, which is not present in other | ||
| 718 | // peripherals and does not fit the current RCC structure of stm32-data. | ||
| 719 | if chip_name.starts_with("stm32f4") && !chip_name.starts_with("stm32f410") { | ||
| 720 | clock_gen.clock_names.insert("plli2s1_p".to_string()); | ||
| 721 | clock_gen.clock_names.insert("plli2s1_q".to_string()); | ||
| 722 | clock_gen.clock_names.insert("plli2s1_r".to_string()); | ||
| 723 | } | ||
| 724 | |||
| 715 | let clock_idents: Vec<_> = clock_gen.clock_names.iter().map(|n| format_ident!("{}", n)).collect(); | 725 | let clock_idents: Vec<_> = clock_gen.clock_names.iter().map(|n| format_ident!("{}", n)).collect(); |
| 716 | g.extend(quote! { | 726 | g.extend(quote! { |
| 717 | #[derive(Clone, Copy, Debug)] | 727 | #[derive(Clone, Copy, Debug)] |
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index 79d6279f6..1a7393ba4 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs | |||
| @@ -7,6 +7,7 @@ use stm32_metapac::spi::vals; | |||
| 7 | use crate::dma::{ringbuffer, ChannelAndRequest, ReadableRingBuffer, TransferOptions, WritableRingBuffer}; | 7 | use crate::dma::{ringbuffer, ChannelAndRequest, ReadableRingBuffer, TransferOptions, WritableRingBuffer}; |
| 8 | use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed}; | 8 | use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed}; |
| 9 | use crate::mode::Async; | 9 | use crate::mode::Async; |
| 10 | use crate::rcc::get_freqs; | ||
| 10 | use crate::spi::{Config as SpiConfig, RegsExt as _, *}; | 11 | use crate::spi::{Config as SpiConfig, RegsExt as _, *}; |
| 11 | use crate::time::Hertz; | 12 | use crate::time::Hertz; |
| 12 | use crate::{Peripheral, PeripheralRef}; | 13 | use crate::{Peripheral, PeripheralRef}; |
| @@ -491,10 +492,9 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 491 | 492 | ||
| 492 | let regs = T::info().regs; | 493 | let regs = T::info().regs; |
| 493 | 494 | ||
| 494 | // TODO move i2s to the new mux infra. | 495 | #[cfg(all(rcc_f4, not(stm32f410)))] |
| 495 | //#[cfg(all(rcc_f4, not(stm32f410)))] | 496 | let pclk = unsafe { get_freqs() }.plli2s1_r.to_hertz().unwrap(); |
| 496 | //let pclk = unsafe { get_freqs() }.plli2s1_q.unwrap(); | 497 | #[cfg(stm32f410)] |
| 497 | //#[cfg(stm32f410)] | ||
| 498 | let pclk = T::frequency(); | 498 | let pclk = T::frequency(); |
| 499 | 499 | ||
| 500 | let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format); | 500 | let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format); |
