gqrx-sdr / gqrx

Software defined radio receiver powered by GNU Radio and Qt.
http://gqrx.dk
GNU General Public License v3.0
3.02k stars 538 forks source link

r82xx_init: failed=-1 with rtlsdrs #996

Closed Ismas closed 1 year ago

Ismas commented 2 years ago

Hi there. Solidly receiving r82xx_init: failed=-1 on Ubuntu when triying to use any rtl dongle. Unable to run gqrx. Tried distribution package, compiling gqrx and osmosdr library, and appimage, to no avail. Dongles work perfectly on Windows on the same computer. No problem with Pluto and Soapy devices. Enviroment: Ubuntu 20.04.1 with kernel 5.11.0-38 on AMD Ryzen 5900X

Extact: `~/aps$ ./Gqrx-2.14.5-x86_64.AppImage linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown

gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.8.2.0 built-in source types: file fcd rtl rtl_tcp uhd hackrf bladerf rfspace airspy airspyhf soapy redpitaya freesrp gr::log :WARN: file_source0 - file size is not a multiple of item size Resampling audio 96000 -> 48000 BandPlanFile is /home/ismael/.config/gqrx/bandplan.csv BookmarksFile is /home/ismael/.config/gqrx/bookmarks.csv gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.8.2.0 built-in source types: file fcd rtl rtl_tcp uhd hackrf bladerf rfspace airspy airspyhf soapy redpitaya freesrp Using device #0 Realtek RTL2838UHIDIR SN: 00000013 Found Rafael Micro R820T tuner r82xx_write: i2c wr failed=-1 reg=13 len=7 r82xx_write: i2c wr failed=-1 reg=0c len=1 r82xx_init: failed=-1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 r82xx_write: i2c wr failed=-1 reg=0a len=1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 rtlsdr_demod_write_reg failed with -1 rtlsdr_demod_read_reg failed with -1 gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.8.2.0 built-in source types: file fcd rtl rtl_tcp uhd hackrf bladerf rfspace airspy airspyhf soapy redpitaya freesrp gr::log :WARN: file_source0 - file size is not a multiple of item size WARNING: Overriding original sample rate of 96000 with 1.8e+06 ~/aps$ uname -a Linux tifon 5.11.0-38-generic #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux `

argilo commented 2 years ago

Do you see errors if you run rtl_test? If so, then the problem is not with Gqrx.

Ismas commented 2 years ago

Ok, I checked with rtl_test and things got weirder. rtl_test also crashed, and I managed to isolate part of the problem to the 50cm USB extension cable was using (!) Checked on both USB2 ans USB3 ports. Dongle with cable works OK on WIndows. After connecting the dongle directly to the port, rtl_test and gqrx starts ok, but fails when trying to change frequency. Tested as USB device and rtl_server, same result. Also changed kernel to 5.14. Thanks for the help.

$ gqrx
Controlport disabled
No user supplied config file. Using "default.conf"
gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.8.1.0
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy airspyhf soapy redpitaya freesrp 
gr::log :WARN: file_source0 - file size is not a multiple of item size
FM demod gain: 3.05577
Resampling audio 96000 -> 48000
IQ DCR alpha: 1.04166e-05
Using audio backend: auto
BookmarksFile is /home/ismael/.config/gqrx/bookmarks.csv
[INFO] [UHD] linux; GNU C++ version 9.2.1 20200304; Boost_107100; UHD_3.15.0.0-2build5
getDeviceList : Available input devices:
   "Realtek RTL2838UHIDIR SN: 00000001"
   "RFSPACE SDR-IQ Receiver"
   "RFSPACE SDR-IP Receiver"
   "RFSPACE NetSDR Receiver"
   "RFSPACE Cloud-IQ Receiver"
   "RTL-SDR Spectrum Server"
   "Red Pitaya Transceiver Server"
   "Complex Sampled (IQ) File"
Loading configuration from: "default.conf"
Configuration file: "/home/ismael/.config/gqrx/default.conf"
Crash guard triggered! 

Launching I/O device editor
firstTimeConfig
CIoConfig : Available output devices:
    0 : "Starship/Matisse HD Audio Controller Estéreo digital (IEC958)"
    1 : "GP104 High Definition Audio Controller Digital Stereo (HDMI)"
    2 : "Jack sink (PulseAudio JACK Sink)"
qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 562, resource id: 11078674, major code: 40 (TranslateCoords), minor code: 0
New input device selected: 6
  Label: "Realtek RTL2838UHIDIR SN: 00000001"
  Devstr: "rtl=0"
saveConfig
Loading configuration from: "/home/ismael/.config/gqrx/default.conf"
Configuration file: "/home/ismael/.config/gqrx/default.conf"
gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.8.1.0
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy airspyhf soapy redpitaya freesrp 
Using device #0 Realtek RTL2838UHIDIR SN: 00000001
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!
[R82XX] PLL not locked!
IQ DCR samp_rate: 1.024e+06
IQ DCR alpha: 9.76562e-07
Changing NB_RX quad rate: 96000 -> 1.024e+06
New antenna selected: "RX"
********************
Gain name: "LNA"
      min: 0
      max: 49.6
     step: 0.5
********************
No change in output device:
  old: 
  new: 
[R82XX] PLL not locked!
IQ DCR samp_rate: 1.8e+06
IQ DCR alpha: 5.55555e-07
Changing NB_RX quad rate: 1.024e+06 -> 1.8e+06
Requested sample rate: 1800000
Actual sample rate   : "1800000.000000"
New FFT rate: 25 Hz
Requested bandwidth: 2000000 Hz
Actual bandwidth   : 0 Hz
setFreqCorr : 0 ppm
New LNB LO: 0 Hz
New mode index: 2
Filter preset for mode 2 LO: -5000 HI: 5000
Generating taps for new filter   LO:-5000   HI:5000 TW:2000   Taps: 115
setFftRate to "25 fps"
New FFT rate: 25 Hz
New FFT rate: 25 Hz
setFftSize to "8192"
New FFT rate: 25 Hz
Generating taps for new filter   LO:-5000   HI:5000 TW:2000   Taps: 115
New FFT rate: 25 Hz
New FFT rate: 25 Hz
No audio FFT data.
No audio FFT data.
No audio FFT data.
No audio FFT data.
No audio FFT data.
No audio FFT data.
No audio FFT data.
No audio FFT data.
No audio FFT data.
No audio FFT data.
rtlsdr_demod_write_reg failed with -9                         (<- CHANGED FREQ HERE)
r82xx_write: i2c wr failed=-9 reg=17 len=1
r82xx_set_freq: failed=-9
rtlsdr_demod_write_reg failed with -9                          (<- CHANGED FREQ HERE)
r82xx_write: i2c wr failed=-9 reg=17 len=1
r82xx_set_freq: failed=-9
rtlsdr_demod_write_reg failed with -9                         (<- CHANGED FREQ HERE)
r82xx_write: i2c wr failed=-9 reg=17 len=1
r82xx_set_freq: failed=-9
saveSettings *** FIXME_ SQL on/off                            (<- EXITED HERE)
New FFT rate: 25 Hz
rtlsdr_demod_write_reg failed with -9
r82xx_write: i2c wr failed=-9 reg=06 len=1
Ismas commented 2 years ago

Well, I have the problem mostly located and patched. Surprised none others have this problem. Motherboard firmware updated (MSI MS-7C92), kernel to 5.14.0-1005, CPU Ryzen 5900X, ubuntu 20.04 LTS up to date. Recompiled libusb-1.0, rtl_sdr and gqrx. Now long USB cable problem apparently dissapeared, but frecuency change problem remained.

Isolated the problem to libusb libusb_control_transfer() function raising LIBUSB_ERROR_PIPE error on call from rtlsdr_set_i2c_repeater(dev, 1); included on function rtlsdr_set_center_freq()

When control_transfer fails, it seems to left incorrectly configured USB communication and rest of USB calls fails (for the set_center function). There are dozens of rtlsdr_set_i2c_repeater(dev, 1); calls but only this one fails, don't know why. BTW, libusb error is not captured nor managed in any way so subsequent USB calls failis.

Discovered that simply calling rtlsdr_set_i2c_repeater(dev, 1); twice in short succession the function works. First fails, second works. gqrx and other rtl_sdr library consumers works with low to none degraded performance. Might be some hw specific timing of quirk.

librltlsdr.c: ` int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq) { int r = -1;

if (!dev || !dev->tuner)
    return -1;

if (dev->direct_sampling) {
    r = rtlsdr_set_if_freq(dev, freq);
} else if (dev->tuner && dev->tuner->set_freq) {
    rtlsdr_set_i2c_repeater(dev, 1);
    ///////////////////////////////////
    fprintf(stderr, "** LAME PATCH for -9 (LIBUSB_ERROR_PIPE) **\n");
    rtlsdr_set_i2c_repeater(dev, 1);
    /////////////////////////////////////////
    r = dev->tuner->set_freq(dev, freq - dev->offs_freq);
    rtlsdr_set_i2c_repeater(dev, 0);
}

if (!r)
    dev->freq = freq;
else
    dev->freq = 0;

return r;

} `

I'm sorry but have no time to report and follow this error/bug to osmosdr, so I left it here to whoever interested.

Regards

argilo commented 1 year ago

I'll close this off, as this appears to be a hardware issue and not a bug in Gqrx.