Skip to content

fix(gps): match Airoha idle_int sleep to the documented sequence - #12167

Merged
jp-bennett merged 2 commits into
developfrom
claude/airoha-idle-int-sleep
Oct 19, 2026
Merged

jp-bennett merged 2 commits into
developfrom
claude/airoha-idle-int-sleep

Conversation

@jp-bennett

@jp-bennett jp-bennett commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #12151 and #12004. Changes the sleep sequence on boards that talk to an AG3352 through idle_int and have no RTC_INT: the ThinkNode M8 ($PAIR650, reset wake) and the ThinkNode M9 ($PAIR003). Boards with RTC_INT (T1000-E, Wio T1000-S, Mesh Tracker X1) are unchanged.

Elecrow measured 1.5 mA in sleep on the M8 and reported that the GPS had not entered low-power mode. Their reference firmware enters sleep differently from ours, and the Quectel GNSS protocol spec explains part of the difference (V1.4, for the Airoha-based LC26G/LC76G/LC86G).

Before After
Before the sleep command $PAIR382,1 nothing
idle_int low before sending 5 ms 50 ms
idle_int low after sending 5 ms 0 ms
Sleep confirmed by $PAIR001,<cmd>,0 only $PAIR001,<cmd>,0, or no NMEA sentence for 1.1 s
Retries resend for up to 1.5 s 2 attempts
Before EN goes low nothing 50 ms

Why:

  • $PAIR382 is PAIR_TEST_LOCK_SYSTEM_SLEEP: "The CPU core will not enter Sleep mode automatically after the command has been sent." The spec only pairs it with $PAIR003 before saving settings, to keep the CPU awake. Here it works against sleep.
  • $PAIR650: "If successful, the module will be set to Backup mode and be prevented from receiving any commands. If failed, the $PAIR001 message will be returned." A successful $PAIR650 may never reply, so a missing reply can't be counted as a failure. Instead, either command counts as successful once NMEA stops. $PAIR001 replies arriving late are ignored, so a slow $PAIR003,0 on the M9 doesn't trigger a resend.
  • The 50 ms timings match Elecrow's reference cpuDeepSleep(). That reference sends only $PAIR650,0, with idle_int held low for 50 ms beforehand, then waits 50 ms before cutting the 0.8 V core.

A debug line now records how each sleep was confirmed: GPS: $PAIR650 took (acked, attempt 1).

M8 boot reset (second commit). If the MCU resets while the AG3352 is in backup mode, the GPS stays there. The cached-probe check then gets no answer, logs Cached GPS probe stale, and falls back to a full probe. earlyInitVariant() now pulses RESETB once at boot, like the M5's wake pulse in #12113. It isn't in initVariant(), because on nRF52 that runs before the scheduler, where delay() is unsafe.

GPS_DEBUG=1 trace (M8). Each sleep:

$PAIR012*39            (unsolicited, not in the Quectel spec; precedes every sleep)
$PAIR001,650,0*38      (ack)
GPS: $PAIR650 took (acked, attempt 1)
Pin EN LOW

After each RESETB wake, the receiver prints its boot banner unprompted: $PAIR001,002,1/,0, $PAIR011,001 (GNSS system startup), $PAIR021,AG3352Q_V3.3.0.AG3352_20251119,..., and $PAIR010 aiding requests. So every wake is a full restart out of backup mode. I rebooted the M8 with meshtastic --reboot while the GPS was in backup mode, and it came back with Using cached GPS probe: AG3352 @ 115200.

@mverch67, could you check the M9? #12004 found that $PAIR003 went unanswered without $PAIR382. That was with idle_int low for only 5 ms before sending. With 50 ms it may now be acknowledged; if not, the NMEA check should still confirm sleep and stop the resends.

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card (builds; path unchanged)
    • Other (please specify below)
      • ThinkNode M8 (AG3352Q): 7 of 7 sleeps acknowledged on the first attempt, with no $PAIR382; NMEA resumed after every reset wake. Fixes after waking took 27–32 s, against 36–84 s before. The boot reset recovered the GPS after a reboot during backup mode, using the cached probe.
      • ThinkNode M9 V2 tested OK
      • ThinkNode M8 sleep current: test build sent to Elecrow
      • ThinkNode M5 V2 (see PR12113)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved GPS receiver sleep handling for receivers with and without a software clock. Sleep confirmation and retries now account for differences in receiver behavior.
    • Receivers can also be recognized as asleep when NMEA output pauses, even if an acknowledgment is unavailable. This helps avoid relying on a single confirmation method.

For boards that wake the AG3352 through idle_int (ThinkNode M8 and M9):

- Drop $PAIR382,1 before the sleep command. It locks the CPU out of
  sleep, which works against both $PAIR003 and $PAIR650.
- Hold idle_int low 50 ms before sending, and wait 50 ms after the
  command takes before EN cuts the core, as Elecrow's reference does.
- A successful $PAIR650 need not reply, so also accept NMEA going quiet
  for a full cycle as success; resend once otherwise.

Boards with RTC_INT are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jp-bennett
jp-bennett requested a review from mverch67 October 15, 2026 20:22
@github-actions

Copy link
Copy Markdown
Contributor

⚡ Try this PR in the Web Flasher

Note

Building this pull request… the flash button, badges and supported-board
list will appear here automatically once CI finishes.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: meshtastic/firmware/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 61659d6d-adfa-446e-b99d-9d0e5e3909e6
📥 Commits

Reviewing files that changed from the base of the PR and between 653dace and 50f8105.

📒 Files selected for processing: 1
  • variants/nrf52840/ELECROW-ThinkNode-M8/variant.cpp

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

📝 Walkthrough

Airoha sleep handling now uses different success checks for software-RTC and other receivers. Non-software-RTC sleep uses an idle-interrupt lead, up to two command attempts, and either an ACK or NMEA silence to detect sleep. The ELECROW ThinkNode-M8 variant also pulses the GPS reset pin during early initialization.

Changes: Airoha sleep handling

Layer / File(s) Summary
Sleep timing and NMEA silence detection
src/gps/GPS.cpp
The idle-interrupt lead and receiver-settle interval are 50 ms. A quiet-period check detects NMEA sentence starts and feeds the watchdog while waiting.
Sleep command and retry behavior
src/gps/GPS.cpp
Non-software-RTC sleep no longer sends $PAIR382. It sends the sleep command up to twice and accepts an ACK or a full quiet interval as success. Software-RTC sleep retains its ACK-based retry loop.

ThinkNode-M8 GPS reset

Layer / File(s) Summary
Early GPS reset pulse
variants/nrf52840/ELECROW-ThinkNode-M8/variant.cpp
earlyInitVariant() configures PIN_GPS_RESET as an output, drives it high for 10 ms, then drives it low.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: 🔵 Low · up to 50f81

An awake AG3352 with no fix can appear quiet before the sleep command is confirmed, after which the device lowers EN. This is a bounded sleep-path risk, not a broad availability failure.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the main GPS sleep-sequence change for Airoha idle_int boards.
Description check Passed The description explains the affected boards, behavior changes, rationale, testing results, limitations, and relevant follow-up issues. It retains some template guidance, but the required technical an…
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@jp-bennett jp-bennett added the hardware-support Hardware related: new devices or modules, problems specific to hardware label Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

@mverch67 mverch67 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shutdown for M9 still works:

INFO  | 21:21:29 48 Enter deep sleep forever
INFO  | 21:21:29 49 GPS deep sleep
INFO  | 21:21:29 49 GPS power state ACTIVE -> OFF
DEBUG | 21:21:29 49 $GNGGA,000027.012,,,,,0,0,,,M,,M,,*50.
DEBUG | 21:21:29 49 $GNGGA,000027.012,,,,,0,0,,,M,,M,,*50..$GNRMC,000027.012,V,,,,,,,060180,,,N,V*20.
DEBUG | 21:21:29 49 $GNGGA,000027.012,,,,,0,0,,,M,,M,,*50..$GNRMC,000027.012,V,,,,,,,060180,,,N,V*20..$PAIR001,003,1*39.
DEBUG | 21:21:29 49 $GNGGA,000027.012,,,,,0,0,,,M,,M,,*50..$GNRMC,000027.012,V,,,,,,,060180,,,N,V*20..$PAIR001,003,1*39..$GNGGA,000028.012,,,,,0,0,,,M,,M,,*5F.
DEBUG | 21:21:29 49 $GNGGA,000027.012,,,,,0,0,,,M,,M,,*50..$GNRMC,000027.012,V,,,,,,,060180,,,N,V*20..$PAIR001,003,1*39..$GNGGA,000028.012,,,,,0,0,,,M,,M,,*5F..$GNRMC,000028.012,
DEBUG | 21:21:29 49 $GNGGA,000027.012,,,,,0,0,,,M,,M,,*50..$GNRMC,000027.012,V,,,,,,,060180,,,N,V*20..$PAIR001,003,1*39..$GNGGA,000028.012,,,,,0,0,,,M,,M,,*5F..$GNRMC,000028.012,
DEBUG | 21:21:29 49 Found: $PAIR001,003,0
DEBUG | 21:21:29 49 GPS: $PAIR003 took (acked, attempt 1)
DEBUG | 21:21:29 49 Pin EN LOW

There may be merge conflicts with #12113 .

If the MCU resets while the AG3352 is in backup mode, the GPS stays
there and the cached-probe check gets no answer, forcing a full re-probe.
Pulse RESETB in earlyInitVariant(), as the M5 does with its wake pulse
in #12113.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jp-bennett jp-bennett added this to the 2.8.2 milestone Oct 18, 2026
@jp-bennett
jp-bennett added this pull request to the merge queue Oct 19, 2026
Merged via the queue into develop with commit 8ebb698 Oct 19, 2026
@jp-bennett
jp-bennett deleted the claude/airoha-idle-int-sleep branch October 19, 2026 02:44
Slankydudl pushed a commit to Slankydudl/firmware that referenced this pull request Nov 23, 2026
…htastic#12167)

* fix(gps): match Airoha idle_int sleep to the documented sequence

For boards that wake the AG3352 through idle_int (ThinkNode M8 and M9):

- Drop $PAIR382,1 before the sleep command. It locks the CPU out of
  sleep, which works against both $PAIR003 and $PAIR650.
- Hold idle_int low 50 ms before sending, and wait 50 ms after the
  command takes before EN cuts the core, as Elecrow's reference does.
- A successful $PAIR650 need not reply, so also accept NMEA going quiet
  for a full cycle as success; resend once otherwise.

Boards with RTC_INT are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ThinkNode M8: reset the GPS out of backup mode at boot

If the MCU resets while the AG3352 is in backup mode, the GPS stays
there and the cached-probe check gets no answer, forcing a full re-probe.
Pulse RESETB in earlyInitVariant(), as the M5 does with its wake pulse
in meshtastic#12113.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hardware-support Hardware related: new devices or modules, problems specific to hardware

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants