[Hackrf-dev] hackrf_open() failed: HACKRF_ERROR_LIBUSB (-1000)

Vincent Le Nir vlenir.ciss.rma at gmail.com
Thu Mar 19 06:22:10 EDT 2015


2015-03-18 18:26 GMT+01:00 Dominic Spill <dominicgs at gmail.com>:

> On 18 March 2015 at 14:55, Vincent Le Nir <vlenir.ciss.rma at gmail.com>
> wrote:
> > 2015-03-18 14:20 GMT+01:00 Dominic Spill <dominicgs at gmail.com>:
> >
> >> Have you tried switching between TX and RX without closing the device?
> >
> > I also tried this approach, but without closing the device I have another
> > error related to the problem that I cannot write or read from the
> transfer
> > buffer.
>
> Could you tell me what this error is?  It seems like this one might be
> more useful to solve for your issue.
>

Yes, the error is below.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffafffe700 (LWP 11456)]
0x000000000051c6d2 in HackRFDevice::callback_rx (transfer=0x7fffafffcef0)
    at ../CogWave_L2/Channel/hackrfdevice.cpp:43
43               hackrf_rx_buf[i] = (int8_t)transfer->buffer[i];
(gdb) backtrace
#0  0x000000000051c6d2 in HackRFDevice::callback_rx
(transfer=0x7fffafffcef0)
    at ../CogWave_L2/Channel/hackrfdevice.cpp:43
#1  0x00007ffff5e0a86e in hackrf_libusb_transfer_callback ()
   from /usr/local/lib/libhackrf.so.0
#2  0x00007ffff05d2648 in ?? () from /lib/x86_64-linux-gnu/libusb-1.0.so.0
#3  0x00007ffff05d7664 in ?? () from /lib/x86_64-linux-gnu/libusb-1.0.so.0
#4  0x00007ffff05d2358 in ?? () from /lib/x86_64-linux-gnu/libusb-1.0.so.0
#5  0x00007ffff05d2f03 in libusb_handle_events_timeout_completed ()
   from /lib/x86_64-linux-gnu/libusb-1.0.so.0
#6  0x00007ffff5e0a76e in transfer_threadproc ()
   from /usr/local/lib/libhackrf.so.0
#7  0x00007ffff36a50a5 in start_thread (arg=0x7fffafffe700)
    at pthread_create.c:309
#8  0x00007ffff2ba6cfd in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111


In this approach, I first initialize the hackrf using the following
function:
void HackRFDevice::init()
{
    hackrf=NULL;
    hackrf_init();
    hackrf_open(&hackrf);
    hackrf_set_freq(hackrf,uint64_t(rx_freq));
    hackrf_set_sample_rate(hackrf,rx_rate);
    hackrf_compute_baseband_filter_bw(uint32_t(0.75*rx_rate));
    hackrf_set_amp_enable(hackrf,rx_gain);
    hackrf_set_lna_gain(hackrf,uint32_t(16));
    hackrf_set_vga_gain(hackrf,uint32_t(20));
}

Then, read samples using the following function:
cvec HackRFDevice::readsamplesnow(int Nsamples){



    hackrf_rx_count=0;
    hackrf_rx_buffer_size=Nsamples*2;
    hackrf_rx_buf.resize(Nsamples*2);
    hackrf_start_rx(hackrf,callback_rx,NULL);


    while (hackrf_is_streaming (hackrf) != HACKRF_TRUE){
        cout << "waiting for streaming..." << endl;
    }
    while(hackrf_is_streaming (hackrf)==HACKRF_TRUE){
       if(hackrf_rx_count==Nsamples*2){
       break;
       }
    }
    cvec buffer;
    buffer.set_size(Nsamples);
    for (int i=0;i<Nsamples;i++) {

buffer[i]=complex<double>(((double)hackrf_rx_buf[(i<<1)])/128.0,((double)hackrf_rx_buf[(i<<1)+1])/128.0);
    }

    hackrf_stop_rx(hackrf);
    return buffer;

}

and with callback_rx

int HackRFDevice::callback_rx(hackrf_transfer* transfer){

    if(hackrf_rx_buffer_size!=0){
       for (int i=0; i<hackrf_rx_buffer_size; i++){
           hackrf_rx_buf[i] = (int8_t)transfer->buffer[i];
       }
       hackrf_rx_count = hackrf_rx_count + hackrf_rx_buffer_size;
    }
    return(0);

}


Opening and closing in readsamplesnow gives no direct errors but after
10-15 times it gives the LIBSUSB ERROR -1000.

cvec HackRFDevice::readsamplesnow(int Nsamples){


    hackrf=NULL;
    hackrf_init();
    hackrf_open(&hackrf);
    hackrf_set_freq(hackrf,uint64_t(rx_freq));
    hackrf_set_sample_rate(hackrf,rx_rate);
    hackrf_compute_baseband_filter_bw(uint32_t(0.75*rx_rate));
    hackrf_set_amp_enable(hackrf,rx_gain);
    hackrf_set_lna_gain(hackrf,uint32_t(16));
    hackrf_set_vga_gain(hackrf,uint32_t(20));
    hackrf_rx_count=0;
    hackrf_rx_buffer_size=Nsamples*2;
    hackrf_rx_buf.resize(Nsamples*2);
    hackrf_start_rx(hackrf,callback_rx,NULL);


    while (hackrf_is_streaming (hackrf) != HACKRF_TRUE){
        cout << "waiting for streaming..." << endl;
    }
    while(hackrf_is_streaming (hackrf)==HACKRF_TRUE){
       if(hackrf_rx_count==Nsamples*2){
       break;
       }
    }
    cvec buffer;
    buffer.set_size(Nsamples);
    for (int i=0;i<Nsamples;i++) {

buffer[i]=complex<double>(((double)hackrf_rx_buf[(i<<1)])/128.0,((double)hackrf_rx_buf[(i<<1)+1])/128.0);
    }

    hackrf_stop_rx(hackrf);
    hackrf_close(hackrf);

    return buffer;

}



> I think the hackrf_open() problem may be down to closing the device
> and what that causes libusb / the kernel to do to the device.  I don't
> know enough about this right now, but I can take a look.
>
> thanks,
>   Dominic
>

 Thanks,
Vincent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist9.pair.net/pipermail/hackrf-dev/attachments/20150319/23609e23/attachment.html>


More information about the HackRF-dev mailing list