From abadf35e0600d66b85ca815680cec701d6233430 Mon Sep 17 00:00:00 2001 From: gullradriel <3157857+gullradriel@users.noreply.github.com> Date: Wed, 1 Jul 2026 08:47:07 +0200 Subject: [PATCH] Lna investigations and fix (#3240) * The LNA gain field 'L' lives in LPF_VGA_2 (reg 6), not RXRF_2 (reg 2). RXRF_2 only holds LNAgain_SPI_EN. The configure_rx_gain() function wrote 'L' into lpf_vga_2 but marked RXRF_2 dirty => the LNA value only got flushed incidentally because the following VGA write marks LPF_VGA_2 dirty. Drop the stray RXRF_2 dirty flag and rely on the LPF_VGA_2 flag, which carries both L and VGA. * The baseband build defined IS_H1_R9 as the compile-time constant 0, on the (now incorrect) assumption that detected_platform() isn't linked. The sd_over_usb image is the only baseband target that compiles the IS_H1_R9-gated upstream files (rf_path.c, si5351c.c, sgpio.c, platform_gpio.c, platform_scu.c), and it *does* link platform_detect.c and call detect_hardware_platform() at startup. Forcing IS_H1_R9=0 dead-stripped every 'if (IS_H1_R9)' branch, so a real HackRF One r9 was set up with the OG clock/GPIO/RF-path config in that image. Define IS_H1_R9 as the runtime '(detected_platform()==BOARD_ID_HACKRF1_R9)', mirroring upstream platform-detect.cmake for HACKRF_ONE. All usages are '#ifdef IS_H1_R9' + 'if (IS_H1_R9)' (no arithmetic '#if'), so a function-call expression is safe, single-quoted -D with no internal spaces keeps it intact through the shell-split DDEFS blob. --------- Co-authored-by: gullradriel --- firmware/application/hw/max2839.cpp | 3 +-- firmware/baseband/CMakeLists.txt | 14 ++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/firmware/application/hw/max2839.cpp b/firmware/application/hw/max2839.cpp index 7243bab95..9286ac7db 100644 --- a/firmware/application/hw/max2839.cpp +++ b/firmware/application/hw/max2839.cpp @@ -307,9 +307,8 @@ void MAX2839::configure_rx_gain() { } _map.r.lpf_vga_2.L = lna::gain_ordinal(lna_gain); - _dirty[Register::RXRF_2] = 1; _map.r.lpf_vga_2.VGA = vga::gain_ordinal(vga_gain); - _dirty[Register::LPF_VGA_2] = 1; + _dirty[Register::LPF_VGA_2] = 1; /* both L (LNA) and VGA live in LPF_VGA_2 */ flush(); } diff --git a/firmware/baseband/CMakeLists.txt b/firmware/baseband/CMakeLists.txt index 4bd84258b..c5939a12b 100644 --- a/firmware/baseband/CMakeLists.txt +++ b/firmware/baseband/CMakeLists.txt @@ -220,11 +220,17 @@ endif() # Upstream hackrf headers now gate on IS_* macros normally populated by # hackrf/firmware/platform-detect.cmake. We don't include that here, so derive -# the IS_* set from BOARD ourselves. IS_H1_R9 is forced to 0 (compile-time -# constant) so `if (IS_H1_R9)` branches resolve without needing the runtime -# detected_platform() symbol, which mayhem doesn't link in. +# the IS_* set from BOARD ourselves. IS_H1_R9 must mirror the upstream +# HACKRF_ONE definition: a *runtime* check on detected_platform(). The only +# baseband image that compiles IS_H1_R9-gated upstream files (rf_path.c, +# si5351c.c, sgpio.c, platform_gpio.c, platform_scu.c) is sd_over_usb, which +# does link platform_detect.c and calls detect_hardware_platform() at startup. +# Forcing IS_H1_R9=0 here silently compiled out all H1R9 behaviour, so a real +# HackRF One r9 was configured with the OG clock/GPIO/RF-path setup in that +# image. All usages are `#ifdef IS_H1_R9` + `if (IS_H1_R9)` (never arithmetic +# `#if`), so a function-call expression is safe. if(BOARD STREQUAL "HACKRF_ONE") - set(BOARD_IS_DEFS "-DIS_HACKRF_ONE=1 -DIS_NOT_PRALINE=1 -DIS_H1_R9=0 -DIS_NOT_H1_R9=1 -DIS_NOT_RAD1O=1 -DIS_NOT_JAWBREAKER=1 -DIS_H1_OR_PRALINE=1 -DIS_H1_OR_RAD1O=1 -DIS_H1_OR_JAWBREAKER=1 -DIS_EXPANSION_COMPATIBLE=1") + set(BOARD_IS_DEFS "-DIS_HACKRF_ONE=1 -DIS_NOT_PRALINE=1 -D'IS_H1_R9=(detected_platform()==BOARD_ID_HACKRF1_R9)' -D'IS_NOT_H1_R9=(!IS_H1_R9)' -DIS_NOT_RAD1O=1 -DIS_NOT_JAWBREAKER=1 -DIS_H1_OR_PRALINE=1 -DIS_H1_OR_RAD1O=1 -DIS_H1_OR_JAWBREAKER=1 -DIS_EXPANSION_COMPATIBLE=1") elseif(BOARD STREQUAL "PRALINE") set(BOARD_IS_DEFS "-DIS_PRALINE=1 -DIS_NOT_HACKRF_ONE=1 -DIS_NOT_H1_R9=1 -DIS_NOT_RAD1O=1 -DIS_NOT_JAWBREAKER=1 -DIS_H1_OR_PRALINE=1 -DIS_FOUR_LEDS=1 -DIS_EXPANSION_COMPATIBLE=1") elseif(BOARD STREQUAL "RAD1O")