Commit Graph
18 Commits
Author SHA1 Message Date
tthandClaude Opus 5.5 fca5ff3c71 Wire (nRF52): a timed-out STOP is a failure, and the TWIM is reset after a timeout
Build / build (feather_nrf52840_sense_tft) (push) Failing after 13s
Build / build (cluenrf52840) (push) Failing after 22s
Build / build (feather52840) (push) Failing after 23s
Build / build (itsybitsy52840) (push) Failing after 25s
Build / build (ledglasses_nrf52840) (push) Failing after 25s
Build / build (feather52832) (push) Failing after 25s
Build / build (feather52840sense) (push) Failing after 25s
Build / build (cplaynrf52840) (push) Failing after 26s
On top of #873, tested on a XIAO nRF52840 with SCL tied to GND:
- the STOP/SUSPEND waits broke out without setting timed_out, so an empty
  probe on a stuck bus returned 0, "device ACKed" (every RTC address of an
  autodiscovery scan looked present); requestFrom() alike;
- after a timeout the TWIM stayed wedged once the bus was released: every
  call timed out until a reboot. A disable/enable cycle recovers it.
Result: stuck bus -> error 4 after ~100 ms per call, no hang; bus released
-> NACK 2 / ACK 0 again in under 1 ms, without a reboot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 13:16:18 +01:00
strasharo 45188a647f Wire (nRF52): add timeout to endTransmission()/requestFrom() poll loops
endTransmission() and requestFrom() both spin on unbounded while(!EVENT)
loops waiting on the TWIM peripheral. Several of these loops - notably
the EVENTS_STOPPED wait - have no EVENTS_ERROR escape at all, so if the
hardware never raises the expected event (e.g. probing an I2C address
on a bus with nothing attached and no pull-ups), the call never
returns and the whole single-threaded firmware hangs forever.

Reported in #771 with the same root cause already identified in the
issue thread. Also affects boards that probe for an optional/absent
I2C device at boot before anything else initializes - e.g. MeshCore's
Xiao_nrf52 target, which runs an RTC autodiscovery scan in radio_init()
and hangs on every cold boot when no RTC is wired up (no serial, no
BLE - see meshcore-dev/MeshCore#2068).

Adds a bounded I2C_TWIM_TIMEOUT_MS (default 100ms, overridable) to
every wait loop in both functions. A timeout that occurs before the
hardware transaction actually completed is surfaced as a proper error
return (endTransmission: 4 "other error"; requestFrom: 0 bytes read)
rather than silently falling through to a success path - a timeout on
the address/data phase must not be reported as if a device ACKed.

Tested on a Seeed XIAO nRF52840 + Wio-SX1262 board that reliably hung
at boot (via MeshCore's RTC autodiscovery probe) after every power
cycle. With this patch the same probe now completes (with a timeout)
in well under a second per address instead of hanging indefinitely,
and the board boots and runs normally.
2026-12-02 12:22:38 +01:00
hathach c6140f12e1 clear STOPPED event when start transmission, which could be caused by missing ack from previous transaction 2021-11-24 19:05:41 +07:00
hathach 23f0b09605 add tinyusb header across libraries 2021-06-02 13:26:54 +07:00
hathach 132f11de33 rename I2C terminology 2020-08-27 12:18:23 +07:00
Trevor 4c593ed216 Revised Wire library to have I2C setPins
updated with hathach requested variable naming and spacing
2020-08-13 19:46:43 -06:00
Trevor 73fb5887f5 Added I2C pin configuration
To configure the I2C pins call Wire.setPins(SDA_Pin, SCL_pin) prior to Wire.begin()
2020-07-14 15:45:34 -06:00
Henry Gabryjelski 20b080f9a2 Control SysView by CFG_SYSVIEW
Of course, this commit ensures the following:

* Zero change to BSP defaults
* Zero change to compiled code
* Zero change to UI / menu options
2020-03-25 16:20:33 -07:00
hathach 873f5770a1 clean up
sysview enter/exit isr for wire
2020-01-13 17:15:50 +07:00
hathach 74b2463953 add second hardware i2c as Wire1 for cplayground bluefruit 2019-10-18 16:09:21 +07:00
hathach f1e9877408 change I2C to use NRF_TWIM0/SPIM0 instead of NRF_TWIM1/SPIM1 for simplicity 2019-10-16 22:47:00 +07:00
hathach 1064e73ac9 correct pin mapping 2018-11-24 00:27:01 +07:00
hathach f15508ad90 wire irq prio from 2 to 3 2018-11-19 12:06:01 +07:00
hathach bba2a74b23 adding nrf52840 port1 (pin > 32) support
- also remove ledToggle()
2018-11-07 12:57:49 +07:00
hathach 313705e15c add nrf52 series common macros NRF52_SERIES 2018-04-17 17:20:22 +07:00
hathach 38047231b1 Fix I2C lock-up when endTransmission() is called with empty txBuffer
close #121
2018-02-27 20:05:17 +07:00
hathach 366416f8ac merge changes with core repo sandeepmistry/arduino-nRF5 0.3.0 2017-03-08 03:19:53 +07:00
hathach 6151838f8f adding file from sandeepmistry/arduino-nRF5 2016-11-22 01:08:21 +07:00