STM32 I2S Driver Clock Configuration #77480
-
if (cfg->pclk_len > 1) {
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t)&cfg->pclken[1],
&freq_in) < 0) {
LOG_ERR("Failed call clock_control_get_rate(pclken[1])");
return -EIO;
}
}
/*
* The ratio between input clock (I2SxClk) and output
* clock on the pad (I2S_CK) is obtained using the
* following formula:
* (i2s_div * 2) + i2s_odd
*/
i2s_div = div_round_closest(freq_in, bit_clk_freq);
i2s_odd = (i2s_div & 0x1) ? 1 : 0;
i2s_div >>= 1; Hello, I am a bit confused by this code snippet in the For context I am trying to run the i2s output sample application on an STM32 Nucelo F401RE to verify a sine wave output. My overlay and clock configuration are here: 8c9c638 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
^^ @marwaiehm-st. Can you have a look ? |
Beta Was this translation helpful? Give feedback.
-
Hi @rriveramcrus , You are right, the code in the function i2s_ll_stm32.c handles only multiple clock sources. In the case of a single clock source, the freq_in remains 0. Therefore, we should handle both cases where pclk_len is greater than 1 and where it is not, ensuring that the freq_in variable is correctly set: static int i2s_stm32_set_clock(const struct device *dev,
uint32_t bit_clk_freq)
{
const struct i2s_stm32_cfg *cfg = dev->config;
uint32_t freq_in = 0U;
uint8_t i2s_div, i2s_odd;
if (cfg->pclk_len > 1) {
// Handle multiple clock sources
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t)&cfg->pclken[1],
&freq_in) < 0) {
LOG_ERR("Failed call clock_control_get_rate(pclken[1])");
return -EIO;
}
} else {
// Handle single clock source
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t)&cfg->pclken[0],
&freq_in) < 0) {
LOG_ERR("Failed call clock_control_get_rate(pclken[0])");
return -EIO;
}
} |
Beta Was this translation helpful? Give feedback.
-
Resolved in #77655 |
Beta Was this translation helpful? Give feedback.
-
Backport PR onto V3.7 is blocked by bot "Backport Issue Check / Backport Issue Check (pull_request_target)", which is requesting backport PRs to include a reference to an issue. PR refers to current discussion, but check is failing anyway. |
Beta Was this translation helpful? Give feedback.
Hi @rriveramcrus ,
You are right, the code in the function i2s_ll_stm32.c handles only multiple clock sources. In the case of a single clock source, the freq_in remains 0. Therefore, we should handle both cases where pclk_len is greater than 1 and where it is not, ensuring that the freq_in variable is correctly set: