Merge pull request #3716 from elagil/fix_stm32f4_i2s_clocks

Fix STM32F4 I2S clock calculations
This commit is contained in:
Dario Nieuwenhuis 2025-01-07 22:06:20 +01:00 committed by GitHub
commit 90cb610ef7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View File

@ -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)]

View File

@ -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);