From c05431a51cb63fc00d710097430ec98f8f9af905 Mon Sep 17 00:00:00 2001 From: Rob Meades Date: Mon, 12 Feb 2018 16:25:57 +0000 Subject: [PATCH] Replace the calls to wait_us() in i2c_api.c for the STM platforms with a microsecond-ticker-based wait (hence becoming RTOSless and all non-C++ code). This is required because the UBLOX_C030 family of boards, which use an STM32F437VG CPU, need to configure a voltage threshold via I2C for reliable operation. Such mbed target configuration can only be done in the HAL_MspInit() hook, which is called before either the RTOS or LIBC has been initialised. --- targets/TARGET_STM/i2c_api.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/targets/TARGET_STM/i2c_api.c b/targets/TARGET_STM/i2c_api.c index b757e3b005a..24a83a6ad7d 100644 --- a/targets/TARGET_STM/i2c_api.c +++ b/targets/TARGET_STM/i2c_api.c @@ -32,6 +32,7 @@ #include "mbed_assert.h" #include "i2c_api.h" #include "platform/mbed_wait_api.h" +#include "hal/us_ticker_api.h" #if DEVICE_I2C @@ -754,7 +755,8 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { timeout = BYTE_TIMEOUT_US * (length + 1); /* transfer started : wait completion or timeout */ while(!(obj_s->event & I2C_EVENT_ALL) && (--timeout != 0)) { - wait_us(1); + int start = us_ticker_read(); + while ((us_ticker_read() - start) < 1); } i2c_ev_err_disable(obj); @@ -805,7 +807,8 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { timeout = BYTE_TIMEOUT_US * (length + 1); /* transfer started : wait completion or timeout */ while(!(obj_s->event & I2C_EVENT_ALL) && (--timeout != 0)) { - wait_us(1); + int start = us_ticker_read(); + while ((us_ticker_read() - start) < 1); } i2c_ev_err_disable(obj); @@ -986,7 +989,8 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) { if(ret == HAL_OK) { timeout = BYTE_TIMEOUT_US * (length + 1); while(obj_s->pending_slave_rx_maxter_tx && (--timeout != 0)) { - wait_us(1); + int start = us_ticker_read(); + while ((us_ticker_read() - start) < 1); } if(timeout != 0) { @@ -1011,7 +1015,8 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) { if(ret == HAL_OK) { timeout = BYTE_TIMEOUT_US * (length + 1); while(obj_s->pending_slave_tx_master_rx && (--timeout != 0)) { - wait_us(1); + int start = us_ticker_read(); + while ((us_ticker_read() - start) < 1); } if(timeout != 0) {