diff --git a/9_Firmware/9_1_Microcontroller/9_1_1_C_Cpp_Libraries/ad9523.c b/9_Firmware/9_1_Microcontroller/9_1_1_C_Cpp_Libraries/ad9523.c index a88e3dc..926b5ab 100644 --- a/9_Firmware/9_1_Microcontroller/9_1_1_C_Cpp_Libraries/ad9523.c +++ b/9_Firmware/9_1_Microcontroller/9_1_1_C_Cpp_Libraries/ad9523.c @@ -704,7 +704,13 @@ int32_t ad9523_setup(struct ad9523_dev **device, AD9523_READBACK_CTRL, 0x0); ad9523_io_update(dev); - ad9523_calibrate(dev); + /* F-4.6: capture VCO calibration result. Without this, a failed + * calibration (e.g. target VCO outside the 3.6-4.0 GHz band) is + * silently swallowed and downstream relies on PLL2_LD alone in + * ad9523_status(), which can pass spuriously. */ + ret = ad9523_calibrate(dev); + if (ret < 0) + return ret; ad9523_sync(dev); *device = dev; diff --git a/9_Firmware/9_1_Microcontroller/9_1_3_C_Cpp_Code/main.cpp b/9_Firmware/9_1_Microcontroller/9_1_3_C_Cpp_Code/main.cpp index e226a7c..9cc45a1 100644 --- a/9_Firmware/9_1_Microcontroller/9_1_3_C_Cpp_Code/main.cpp +++ b/9_Firmware/9_1_Microcontroller/9_1_3_C_Cpp_Code/main.cpp @@ -243,6 +243,11 @@ IWDG_HandleTypeDef hiwdg; ADF4382A_Manager lo_manager; extern SPI_HandleTypeDef hspi4; +// AD9523 device handle. Retained at file scope so the recovery path can free +// the previous instance before re-running setup (F-4.5: ad9523_setup() malloc's +// a new dev + SPI desc each call; without retention each recovery cycle leaks). +static struct ad9523_dev *g_ad9523_dev = NULL; + //ADAR1000 ADAR1000Manager adarManager; @@ -1420,6 +1425,14 @@ static int configure_ad9523(void) int32_t ret; struct ad9523_dev *dev = NULL; + // F-4.5: recovery path re-runs configure_ad9523(); free the previous + // dev/SPI-desc allocation before letting setup() malloc a new pair. + if (g_ad9523_dev != NULL) { + DIAG("CLK", "Releasing previous ad9523_dev before re-setup"); + ad9523_remove(g_ad9523_dev); + g_ad9523_dev = NULL; + } + static struct ad9523_platform_data pdata; memset(&pdata, 0, sizeof(pdata)); @@ -1614,7 +1627,8 @@ static int configure_ad9523(void) ad9523_sync(dev); DIAG("CLK", "AD9523 configuration complete -- all outputs should be active"); - // keep device pointer globally if needed (dev) + // F-4.5: retain the dev handle so recovery can free it before re-setup. + g_ad9523_dev = dev; return 0; }