Skip to content
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

i2c timeout error #88

Open
sylque opened this issue Mar 21, 2024 · 12 comments
Open

i2c timeout error #88

sylque opened this issue Mar 21, 2024 · 12 comments

Comments

@sylque
Copy link

sylque commented Mar 21, 2024

On my two M5StickC-PLUS2, I get the following error:

[176344][W][common.cpp:1400] readBytes(): [LGFX] i2c read error : read timeout

It happens randomly.

It seems to happen only when using the IMU.

When it happens, my single (user) task hangs, but the BLE task remains active.

@sylque
Copy link
Author

sylque commented Mar 21, 2024

Maybe related to lovyan03/LovyanGFX#382?

@lovyan03
Copy link
Collaborator

Hello, @sylque
Thank you for your report.
Perhaps you are using M5.Imu from M5Unified?
M5Unified internally uses the communication capabilities of M5GFX to communicate with Imu.
I would like to know more about how to reproduce the problem and the situation.

@sylque
Copy link
Author

sylque commented Apr 8, 2024

Hi @lovyan03 ,
Sorry to be late on this.
Yes, I am using the M5.Imu from M5Unified on the M5StickC-PLUS2.
I will try to create a small program to reproduce the issue.
What I can tell you at this stage is that the more you solicitate the I2C bus, the faster the issue occurs.

@sylque
Copy link
Author

sylque commented Apr 10, 2024

@lovyan03 , please find here a program to reproduce the issue: https://github.com/sylque/i2c_bug

In order to compile it, you'll need to make a small change to your local M5Unified library, as explained in i2c_bug.cpp.

The program displays the elapsed seconds until it hangs, usually between 0 and 300 seconds.

Typical output (with CORE_DEBUG_LEVEL=3):

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 271414342, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
[    54][I][M5GFX.cpp:532] init_impl(): [M5GFX] [Autodetect] load from NVS : board:5
[    59][I][M5GFX.cpp:750] autodetect(): [M5GFX] [Autodetect] M5StickCPlus2
[   191][I][esp32-hal-i2c.c:75] i2cInit(): Initialising I2C Master: sda=21 scl=22 freq=100000
[   227][I][esp32-hal-i2c.c:75] i2cInit(): Initialising I2C Master: sda=21 scl=22 freq=100000
[  1025][I][BLEDevice.cpp:577] getAdvertising(): create advertising
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 [ 89918][W][common.cpp:1407] readBytes(): [LGFX] i2c read error : read timeout

As you will see, the program uses BLE. I could only reproduce the issue when using IMU+BLE.

@lovyan03
Copy link
Collaborator

@sylque
I apologize for taking so long to confirm.
As you pointed out, I was able to confirm the problem.
The cause was insufficient countermeasures in case an interrupt occurred during the M5GFX's I2C read processing.
I have reflected the changes to the develop branch. We apologize for the inconvenience, but please use this to check the operation.
Thank you for posting this issue.

@sylque
Copy link
Author

sylque commented Apr 23, 2024

The fix seems to work nicely on my side. Thank you @lovyan03 !

@sylque
Copy link
Author

sylque commented Apr 30, 2024

@lovyan03 , unfortunately the issue is still there. It's quite baffling because it appeared to have been resolved previously, but it has now resurfaced.

To reproduce the issue , I'm using https://github.com/sylque/i2c_bug with this modified platformio.ini:

...

[env:M5StickCPlus2]
...
lib_deps = 
    M5StickCPlus2
    https://github.com/m5stack/M5GFX.git#develop ;Required for fix #88
...

As far as I can see, your fix is indeed included in the build.

@alwint3r
Copy link

alwint3r commented May 16, 2024

Our team is facing a similar issue. After this line, he added the following code, which seems to recover the error.

i2c_context[i2c_port].unlock();

below this line:

https://github.com/m5stack/M5GFX/blob/0.1.15/src/lgfx/v1/platforms/esp32/common.cpp#L1409

          if (0 == getRxFifoCount(dev))
          {
            i2c_stop(i2c_port);
            ESP_LOGW("LGFX", "i2c read error : read timeout");
            res = cpp::fail(error_t::connection_lost);
            i2c_context[i2c_port].state = cpp::fail(error_t::connection_lost);
            i2c_context[i2c_port].unlock();
            return res;
          }

Anyone care to test this workaround?

lovyan03 added a commit that referenced this issue May 31, 2024
@lovyan03
Copy link
Collaborator

Hello, @sylque @alwint3r .
I apologize for keeping you waiting so long.

The previous fix was to solve the problem of errors occurring when an interrupt occurred during I2C communication, but there was another bug.

I have just made a new fix and updated the develop branch. This fix resolves the bug that prevented communication if an error occurred during I2C reading.

It is best if I2C communication does not cause errors, but we have now made it so that it can return to normal even if an error does occur.

Please try this version.

@sylque
Copy link
Author

sylque commented Jun 6, 2024

@alwint3r, @lovyan03, sorry for being late on this.

@lovyan03 I've just tested the latest dev branch and unfortunately the issue is still there, although less frequent. It seems to occur after 15 minutes on average, with the following error message:

[947351][W][common.cpp:1409] readBytes(): [LGFX] i2c read error : read timeout

@alwint3r, your fix seems to work. I've got it running for more than 4 hours without issue.

@alwint3r
Copy link

Thanks @lovyan03. Before updating the library version, my device stuck when the error occurred because we heavily used the I2C bus. I haven't observed any failure/error so far, perhaps I'm missing something.

@sylque interesting. The new version worked for me.

@sylque
Copy link
Author

sylque commented Sep 2, 2024

The issue is still there with the latest commit in the #develop branch:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 
146 147 148 149 150 [152595][W][common.cpp:1430] readBytes(): [LGFX] i2c read error : read timeout
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 [286662][W][common.cpp:1430] readBytes(): [LGFX] i2c read error : read timeout
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356  

(what has changed compared to 3 months ago, though, is that now the M5Unified library gracefully ignore the error instead of hanging)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants