-
Notifications
You must be signed in to change notification settings - Fork 3k
Replace wait_us() calls in ST I2C HAL driver with RTOS-less/pure-C waits #6069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…h 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.
Thanks @RobMeades for the fix /morph build |
Build : SUCCESSBuild number : 1123 Triggering tests/morph test |
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few questions about this lines
- us_ticker_read returns uint32_t - why using start as an int ?
- what would be the resulting type of (us_ticker_read() - start) and how to make sure that wrap-around case is well covered ? rather than < 1,maybe != 0 would be safer
- In any case, with current proposal, the start will happen any time between T0 and T0+1, so when ((us_ticker_read() - start) < 1) is true, we have not reached a 1µs time, but rather any time between 0 and 1µs, in random way, so that the result will probably be around 0,5µs in average. The actual measured timeout will be half the expected one. Most probably OK as we take margins in the timeout computation, nevertheless not what we expect to code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to use uint32_t
instead of int
, was just being lazy, though actually if they were both signed then at least the wrap-around case would return immediately rather than get stuck. But rather than dwelling here I'll comment on your other remark below.
@RobMeades @0xc0170 @jeromecoutant I've added questions on the code - I'm not sure that it does what we actually expect. |
@LMESTM: good point about switching to |
Test : SUCCESSBuild number : 930 |
@RobMeades |
Exporter Build : FAILUREBuild number : 800 |
fingers crossed ;-) |
The bugfix for C030 I2C was integrated, is this PR still relevant @RobMeades ? |
No longer required, #6117 is the right fix. |
Description
Replace the calls to
wait_us()
ini2c_api.c
for the STM platforms with a microsecond-ticker-based wait (hence becoming RTOS-less and all pure-C code). This is required because theUBLOX_C030
family of boards (which use an STM32F437VG MCU) need to configure a voltage threshold via I2C for reliable operation. Such Mbed target configuration can only be done in theHAL_MspInit()
hook, which is called before either the RTOS or LIBC have been initialised.Status
Tested on C030 platform, @ARMmbed/team-st-mcd to regression test on other ST platforms.
Related PRs
#5957, #5995, #6034
Steps to test or reproduce
Run
mbed test
and the testmbed_platform-critical_section
will now pass on aUBLOX_C030
platform.Test results attached (noting that the UDP test always fail on our network).
waitless_i2c_test_output.txt
CC @ARMmbed/team-ublox.