From 5bddc8da29253a2e4be58806f75cb4950ce0891f Mon Sep 17 00:00:00 2001 From: Ryan Tucker Date: Tue, 30 May 2017 12:34:05 -0400 Subject: [PATCH] host: bladerf2: init ina219 before ad9361 This is a workaround for persistent USB timeouts after AD9361 init when CMAKE_BUILD_TYPE=Release. If DEBUG is defined, ad9361_verify_fir_filter_coef reads in all the FIR filter coeffs from the 9361 and makes sure they are as expected. If it is NOT defined, it skips this check. For reasons unknown, if ina219_init is called immediately after ad9361_ensm_restore_prev_state (the last thing that happens before ad9361_verify_fir_filter_coef in ad9361_load_fir_filter_coef), libusb times out and everything goes terribly wrong. Adding a usleep(100) is sufficient to avoid this. There does not seem to be a reason why this should make any difference whatsoever, but this seems to do the trick. --- .../libbladeRF/src/board/bladerf2/bladerf2.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/host/libraries/libbladeRF/src/board/bladerf2/bladerf2.c b/host/libraries/libbladeRF/src/board/bladerf2/bladerf2.c index 63f21e60..10e6edcd 100644 --- a/host/libraries/libbladeRF/src/board/bladerf2/bladerf2.c +++ b/host/libraries/libbladeRF/src/board/bladerf2/bladerf2.c @@ -356,6 +356,17 @@ static int bladerf2_initialize(struct bladerf *dev) return status; } + /* Initialize INA219 */ + /* For reasons unknown, this fails if done immediately after + * ad9361_set_rx_fir_config when DEBUG is not defined. It shouldn't make + * a difference, but it does. TODO: Investigate/fix this */ + status = ina219_init(dev, ina219_r_shunt); + if (status < 0) { + log_error("INA219 init error: %d\n", status); + return status; + } + + /* Initialize AD9361 */ status = ad9361_init(&board_data->phy, &ad9361_init_params, dev); if (status < 0) { log_error("AD9361 initialization error: %d\n", status); @@ -374,12 +385,7 @@ static int bladerf2_initialize(struct bladerf *dev) return errno_ad9361_to_bladerf(status); } - status = ina219_init(dev, ina219_r_shunt); - if (status < 0) { - log_error("INA219 init error: %d\n", status); - return status; - } - + /* Set up band selection */ status = bladerf2_select_band(dev, BLADERF_TX, board_data->phy->pdata->tx_synth_freq); if (status < 0) { log_error("bladeRF TX band select error: %d\n", status);