STMicroelectronics' implementation of an I2S driver, also including DMA support.
Dependents: temp X_NUCLEO_CCA01M1 X_NUCLEO_CCA01M1 X_NUCLEO_CCA02M1
Platform compatibility
This driver has been designed to support a wide range of the Nucleo F4 Family of platforms and MCUs, but not all members of this family support I2S
and/or some of the members might require slight modifications to the sources of this driver in order to make it work on those.
This driver has for now been tested only with the following platforms:
Diff: targets/TARGET_STM/stm_i2s_api.c
- Revision:
- 18:1ccbfe84f550
- Parent:
- 16:04e1abb4cca3
- Child:
- 19:ef6ef1795e30
--- a/targets/TARGET_STM/stm_i2s_api.c Thu Jan 26 10:37:27 2017 +0100 +++ b/targets/TARGET_STM/stm_i2s_api.c Fri Jan 27 08:25:10 2017 +0100 @@ -836,7 +836,7 @@ //printf("f = %d / (2 * %d * %f * %d) = %f\r\n", i2sclk, format_factor, magic_factor, mclk_factor, f); /* Returning the computed frequency. */ - return (uint32_t)f; + return (uint32_t)roundf(f); } static uint32_t i2s_compute_closest_frequency(i2s_t *dev_i2s, uint32_t target_freq) { @@ -888,9 +888,9 @@ /* Compute the I2S frequencies. */ uint32_t format_factor = (hi2s->Init.DataFormat == I2S_DATAFORMAT_16B ? 16 : 32); uint32_t mclk_factor = (hi2s->Init.MCLKOutput == I2S_MCLKOUTPUT_ENABLE ? (format_factor == 16 ? 8 : 4) : 1); - uint32_t f = (uint32_t)((float)i2sclk / (float)(2 * format_factor * ((2 * i2sdiv) + i2sodd) * mclk_factor)); + float f = ((float)i2sclk / (float)(2 * format_factor * ((2 * i2sdiv) + i2sodd) * mclk_factor)); - return f; + return (uint32_t)roundf(f); } /** Compute the real frequency of a given I2S objects. @@ -922,7 +922,7 @@ { /* Returning if the two real frequencies are already multiple one of the other. */ float division = (float)real_high_freq / (float)real_low_freq; - float rest = (division - floorf(division)); + float rest = (division - (uint32_t)division); MBED_ASSERT(rest >= 0); if (rest == 0) { return 0; @@ -932,7 +932,7 @@ other by a certain factor. */ uint32_t multiplier = ((rest >= 0.5) ? ((uint32_t)division + 1) : (uint32_t)division); float magic_factor = i2s_compute_magic_factor(i2s_t_l, (float)real_high_freq / (float)multiplier); - uint32_t magic_factor_floor = (uint32_t)floorf(magic_factor); + uint32_t magic_factor_floor = (uint32_t)magic_factor; if(real_high_freq > (*ptr_high_freq)) { if(magic_factor_floor <= 1) {