Skip to content

ESP32-C5: every capture waits about 1.6 ms because the BT modem clock is off - #25

Open
14sea wants to merge 1 commit into
ESPARGOS:mainfrom
14sea:c5-adctrig-bt-clock
Open

14sea wants to merge 1 commit into
ESPARGOS:mainfrom
14sea:c5-adctrig-bt-clock

Conversation

@14sea

@14sea 14sea commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

This is mainly a problem report. The 9-line change is here to show the cause and is for reference only; I am not asking for it to be merged as it stands, and would like to hear how you would prefer to handle it.

Problem. On the C5 the <capture-microseconds> field of the DATA reply is about 1.64 ms longer than the samples themselves: CAP 16380 0 reports about 1880 µs for 205 µs of samples at 80 MS/s. The same fixed cost holds a 256-point SPEC at 429 FFT/s, at 80 and at 4 MS/s alike.

Cause. Vendor adctrig() reads and then writes 0x600a20b4 (it clears bit 0) before starting the capture. That register is in the BT block, and nothing in ESP-SDR turns the BT modem clock on, so each of the two accesses only returns after about 819 µs. That is 65536 cycles at 80 MHz, so it looks like a bus timeout. I found it by writing out the adctrig mode-0 sequence from the disassembly and timing each step; every other step takes 0–4 µs.

The change. One call to modem_clock_module_enable(PERIPH_BT_MODULE) at start-up, C5 only. In the pinned IDF this enables the BLE MAC, BT/802.15.4 common baseband and ETM clocks (plus COEXIST, which Wi-Fi already holds), reference-counted. It does not start the BT controller.

Measured (a8eaac1 against this branch, 5300 MHz, manual gain 40, medians):

Rate (MS/s) 80 40 20 10 8 4
16380 samples take (µs) 205 410 819 1638 2048 4095
a8eaac1 reports (µs) 1884 2083 2492 3311 3720 5773
this branch reports (µs) 239 439 849 1668 2077 4125
SPEC (FFT/s) 256 points, 80 MS/s 256 points, 4 MS/s 2048 points, 80 MS/s
a8eaac1 429 429 159
this branch 1666 1477 217
  • Same result on one rev v1.2 board and two rev v1.0 boards; each v1.0 board ran both builds.
  • Alternating CAP (six rates) and SPEC on this branch, 90 minutes on each v1.0 board: in total 16518 captures and 6.9 million spectrum frames with no command, CRC or frame-sequence error; the 80 MS/s capture time stayed within 234–248 µs.
  • On the same board, noise level (within 0.06 dB), 64-bin spectrum shape (0.03 dB rms), DC offset and gain field are unchanged.
  • CAP round trips over USB hardly change (12–13 per second either way); the gain is in what runs on the chip.
  • The one difference I saw: a capture starts 1.6 ms sooner after a command, so the first capture straight after GAIN HARDWARE on a busy channel more often still carries the manual gain index (12 % against 4–7 % with no delay, almost none from 4 ms on). Both builds do this; the earlier start only makes it more visible.

Not checked, and questions.

  • Current draw with the extra clocks on. I have no way to measure it.
  • C6 and C61. Their stock_capture() clears the same bit of 0x600a20b4 directly. I have neither board, so I do not know whether they wait too; <capture-microseconds> for CAP 16380 0 against 205 µs would show it.
  • The alternative of leaving the clock off and not touching that register, in a hand-written C5 capture sequence like the C6/C61 ones. In a local experiment that gave 214 µs at 80 MS/s, but it replaces the vendor call.

Whether to enable the clock, skip the access, or leave it as it is, is your call. Happy to rework or drop this.

Co-worked with Claude Code

… stall

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 11:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Jeija

Jeija commented Nov 16, 2026

Copy link
Copy Markdown
Member

Thanks for the PR, and thanks for noticing this in the first place 👍

Also affects the ESP32-C61 (but not ESP32-C6), so I merged it as 3ab3b65

I think enabling the bluetooth modem clock is a good enough fix for now. Seems like at least one of the bits inside the 0x600a20b4 register has to be clear for the dump mode to work correctly (and we don't want to rely on potentially undefined previous hardware state), so we should probably write that register.

I will leave this PR open in case we find a different / better solution in the future.

@14sea

14sea commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for taking it, and for checking the C61 and the C6. Leaving the PR open is fine with me.

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.

3 participants