Skip to content

Commit 29b32b8

Browse files
committed
STM32 I2C - 1MHZ frequency is allowed
So make the assert to cover all possible values Also assert applies only for I2C_IP_VERSION_V2. Also in case of I2C_IP_VERSION_V1, the HAL makes the proper checks and can dynamically scale the frequency in case of intermediate value.
1 parent 0505a52 commit 29b32b8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ void i2c_frequency(i2c_t *obj, int hz)
296296
struct i2c_s *obj_s = I2C_S(obj);
297297
I2C_HandleTypeDef *handle = &(obj_s->handle);
298298

299-
MBED_ASSERT((hz > 0) && (hz <= 400000));
300-
301299
// wait before init
302300
timeout = BYTE_TIMEOUT;
303301
while ((__HAL_I2C_GET_FLAG(handle, I2C_FLAG_BUSY)) && (--timeout != 0));
@@ -307,6 +305,8 @@ void i2c_frequency(i2c_t *obj, int hz)
307305
handle->Init.DutyCycle = I2C_DUTYCYCLE_2;
308306
#endif
309307
#ifdef I2C_IP_VERSION_V2
308+
/* Only predefined timing for below frequencies are supported */
309+
MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000));
310310
handle->Init.Timing = get_i2c_timing(hz);
311311

312312
// Enable the Fast Mode Plus capability

0 commit comments

Comments
 (0)