Files
mayhem-firmware/firmware/application/rf_path.cpp
T
Mo 60b5cc8832 PRALINE: fix TX/RX above 2580 MHz (high-band mixer routing + tuning) (#3316)
* PRALINE: take high-band IF from the reference tune tables

high_band() used a hand-written formula for the second LO that pushed the
MAX2831 IF above 2600 MHz from ~4.5 GHz upwards (2733 MHz at 5 GHz,
2760 MHz at 7.2 GHz), outside its usable range. Use the reference
praline_tune_config_tx/rx tables (already present in tuning.cpp but only
consulted below 2580 MHz): TX IF stays within 2325-2575 MHz, low-side
injection LO = RF - IF, and the RX quarter-rate shift is applied, as in
hackrf radio.c radio_update_frequency() for RF_PATH_FILTER_HIGH_PASS.
HackRF One keeps its existing formula (#ifndef PRALINE).

* RFFC507x: select LO divider like the reference, add RELOK

The LO divider loop stopped at the first divider that lifted the VCO to or
above its 2.7 GHz minimum, parking the VCO exactly on the floor for some
LOs (e.g. LO = 675 MHz used for 3.000 GHz TX on PRALINE: 675 x 4 =
2700.0 MHz) where lock is marginal. Mirror hackrf rffc5071_config_synth()
and pick the largest divider that keeps the VCO at or below 5.4 GHz; the
result is identical to the reference for every LO in 85-5400 MHz.

Also request a relock (PLL_CTRL.relok) after reprogramming the synthesizer
while the part is enabled, as rffc5071_set_frequency() does.

* PRALINE: enable the RFFC5072 mixer on the high band

Regression from #3238: the PRALINE RF path enabled the mixer only on the
Low band (mix_bypass.setState(band == Band::Low)). Before #3238 (#3030)
the mixer was bypassed only in the Mid window. On the High band (>2580 MHz)
tuning.cpp still programmed and enabled the RFFC5072, but the RF switch
(MIX_EN_N) routed around it, so the MAX2831 IF (~2.3-2.7 GHz) appeared at
the antenna port instead of the requested RF: TX and RX above 2580 MHz
effectively did not work from the GUI, while hackrf_transfer with the
reference firmware did. Enable the mixer on Low and High, bypass only on
Mid, as hackrf rf_path.c rf_path_set_filter() does (LOW_PASS and HIGH_PASS
both call mixer_enable(); only BYPASS disables it).

* Update VCO frequency logic with conditional compilation

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Fix code formatting (clang-format)

Single space before a trailing comment in rffc507x.cpp set_frequency(),
per the project's clang-format config. No functional change.

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-09-16 16:03:19 +02:00

139 lines
3.8 KiB
C++

/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "rf_path.hpp"
#include "platform.hpp"
#include "utility.hpp"
#include "gpio.hpp"
using namespace gpio_control;
namespace rf {
namespace path {
void Path::init() {
/* Set safe initial default states */
direction = Direction::Receive;
rf_amp_en = false;
ant_bias_en = false;
#ifdef PRALINE
band = Band::Low;
#else
band = Band::Mid;
#endif
update();
}
void Path::set_direction(const Direction new_direction) {
direction = new_direction;
update();
}
void Path::set_band(const Band new_band) {
band = new_band;
update();
}
void Path::set_rf_amp(const bool new_rf_amp) {
rf_amp_en = new_rf_amp;
update();
}
void Path::set_ant_bias(const bool new_ant_bias) {
ant_bias_en = new_ant_bias;
update();
}
bool Path::get_ant_bias() const {
return ant_bias_en;
}
void Path::update() {
const bool is_tx = (direction == Direction::Transmit);
#ifdef PRALINE
// PRALINE specific RF path control directly applied to pins.
// Active-low pin inversion is handled internally inside setState().
tx_enable.setState(is_tx);
// On the PRALINE board the RFFC5072 mixer is used on BOTH the Low band
// (<2320 MHz, low-side image reject, LPF) and the High band (>2580 MHz,
// high-side image reject, LPF off). It is bypassed only in the Mid window
// (2320-2580 MHz) where the MAX2831 tunes the RF directly. This mirrors the
// reference firmware (hackrf rf_path.c rf_path_set_filter(): LOW_PASS and
// HIGH_PASS both call mixer_enable(); only BYPASS disables it).
//
// setState() handles the active-low MIX_ENABLE_N inversion, so 'true' means
// "mixer enabled". Bypassing the mixer on the High band leaves the MAX2831
// IF (~2.3-2.7 GHz) at the antenna port instead of the requested RF, which
// made TX (and RX) above 2580 MHz effectively not work.
mix_bypass.setState(band != Band::Mid);
lpf.setState(band == Band::Low);
rf_amp_enable.setState(rf_amp_en);
ant_bias.setState(ant_bias_en);
#else
const bool is_rx = (direction == Direction::Receive);
// HackRF One (OG & R9) RF path control
const bool mix_bypass_en = (band == Band::Mid);
const bool amplify = rf_amp_en;
// Primary TX/RX routing switches
if (!hackrf_r9) {
og_tx.setState(is_tx);
}
if (hackrf_r9) {
r9_rx.setState(is_rx); // Single pin handles directional switching on R9
} else {
og_rx.setState(is_rx);
}
// RF path switch configuration matrix
rx_mix_bypass.setState(mix_bypass_en);
tx_mix_bp.setState(is_tx && mix_bypass_en);
rx_mix_bp.setState(is_rx && mix_bypass_en);
hpf.setState(band == Band::High);
lpf.setState(band == Band::Low);
amp_bypass.setState(!amplify);
tx_amp.setState(is_tx && amplify);
rx_amp.setState(is_rx && amplify);
tx_mix_bypass.setState(mix_bypass_en);
tx_amp_pwr.setState(is_tx && amplify);
rx_amp_pwr.setState(is_rx && amplify);
if (hackrf_r9) {
ant_bias.setState(ant_bias_en);
}
#endif
}
} // namespace path
} // namespace rf