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() { // Generate RCC clock_gen.clock_names.insert("sys".to_string()); clock_gen.clock_names.insert("rtc".to_string()); + + // STM32F4 SPI in I2S mode receives a clock input from the dedicated I2S PLL. + // For this, there is an additional clock MUX, which is not present in other + // peripherals and does not fit the current RCC structure of stm32-data. + if chip_name.starts_with("stm32f4") && !chip_name.starts_with("stm32f410") { + clock_gen.clock_names.insert("plli2s1_p".to_string()); + clock_gen.clock_names.insert("plli2s1_q".to_string()); + clock_gen.clock_names.insert("plli2s1_r".to_string()); + } + let clock_idents: Vec<_> = clock_gen.clock_names.iter().map(|n| format_ident!("{}", n)).collect(); g.extend(quote! { #[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> { /// Write data directly to the raw I2S ringbuffer. /// This can be used to fill the buffer before starting the DMA transfer. - pub async fn write_immediate(&mut self, data: &mut [W]) -> Result<(usize, usize), Error> { + pub async fn write_immediate(&mut self, data: &[W]) -> Result<(usize, usize), Error> { match &mut self.tx_ring_buffer { Some(ring) => Ok(ring.write_immediate(data)?), _ => return Err(Error::NotATransmitter), @@ -491,10 +491,9 @@ impl<'d, W: Word> I2S<'d, W> { let regs = T::info().regs; - // TODO move i2s to the new mux infra. - //#[cfg(all(rcc_f4, not(stm32f410)))] - //let pclk = unsafe { get_freqs() }.plli2s1_q.unwrap(); - //#[cfg(stm32f410)] + #[cfg(all(rcc_f4, not(stm32f410)))] + let pclk = unsafe { crate::rcc::get_freqs() }.plli2s1_r.to_hertz().unwrap(); + #[cfg(not(all(rcc_f4, not(stm32f410))))] let pclk = T::frequency(); let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format);