stm32-rs / stm32f4xx-hal

A Rust embedded-hal HAL for all MCUs in the STM32 F4 family
BSD Zero Clause License
552 stars 210 forks source link

I2S master clock not working in transmit mode #685

Open JosefUtbult opened 1 year ago

JosefUtbult commented 1 year ago

Hello.

I've been trying to get an I2S transmit stream to work. I've been using the following configuration from the i2s-audio-out example.

let i2s_transmit = I2s::new(codec.spi2, i2s_transmit_pins, codec.clocks);

// Setup Master device for configurations codec
let i2s_transmit_config = I2sDriverConfig::new_master()
    .receive()
    .standard(Philips)
    .data_format(DataFormat::Data24Channel32)
    .master_clock(true)
    .request_frequency(48_000);

let mut i2s_transmit_driver = I2sDriver::new(i2s_transmit, i2s_transmit_config);
defmt::info!("Actual sample rate is {}", i2s_transmit_driver.sample_rate());

i2s_transmit_driver.enable();

Which generates a functioning master clock output on pin C6. The problem though is that this master clock doesn't function when I'm changing it to transmit mode.

let i2s_transmit = I2s::new(codec.spi2, i2s_transmit_pins, codec.clocks);

// Setup Master device for configurations codec
let i2s_transmit_config = I2sDriverConfig::new_master()
    .transmit()
    .standard(Philips)
    .data_format(DataFormat::Data24Channel32)
    .master_clock(true)
    .request_frequency(48_000);

let mut i2s_transmit_driver = I2sDriver::new(i2s_transmit, i2s_transmit_config);
defmt::info!("Actual sample rate is {}", i2s_transmit_driver.sample_rate());

i2s_transmit_driver.enable();

Is this a problem with how the STM32 works, or is it something thats missing in the HAL? Thanks in advance

burrbull commented 1 year ago

cc @YruamaLairba

YruamaLairba commented 1 year ago

@JosefUtbult not sure, but i think clocks are generated only when data are send, So you don't see any clock signal until you send data.

JosefUtbult commented 1 year ago

Good call. The problem was in that I didn't send any data to start with. Now the problem lays in that the codec I'm using needs a master clock signal in order to be accessable over i2c for configuration. I solved it by configuring it as a i2s receive with a master clock, wrote the configuration over i2c and then reconfigured it to a i2s transmit. Thanks for the help

YruamaLairba commented 1 year ago

@JosefUtbult What codec do you use ? Are you sure to not confuse I2s Master clock with I2c Master clock ?