From 2ac319649607e4818969a34dd21ea3d0dde7edac Mon Sep 17 00:00:00 2001 From: Laurent MEUNIER Date: Thu, 1 Dec 2016 14:47:44 +0100 Subject: [PATCH] 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. --- targets/TARGET_STM/i2c_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/i2c_api.c b/targets/TARGET_STM/i2c_api.c index 4de4f6cc97..2c2dbb5951 100644 --- a/targets/TARGET_STM/i2c_api.c +++ b/targets/TARGET_STM/i2c_api.c @@ -296,8 +296,6 @@ void i2c_frequency(i2c_t *obj, int hz) struct i2c_s *obj_s = I2C_S(obj); I2C_HandleTypeDef *handle = &(obj_s->handle); - MBED_ASSERT((hz > 0) && (hz <= 400000)); - // wait before init timeout = BYTE_TIMEOUT; while ((__HAL_I2C_GET_FLAG(handle, I2C_FLAG_BUSY)) && (--timeout != 0)); @@ -307,6 +305,8 @@ void i2c_frequency(i2c_t *obj, int hz) handle->Init.DutyCycle = I2C_DUTYCYCLE_2; #endif #ifdef I2C_IP_VERSION_V2 + /* Only predefined timing for below frequencies are supported */ + MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000)); handle->Init.Timing = get_i2c_timing(hz); // Enable the Fast Mode Plus capability