Skip to content

Wire: probe an address without data on the GPIOs; GRTC sleep TIMEOUT to 6 - #17

Merged
caveman99 merged 2 commits into
masterfrom
wire-probe-grtc-timeout
Nov 23, 2026
Merged

caveman99 merged 2 commits into
masterfrom
wire-probe-grtc-timeout

Conversation

@caveman99

@caveman99 caveman99 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Two fixes found while comparing against lolren/nrf54-arduino-core (d9699836, 2d7476a3, 256af4f4) and checked against the nRF54L15 datasheet.

Wire: address-only probe

TWIM DMA.TX.MAXCNT is defined for [1..0xFFFF] (datasheet). endTransmission() with nothing written, which is how I2C scanners probe (beginTransmission(addr); endTransmission(), also Meshtastic's sensor detection), started a zero-byte transfer and stopped it at once. That does not reliably put the address on the bus, and an idle TWIM does not raise STOPPED for a STOP task, so the result did not reflect the target.

With nothing to write, the address is now clocked out on the GPIOs at up to 100 kHz with TWIM disabled: START, address + write bit, ACK, STOP, with clock stretching honoured. It returns 0 on ACK, 2 on NACK and 4 for a busy or stuck bus. The pins are restored to the configuration begin() sets before TWIM is re-enabled. Transfers with data are unchanged.

GRTC sleep TIMEOUT

The datasheet requires TIMEOUT > WAKETIME + guard, with a guard of at least one LFCLK cycle (GRTC, SYSCOUNTER sleep mode). NRFX_GRTC_SLEEP_DEFAULT_CONFIG (TIMEOUT 5, WAKETIME 4), applied since #1, is one cycle short. TIMEOUT is now 6; WAKETIME and AUTOEN stay at the nrfx values.

Testing

Not run on hardware.

  • CI builds both changes for all five boards: tests/blink the GRTC change, tests/libraries (tests: build the bundled libraries in CI, and fix Wire on the nRF54L10/L05 DKs #16) Wire_nRF52.cpp, without warnings.
  • Wire, on a board with a known I2C device: a scan should report only that device's address (0), others NACK (2), and normal reads and writes to the device keep working.
  • GRTC: GRTC->TIMEOUT should read 6 after Bluefruit.begin(), to confirm the SoftDevice does not reprogram it.

Summary by CodeRabbit

  • Bug Fixes
    • Address-only I2C transmissions now report whether a device acknowledges, does not acknowledge, or the bus times out. I2C transfers containing data continue to use the existing hardware transfer path.
    • Adjusted the GRTC sleep timeout, which may slightly change wake timing on supported nRF54L devices.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The tick setup now sets the nRF54L sleep timeout to waketime plus two. Wire uses a bounded GPIO address probe for transmissions with no data. Nonempty transmissions continue through TWIM, with STOP or SUSPEND selected by stopBit.

Changes: nRF54L sleep timeout

Layer / File(s) Summary
Adjust sleep timeout
cores/nRF5/freertos/portable/CMSIS/nrf54l/port_cmsis_systick.c
The tick setup makes sleep_cfg mutable and sets its timeout to waketime + 2. The comment states that the default timeout of 5 is raised to satisfy the timeout requirement.

Wire address probing

Layer / File(s) Summary
Configure pins and probe address
libraries/Wire/Wire_nRF52.cpp
Shared helpers configure the open-drain pins, wait up to 25,000 microseconds for clock release, and probe an address through GPIO. The probe returns 0 for ACK, 2 for NACK, or 4 if the initial line checks or clock release fail. TwoWire::begin() uses the shared pin configuration.
Route empty transmissions through GPIO
libraries/Wire/Wire_nRF52.cpp
For an empty transmit buffer, endTransmission() disables TWIM, runs the GPIO probe, re-enables TWIM, and returns the probe status. For nonempty transfers, stopBit selects STOP or SUSPEND and the corresponding completion event.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant EndTransmission as TwoWire::endTransmission
  participant TWIM
  participant GPIO as GPIO pins
  participant Target as I2C target
  EndTransmission->>TWIM: Disable TWIM
  EndTransmission->>GPIO: Send address and write bit
  GPIO->>Target: Address probe
  Target-->>GPIO: ACK or NACK
  GPIO-->>EndTransmission: Probe status
  EndTransmission->>TWIM: Re-enable TWIM
Loading

Suggested reviewers: cvaldess

Merge Risk: Minimal · up to b4b35

This PR adds a GPIO-based address probe for empty I2C transmissions and raises the nRF54L sleep timeout from 5 to 6. No concrete defect was found in either change. Hardware validation is still pending, including checking that GRTC->TIMEOUT reads 6 after Bluefruit.begin(), but that does not block merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two changes in the PR: a Wire address-only probe on the GPIOs and the GRTC sleep TIMEOUT change to 6. Both appear in the raw summary and the objectives. The title is specific and m…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the two changes in the PR: a Wire address-only probe on the GPIOs and the GRTC sleep TIMEOUT change to 6. Both appear in the raw summary and the objectives. The title is specific and matches the main changes, though it lists two unrelated fixes in one line, which is somewhat broad.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the clock’s release,
Then taps the address on the line.
An ACK returns; a NACK says no,
The empty write gets its reply.
The tick sleeps on, with timeout set.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 180003de-d493-4809-a21e-ba721ac7ca35
Commits

Reviewing files that changed from the base of the PR and between b7e729c and b4b35de.

Files selected for processing: 2

  • cores/nRF5/freertos/portable/CMSIS/nrf54l/port_cmsis_systick.c
  • libraries/Wire/Wire_nRF52.cpp

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

TWIM's DMA.TX.MAXCNT is defined for 1..0xFFFF only. endTransmission()
with nothing written, which is how I2C scanners probe an address, started
a zero-byte transfer and stopped it at once; that never reliably puts the
address on the bus, and an idle TWIM does not raise STOPPED for a STOP
task, so the result did not reflect the target.

An address-only write is now clocked out on the GPIOs at up to 100 kHz
with TWIM disabled: START, address and write bit, ACK, STOP. It returns 0
on ACK, 2 on NACK and 4 for a busy or stuck bus. Transfers with data still
go through TWIM.
The datasheet requires TIMEOUT > WAKETIME + guard, with a guard of at
least one LFCLK cycle. NRFX_GRTC_SLEEP_DEFAULT_CONFIG gives TIMEOUT 5 and
WAKETIME 4, one cycle short. WAKETIME and AUTOEN stay at the nrfx values.
@caveman99
caveman99 force-pushed the wire-probe-grtc-timeout branch from b4b35de to 7e129d7 Compare November 23, 2026 14:34
@caveman99
caveman99 merged commit 29c4903 into master Nov 23, 2026
11 checks passed
@caveman99
caveman99 deleted the wire-probe-grtc-timeout branch November 23, 2026 14:36
@cvaldess

Copy link
Copy Markdown
Contributor

Tested master (29c4903, so #13–#17 together) on an nRF54L15-DK today. The firmware is the Meshtastic image the board has been running in production (2.8.3, platform v0.5.0, s145 10.0.1), rebuilt against master with nothing else changed. All reads below were taken over SWD without halting the CPU.

GRTC. GRTC->TIMEOUT reads 6 and WAKETIME 4, both 0.5 s after boot and again at 74 s, with BLE up and a phone connected. The SoftDevice doesn't reprogram it.

Wire. The board has an INA3221 at 0x42 and an SHT40 at 0x44 on the same bus. Meshtastic's scan (beginTransmission(addr); endTransmission() over the whole address range) found exactly those two, as the previous image did. It found no display, RTC or accelerometer, so no empty address answered. Both read back normally: the first environment packet had 23.4 °C / 42.6 %RH, and the power packet had 3.272 V on ch1 and 4.744 V on ch2, in line with the readings from the old image this morning.

Not covered: the scanner object is freed after setup and the console on this board is silent, so I didn't see the raw 0/2 codes for each address. I also didn't test a stuck bus (code 4), and the bus only ran at 100 kHz.

#15 on the shutdown path. I triggered a shutdown by writing shutdownAtMsec = 1 over SWD, the same flag the app's Shut down button sets. That runs cpuDeepSleep(): Serial.end(), then the BLE shutdown, which logs, then SYSTEMOFF. DWT comparators armed beforehand matched on the SYSTEMOFF write and, repeatedly, on the LOG_DEBUG in the loop after it. So logging with the UART closed now just returns, with no HardFault and no reset. With v0.5.1 the same path faulted about 2 s in. After I detached the probe, the next connection reported "Failed to power up DAP", meaning the part was really off. On a second run, waking it with a reset left RESETREAS at SREQ + DIF.

The rest of master looked fine in the same run: the TRNG produced its conditioning key, the phone reconnected with its stored bond (LESC, MTU 247, 2M PHY), and the flash showed no errors. The board stays on this image, so I'll report back if the soak turns anything up.

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

Successfully merging this pull request may close these issues.

2 participants