i2c_read_timeout_us causing lockup #2311
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#2311
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've updated my gamepad library to utilize Pico SDK 2.1.0, and today 2.1.1, and both have a serious issue with I2C making it unusable. I have a loop communicating with a battery PMIC as well as an ESP32. With the new library functions that underly these (i2c_write_blocking_internal && i2c_read_blocking_internal), they are hogging way more CPU time than would be determined by the set timeout. I wrote a custom wrapper which re-implements the 1.5.1 I2C functions and the issues went away.
I see a similar issue dating back to 2023 and I'm hoping that there is a fix on the horizon, as this would severely impact anyone else trying to use 2.1.0 and 2.1.1 https://github.com/raspberrypi/pico-sdk/issues/1471
What hardware do we need to reproduce these issues?
@mitchellcairns I'd appreciate any advice you can offer on reproducing the problems you're seeing with the sdk.
I've looked at the changes since 1.5.1 and the only thing that looks interesting is the following code added to the "for (byte_ctr = 0; byte_ctr < ilen; ++byte_ctr)" loop in i2c_write_blocking_internal and i2c_read_blocking_internal
I can't really see how that could cause the problems you're seeing however.
I will try to see if there's a basic setup I can provide which would help to reproduce this issue
@peterharperuk I have been able to narrow down the issue further.
The issue is isolated to i2c_read_blocking_internal and not i2c_write_blocking_internal.
The clr_tx_abrt is only referenced within a condition where the TX_ABRT_BIT is set
github.com/raspberrypi/pico-sdk@ee68c78d0a/src/rp2_common/hardware_i2c/i2c.c (L303)Adding this line
abort = (bool) i2c->hw->clr_tx_abrt;outside of that if statement resolves the issue I'm having. Is it possible that the abort interrupt isn't firing under some condition?
Additionally, I noticed that the timeout_check is now reset for every byte that is being attempted. This basically changes the timeout_us to be timeout_us * transaction size (which doesn't seem intentional, or at least should be an option and not the default in my opinion)
In my context, I am writing data to an ESP32 in I2C slave mode using the RP2040. From what I understand, the ESP32 in I2C slave mode may never transmit a NAK packet (which is not normal behavior) but this should still not stop the i2c timeout from passing on as we would expect. For whatever reason, adding that original line back in causes this to work as intended.
My reading of the code is that this only happens when using i2c_read_timeout_per_char_us which ends up calling check_per_iteration_timeout_us. Other functions should call check_single_timeout_us which does not reset the timeout.
Thanks - that gives me something to think about!
Is there any updates on this front? I saw 2.2.0 drop but I did not see any notes on this.
I've done a bit more digging into this. It seems like, in the case of the ESP32 slave I2C driver, even if you are accepting, for example, 32 bytes, the final byte may be accepted, but NAK'd to the host. This leaves the RP2040 in a sort of fail state.
On the next I2C write to the ESP32, it only pushes one byte, then spins until the write timeout occurs.
If this code is called after the SDK write function as-is with the latest SDK version, this is cleared up.