This patch fixes a regression of rtl-sdr dongles with the FC00012 tuner.
The code to switch on the FC00012 tuner by pulling it's ~RESET line low ended up with an off-by-one error in a refactor a long time ago,
The FC00012 only continued to work by accident as a different bug in rtlsdr_set_gpio_output had a side-effect of pulling low the FC00012's ~RESET line
When the rtl_set_gpio_output bug was fixed in ba64a7459a43 the side- effect also went away, leaving the FC00012 tuner in reset, and failing to be detected (or indeed work at all).
This patch fixes the original off-by-one error. It's been tested on an FC00012 in a GTek T803 from both warm and cold starts, but needs testing on the FC2580 as both the FC00012 and FC2580 are brought out of reset by a GPIO off the RTL (at least in some designs). If the FC2580 actually uses a different pin, this code will also break. (I'm only going from vague memory that the FC2580 used the same pin.)
--- src/librtlsdr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/librtlsdr.c b/src/librtlsdr.c index b369a5d..678fadd 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -1565,11 +1565,11 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) }
/* initialise GPIOs */ - rtlsdr_set_gpio_output(dev, 5); + rtlsdr_set_gpio_output(dev, 4);
/* reset tuner before probing */ - rtlsdr_set_gpio_bit(dev, 5, 1); - rtlsdr_set_gpio_bit(dev, 5, 0); + rtlsdr_set_gpio_bit(dev, 4, 1); + rtlsdr_set_gpio_bit(dev, 4, 0);
reg = rtlsdr_i2c_read_reg(dev, FC2580_I2C_ADDR, FC2580_CHECK_ADDR); if ((reg & 0x7f) == FC2580_CHECK_VAL) { @@ -1581,7 +1581,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) reg = rtlsdr_i2c_read_reg(dev, FC0012_I2C_ADDR, FC0012_CHECK_ADDR); if (reg == FC0012_CHECK_VAL) { fprintf(stderr, "Found Fitipower FC0012 tuner\n"); - rtlsdr_set_gpio_output(dev, 6); + rtlsdr_set_gpio_output(dev, 5); dev->tuner_type = RTLSDR_TUNER_FC0012; goto found; } -- 2.13.2
On Sun, 4 Feb 2018, David Basden wrote:
This patch fixes a regression of rtl-sdr dongles with the FC00012 tuner.
The code to switch on the FC00012 tuner by pulling it's ~RESET line low ended up with an off-by-one error in a refactor a long time ago,
The FC00012 only continued to work by accident as a different bug in rtlsdr_set_gpio_output had a side-effect of pulling low the FC00012's ~RESET line
When the rtl_set_gpio_output bug was fixed in ba64a7459a43 the side- effect also went away, leaving the FC00012 tuner in reset, and failing to be detected (or indeed work at all).
This patch fixes the original off-by-one error. It's been tested on an FC00012 in a GTek T803 from both warm and cold starts, but needs testing on the FC2580 as both the FC00012 and FC2580 are brought out of reset by a GPIO off the RTL (at least in some designs). If the FC2580 actually uses a different pin, this code will also break. (I'm only going from vague memory that the FC2580 used the same pin.)
Hi David,
I ran into the same issue and already submitted a patch http://lists.osmocom.org/pipermail/osmocom-sdr/2017-November/001630.html but it seems nobody was interested in integrating it. I wasn't the first to run into this either: http://lists.osmocom.org/pipermail/osmocom-sdr/2017-October/001617.html
I see we reached the same conclusions and the patches are also very similar. The one difference is that you also do:
@@ -1581,7 +1581,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) reg = rtlsdr_i2c_read_reg(dev, FC0012_I2C_ADDR, FC0012_CHECK_ADDR); if (reg == FC0012_CHECK_VAL) { fprintf(stderr, "Found Fitipower FC0012 tuner\n");
- rtlsdr_set_gpio_output(dev, 6);
- rtlsdr_set_gpio_output(dev, 5);
dev->tuner_type = RTLSDR_TUNER_FC0012; goto found; }
What is the purpose of this change? I see GPIO 6 is used in fc0012_set_freq():
int fc0012_set_freq(void *dev, uint32_t freq) { /* select V-band/U-band filter */ rtlsdr_set_gpio_bit(dev, 6, (freq > 300000000) ? 1 : 0); return fc0012_set_params(dev, freq, 6000000); }
so I think we need to set GPIO 6 to output mode.
Best regards, David