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 b9edc50..e226a7c 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 @@ -1423,6 +1423,43 @@ static int configure_ad9523(void) static struct ad9523_platform_data pdata; memset(&pdata, 0, sizeof(pdata)); + // Channels array (must allocate AD9523_NUM_CHAN entries) — assigned to + // pdata BEFORE ad9523_init() so its per-channel default loop iterates + // over the right num_channels. + static struct ad9523_channel_spec channels[AD9523_NUM_CHAN]; + pdata.channels = channels; + pdata.num_channels = AD9523_NUM_CHAN; + + // Fill ad9523 init param + struct ad9523_init_param init_param; + memset(&init_param, 0, sizeof(init_param)); + + // SPI init (no_os type) + init_param.spi_init.max_speed_hz = 10000000; // 10 MHz SPI + init_param.spi_init.chip_select = 0; + init_param.spi_init.mode = NO_OS_SPI_MODE_0; + init_param.spi_init.platform_ops = &stm32_spi_ops; + init_param.spi_init.extra = &hspi4; // pass HAL handle via extra + + init_param.pdata = &pdata; + + // F-4.1: ad9523_init() unconditionally overwrites every field in pdata + // (vcxo_freq=0, pll1_bypass_en=1, pll2_ndiv_b_cnt=4, every channel + // field). Call it BEFORE the user overrides below. The previous + // "customize → init → setup" ordering wiped every user value and left + // PLL2 N=16 (target VCO 1.6 GHz, far below the 3.6-4.0 GHz band) → + // PLL2 never locked → boot halted. This call seeds defaults; user + // overrides land on top. + DIAG("CLK", "Calling ad9523_init() -- seeds pdata defaults (must precede overrides)"); + { + int32_t init_ret = ad9523_init(&init_param); + DIAG("CLK", "ad9523_init() returned %ld", (long)init_ret); + if (init_ret != 0) { + DIAG_ERR("CLK", "ad9523_init() FAILED (ret=%ld)", (long)init_ret); + return -1; + } + } + // VCXO + refs pdata.vcxo_freq = 100000000; // 100 MHz VCXO on OSC_IN pdata.refa_diff_rcv_en = 0; // REFA 10 MHz single-ended @@ -1438,7 +1475,16 @@ static int configure_ad9523(void) pdata.pll2_ndiv_a_cnt = 0; pdata.pll2_ndiv_b_cnt = 9; // 4*9 + 0 = 36 pdata.pll2_r2_div = 0; // R2=1 - pdata.pll2_charge_pump_current_nA = 3500; // example + pdata.pll2_charge_pump_current_nA = 3500; + + // F-4.2 + F-4.7: AD9523 OUT4-OUT9 source from M1 or M2 only (no VCO + // direct path); M1/M2 ∈ {3,4,5}. m1=0 (memset/init default) sets + // M1_PWR_DOWN_EN, killing channels 4-9. With m1=3 and VCO 3.6 GHz, + // M1 output = 1.2 GHz; channel dividers below operate on this. m1=3 + // is the unique choice for the labelled frequency set (m1=4 fails + // OUT4=400MHz; m1=5 fails OUT0/1=300MHz). + pdata.pll2_vco_diff_m1 = 3; + pdata.pll2_vco_diff_m2 = 3; // Loop filters: reasonable starting values from examples pdata.rpole2 = RPOLE2_900_OHM; @@ -1446,11 +1492,6 @@ static int configure_ad9523(void) pdata.cpole1 = CPOLE1_24_PF; pdata.rzero_bypass_en = 0; - // Channels array (must allocate AD9523_NUM_CHAN entries) - static struct ad9523_channel_spec channels[AD9523_NUM_CHAN]; - pdata.channels = channels; - pdata.num_channels = AD9523_NUM_CHAN; - // Initialize channels to disabled defaults for (int i=0; i VCO 3.6 GHz, M1 1.2 GHz", (unsigned long)pdata.vcxo_freq, 4 * pdata.pll2_ndiv_b_cnt + pdata.pll2_ndiv_a_cnt, pdata.pll2_ndiv_b_cnt, pdata.pll2_ndiv_a_cnt, 4 * pdata.pll2_ndiv_b_cnt + pdata.pll2_ndiv_a_cnt, - pdata.pll2_r2_div); - DIAG("CLK", "Enabled channels: 0,1(/12=300M) 4,5(/9=400M) 6(/36=100M) 7(/180=20M) 8,9(/60=60M) 10,11(/30=120M)"); - - // init ad9523 defaults (fills any missing pdata defaults) - DIAG("CLK", "Calling ad9523_init() -- fills pdata defaults"); - { - int32_t init_ret = ad9523_init(&init_param); - DIAG("CLK", "ad9523_init() returned %ld", (long)init_ret); - if (init_ret != 0) { - DIAG_ERR("CLK", "ad9523_init() FAILED (ret=%ld)", (long)init_ret); - return -1; - } - } + pdata.pll2_r2_div, + pdata.pll2_vco_diff_m1); + DIAG("CLK", "Enabled channels: 0,1(/4=300M) 4,5(/3=400M) 6(/12=100M) 7(/60=20M) 8,9(/20=60M) 10,11(/10=120M)"); /* [Bug #2 FIXED] Removed first ad9523_setup() call that was here. * It wrote to the chip while still in reset — writes were lost.