firmware: fix explicit LO frequency being ignored in radio_update_frequency#1795
Closed
munzzyy wants to merge 1 commit into
Closed
firmware: fix explicit LO frequency being ignored in radio_update_frequency#1795munzzyy wants to merge 1 commit into
munzzyy wants to merge 1 commit into
Conversation
mixer_set_frequency() was called with freq_lo instead of requested_lo, so any explicit LO that differs from the currently applied one gets silently dropped and the mixer stays on the old LO. The IF branch just above already passes requested_if correctly, so this brings LO in line with it. It's worse right after a device reset: radio_init() sets every RADIO_BANK_APPLIED register, including LO, to RADIO_UNSET, and freq_lo starts out as applied_lo. RADIO_UNSET is 0xffffffffffffffff, so passed through as an fp_40_24_t it gets clamped straight down to MAX_LO by rffc5071_config_synth() (5400 MHz), which is exactly what greatscottgadgets#1785's register dumps show (LO=5400 MHz, RF=5400-2380=3020 MHz) instead of the requested LO.
Member
|
We do not accept LLM-generated contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1785.
The bug
In
radio_update_frequency()(firmware/common/radio.c), the LO branch callsmixer_set_frequency()withfreq_loinstead ofrequested_lo:freq_lois initialized a few lines up fromapplied_lo(the last LO actuallyprogrammed into the mixer), so this branch reprograms the mixer with whatever
LO was already applied and throws away
requested_loentirely. The IF branchdirectly above it does this correctly with
requested_if, so LO was just outof step with it.
This means any explicit LO tune that differs from the currently applied one
gets silently dropped, not just the first tune after a reset. It's worse right
after a reset, though:
radio_init()sets everyRADIO_BANK_APPLIEDregister,LO included, to
RADIO_UNSET(0xffffffffffffffff).freq_lostarts out asapplied_lo, so on the first explicit tune after reset it'sRADIO_UNSETflowing into
mixer_set_frequency(). As anfp_40_24_tthat's a huge value,and
rffc5071_config_synth()clamps it straight down:So the RFFC5071 gets programmed to 5400 MHz regardless of what LO was
requested, matching the register dumps in #1785 (LO=5400 MHz, RF =
5400-2380 = 3020 MHz).
The fix
Pass
requested_loinstead offreq_lo, matching the IF branch above it.if (requested_lo != RADIO_UNSET) { - freq_lo = mixer_set_frequency(&mixer, freq_lo, false); + freq_lo = mixer_set_frequency(&mixer, requested_lo, false); }One line, one file.
freq_lostill gets updated afterward for whateverdownstream RF math still reads it (e.g. the PRALINE image-rejection block),
now with the value the mixer was actually just programmed to.
Scope check
Only the explicit-LO path is touched. The auto-tune path (
requested_lo == RADIO_UNSET, the "compute precise LO" block further down) never runsmixer_set_frequency()withfreq_lo, so it's unaffected. RX/TX/RX_SWEEPstartup and the CLKIN/XTAL clock-source-selection path are also untouched by
this diff.
Not bench-tested
I don't have an ARM toolchain or a HackRF on hand to build and flash this, so
this is reasoned from source and the register dumps in the issue, not
verified on hardware. To confirm: flash this build, do a cold reset, issue an
explicit LO tune (e.g. via
hackrf_set_freq_explicit) to something other than5400 MHz, and check with
hackrf_debug/a register dump that the RFFC5071 LOmatches what was requested instead of clamping to 5400 MHz. Worth also
re-running a normal auto-tune (
hackrf_set_freq) afterward to confirm thatpath still behaves as before.