From bc8d1d060c2ea9455b61dc8cdcc0288f275f4ee3 Mon Sep 17 00:00:00 2001 From: mrbubble62 Date: Mon, 2 Mar 2015 02:32:54 -0500 Subject: [PATCH 01/32] Update README.md --- host/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/host/README.md b/host/README.md index 56de42ed..e03c447d 100644 --- a/host/README.md +++ b/host/README.md @@ -51,15 +51,17 @@ Debug version: `make install` +###For Visual Studio 2012 x64 +`c:\hackrf\host\cmake>cmake ../ -G "Visual Studio 11 2012 Win64" -DLIBUSB_INCLUDE_DIR=c:\libusb-1.0.18-win\include\libusb-1.0 -DLIBUSB_LIBRARIES=c:\libusb-1.0.18-win\MS64\static\libusb-1.0.lib -DTHREADS_PTHREADS_INCLUDE_DIR=c:\pthreads-w32-2-9-1-release\Pre-built.2\include -DTHREADS_PTHREADS_WIN32_LIBRARY=c:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib` + +Solution file: `c:\hackrf\host\cmake\hackrf_all.sln` ##How to build the host software on Linux: ###Prerequisites for Linux (Debian/Ubuntu): - `sudo apt-get install build-essential cmake libusb-1.0-0-dev` - ###Build host software on Linux: `cd host` From 4592d38871e4250adf74ea8789ee0291538734d3 Mon Sep 17 00:00:00 2001 From: Tomasz CEDRO Date: Wed, 8 Apr 2015 03:16:39 +0200 Subject: [PATCH 02/32] Fixed pkgdata install path on FreeBSD. Signed-off-by: Tomasz CEDRO --- host/libhackrf/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index 4f1ec642..b5134f84 100644 --- a/host/libhackrf/CMakeLists.txt +++ b/host/libhackrf/CMakeLists.txt @@ -70,6 +70,11 @@ set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix \${prefix}) set(libdir \${exec_prefix}/lib${LIB_SUFFIX}) set(includedir \${prefix}/include) +set(libpkgdata "lib"${LIB_SUFFIX}) + +if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + set(libpkgdata "libdata") +endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/libhackrf.pc.in @@ -78,7 +83,7 @@ CONFIGURE_FILE( INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/libhackrf.pc - DESTINATION lib${LIB_SUFFIX}/pkgconfig + DESTINATION ${libpkgdata}/pkgconfig ) ######################################################################## From 4dc991e79dfd0b4bd4a4456da6df2c2c24152126 Mon Sep 17 00:00:00 2001 From: Tomasz CEDRO Date: Wed, 8 Apr 2015 03:27:43 +0200 Subject: [PATCH 03/32] Added information on FreeBSD build. Signed-off-by: Tomasz CEDRO --- host/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/host/README.md b/host/README.md index 56de42ed..1f3a0b13 100644 --- a/host/README.md +++ b/host/README.md @@ -52,6 +52,18 @@ Debug version: `make install` +##How to build host the software on FreeBSD + +[Tomek "CeDeROM" CEDRO](http://www.tomek.cedro.info) is working on a Port for you - stay tuned! :-) + +You can use the binary package: +`# pkg install hackrf` + +You can build and install from ports: +`# cd /usr/ports/comms/hackrf` +`# make install` + + ##How to build the host software on Linux: ###Prerequisites for Linux (Debian/Ubuntu): From de81c54e4e66c5df56dcd62ec476fcfeab7f415a Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Sun, 26 Apr 2015 16:54:22 +0100 Subject: [PATCH 04/32] Fix discovery of libusb 1.0 for FreeBSD --- host/cmake/modules/FindUSB1.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/host/cmake/modules/FindUSB1.cmake b/host/cmake/modules/FindUSB1.cmake index 0cbf8022..2f3138dc 100644 --- a/host/cmake/modules/FindUSB1.cmake +++ b/host/cmake/modules/FindUSB1.cmake @@ -24,10 +24,15 @@ else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) pkg_check_modules(PC_LIBUSB libusb-1.0) ENDIF(NOT WIN32) + set(LIBUSB_LIBRARY_NAME usb-1.0) + IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + set(LIBUSB_LIBRARY_NAME usb) + ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS}) - FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0 + FIND_LIBRARY(LIBUSB_LIBRARIES NAMES ${LIBUSB_LIBRARY_NAME} PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS}) include(FindPackageHandleStandardArgs) From ea46e4435ba36065d510575cd2976e788f141a4d Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Mon, 25 May 2015 17:31:53 -0700 Subject: [PATCH 05/32] explain which gain setting was wrong because sometimes you don't see your typos at 3am. --- host/hackrf-tools/src/hackrf_transfer.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 6c7b0441..36b53abc 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -582,6 +582,18 @@ int main(int argc, char** argv) { } } + if (lna_gain % 8) { + printf("argument error: lna_gain (-l) must be a multiple of 8\n"); + usage(); + return EXIT_FAILURE; + } + + if (vga_gain % 8) { + printf("argument error: vga_gain (-g) must be a multiple of 2\n"); + usage(); + return EXIT_FAILURE; + } + if (samples_to_xfer >= SAMPLES_TO_XFER_MAX) { printf("argument error: num_samples must be less than %s/%sMio\n", u64toa(SAMPLES_TO_XFER_MAX,&ascii_u64_data1), From 2570f35260e0351df56e271260797687b2c3b6d5 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Mon, 25 May 2015 17:38:24 -0700 Subject: [PATCH 06/32] vga gain must be a multiple of 2, not 8 allow both args to be checked before bailing out --- host/hackrf-tools/src/hackrf_transfer.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 36b53abc..61be1b2a 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -582,14 +582,12 @@ int main(int argc, char** argv) { } } - if (lna_gain % 8) { - printf("argument error: lna_gain (-l) must be a multiple of 8\n"); - usage(); - return EXIT_FAILURE; - } + if ((lna_gain % 8) || (vga_gain % 2)) { + if (lna_gain % 8) + printf("argument error: lna_gain (-l) must be a multiple of 8\n"); + if (vga_gain % 2) + printf("argument error: vga_gain (-g) must be a multiple of 2\n"); - if (vga_gain % 8) { - printf("argument error: vga_gain (-g) must be a multiple of 2\n"); usage(); return EXIT_FAILURE; } From faddb1b320d998b5c2cc452aed4b045f8e192973 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Fri, 29 May 2015 00:05:12 -0700 Subject: [PATCH 07/32] squish invalid gain values to acceptable levels --- host/libhackrf/src/hackrf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 790c8431..4eb87ae5 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -958,6 +958,7 @@ int ADDCALL hackrf_set_lna_gain(hackrf_device* device, uint32_t value) return HACKRF_ERROR_INVALID_PARAM; } + value &= ~(1<<3); result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, @@ -987,6 +988,7 @@ int ADDCALL hackrf_set_vga_gain(hackrf_device* device, uint32_t value) return HACKRF_ERROR_INVALID_PARAM; } + value &= ~(1<<0); result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, From 94b37453b79d2aceba329cb61b44605efa717522 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Fri, 29 May 2015 00:32:20 -0700 Subject: [PATCH 08/32] these don't need to be errors any more --- host/hackrf-tools/src/hackrf_transfer.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 61be1b2a..bd9bdb78 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -582,15 +582,11 @@ int main(int argc, char** argv) { } } - if ((lna_gain % 8) || (vga_gain % 2)) { - if (lna_gain % 8) - printf("argument error: lna_gain (-l) must be a multiple of 8\n"); - if (vga_gain % 2) - printf("argument error: vga_gain (-g) must be a multiple of 2\n"); + if (lna_gain % 8) + printf("warning: lna_gain (-l) must be a multiple of 8\n"); - usage(); - return EXIT_FAILURE; - } + if (vga_gain % 2) + printf("warning: vga_gain (-g) must be a multiple of 2\n"); if (samples_to_xfer >= SAMPLES_TO_XFER_MAX) { printf("argument error: num_samples must be less than %s/%sMio\n", From edf8c23cfd7a76815d70a72a1143664fb9154015 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Fri, 29 May 2015 09:25:24 -0700 Subject: [PATCH 09/32] Derp. That's what I get for hacking after bedtime... --- host/libhackrf/src/hackrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 4eb87ae5..85de4506 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -958,7 +958,7 @@ int ADDCALL hackrf_set_lna_gain(hackrf_device* device, uint32_t value) return HACKRF_ERROR_INVALID_PARAM; } - value &= ~(1<<3); + value &= ~0x07; result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, @@ -988,7 +988,7 @@ int ADDCALL hackrf_set_vga_gain(hackrf_device* device, uint32_t value) return HACKRF_ERROR_INVALID_PARAM; } - value &= ~(1<<0); + value &= ~0x01; result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, From 1acd6a6ad68159eb43ed46c73e6332ca5f4255fe Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 26 Jun 2015 17:50:27 +0100 Subject: [PATCH 10/32] Fix GitHub issue #163 - Detach the kernel driver automatically --- host/libhackrf/src/hackrf.c | 93 +++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 2902a800..2619ac49 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -69,6 +69,11 @@ typedef enum { HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24, } hackrf_vendor_request; +typedef enum { + USB_CONFIG_STANDARD = 0x1, + USB_CONFIG_CPLD_UPDATE = 0x2, +} hackrf_usb_configurations; + typedef enum { HACKRF_TRANSCEIVER_MODE_OFF = 0, HACKRF_TRANSCEIVER_MODE_RECEIVE = 1, @@ -233,6 +238,74 @@ static int prepare_transfers( } } +static int detach_kernel_drivers(libusb_device_handle* usb_device_handle) +{ + int i, result; + libusb_device* dev; + struct libusb_config_descriptor* config; + + dev = libusb_get_device(usb_device_handle); + result = libusb_get_active_config_descriptor(dev, &config); + if( result < 0 ) + { + return HACKRF_ERROR_LIBUSB; + } + + for(i=0; ibNumInterfaces; i++) + { + result = libusb_kernel_driver_active(usb_device_handle, i); + if( result < 0 ) + { + if( result == LIBUSB_ERROR_NOT_SUPPORTED ) { + return 0; + } + return HACKRF_ERROR_LIBUSB; + } else if( result == 1 ) { + result = libusb_detach_kernel_driver(usb_device_handle, i); + if( result != 0 ) + { + return HACKRF_ERROR_LIBUSB; + } + } + } + return HACKRF_SUCCESS; +} + +static int set_hackrf_configuration(libusb_device_handle* usb_device, int config) +{ + int result, curr_config; + result = libusb_get_configuration(usb_device, &curr_config); + if( result != 0 ) + { + libusb_close(usb_device); + return HACKRF_ERROR_LIBUSB; + } + + if(curr_config != config) + { + result = detach_kernel_drivers(usb_device); + if( result != 0 ) + { + libusb_close(usb_device); + return result; + } + result = libusb_set_configuration(usb_device, config); + if( result != 0 ) + { + libusb_close(usb_device); + return HACKRF_ERROR_LIBUSB; + } + } + + result = detach_kernel_drivers(usb_device); + if( result != 0 ) + { + libusb_close(usb_device); + return result; + } + return LIBUSB_SUCCESS; +} + #ifdef __cplusplus extern "C" { @@ -410,16 +483,15 @@ static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** d //int speed = libusb_get_device_speed(usb_device); // TODO: Error or warning if not high speed USB? - - result = libusb_set_configuration(usb_device, 1); - if( result != 0 ) + + result = set_hackrf_configuration(usb_device, USB_CONFIG_STANDARD); + if( result != LIBUSB_SUCCESS ) { - libusb_close(usb_device); - return HACKRF_ERROR_LIBUSB; + return result; } result = libusb_claim_interface(usb_device, 0); - if( result != 0 ) + if( result != LIBUSB_SUCCESS ) { libusb_close(usb_device); return HACKRF_ERROR_LIBUSB; @@ -842,10 +914,13 @@ int ADDCALL hackrf_cpld_write(hackrf_device* device, return HACKRF_ERROR_LIBUSB; } - result = libusb_set_configuration(device->usb_device, 2); - if (result != LIBUSB_SUCCESS) { - return HACKRF_ERROR_LIBUSB; + result = set_hackrf_configuration(device->usb_device, USB_CONFIG_CPLD_UPDATE); + if( result != LIBUSB_SUCCESS ) + { + return result; } + result = libusb_set_configuration(device->usb_device, 2); + result = libusb_claim_interface(device->usb_device, 0); if (result != LIBUSB_SUCCESS) { From f3a9e6692460c2c97e6329a6677d5c9921f36786 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Mon, 29 Jun 2015 13:08:41 +0100 Subject: [PATCH 11/32] Remove duplicate call to set configuration + tidy calls to libusb_close() --- host/libhackrf/src/hackrf.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 2619ac49..2c061f21 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -277,7 +277,6 @@ static int set_hackrf_configuration(libusb_device_handle* usb_device, int config result = libusb_get_configuration(usb_device, &curr_config); if( result != 0 ) { - libusb_close(usb_device); return HACKRF_ERROR_LIBUSB; } @@ -286,13 +285,11 @@ static int set_hackrf_configuration(libusb_device_handle* usb_device, int config result = detach_kernel_drivers(usb_device); if( result != 0 ) { - libusb_close(usb_device); return result; } result = libusb_set_configuration(usb_device, config); if( result != 0 ) { - libusb_close(usb_device); return HACKRF_ERROR_LIBUSB; } } @@ -300,7 +297,6 @@ static int set_hackrf_configuration(libusb_device_handle* usb_device, int config result = detach_kernel_drivers(usb_device); if( result != 0 ) { - libusb_close(usb_device); return result; } return LIBUSB_SUCCESS; @@ -487,6 +483,7 @@ static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** d result = set_hackrf_configuration(usb_device, USB_CONFIG_STANDARD); if( result != LIBUSB_SUCCESS ) { + libusb_close(usb_device); return result; } @@ -919,8 +916,6 @@ int ADDCALL hackrf_cpld_write(hackrf_device* device, { return result; } - result = libusb_set_configuration(device->usb_device, 2); - result = libusb_claim_interface(device->usb_device, 0); if (result != LIBUSB_SUCCESS) { From 9cfa4048e9abbe9a62bd794a9e2c1d0269b15fb2 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Mon, 29 Jun 2015 13:41:45 +0100 Subject: [PATCH 12/32] Free config descriptor once we have the number of interfaces --- host/libhackrf/src/hackrf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 2c061f21..6632fb41 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -240,7 +240,7 @@ static int prepare_transfers( static int detach_kernel_drivers(libusb_device_handle* usb_device_handle) { - int i, result; + int i, num_interfaces, result; libusb_device* dev; struct libusb_config_descriptor* config; @@ -251,7 +251,9 @@ static int detach_kernel_drivers(libusb_device_handle* usb_device_handle) return HACKRF_ERROR_LIBUSB; } - for(i=0; ibNumInterfaces; i++) + num_interfaces = config->bNumInterfaces; + libusb_free_config_descriptor(config); + for(i=0; i Date: Mon, 6 Jul 2015 21:25:01 +0100 Subject: [PATCH 13/32] Fix issue #113 - CPLD update fails on Windows Using the patch from @supersat --- firmware/common/hackrf_core.h | 4 +++- firmware/hackrf_usb/hackrf_usb.c | 5 +++++ host/hackrf-tools/src/hackrf_transfer.c | 7 ------- host/libhackrf/src/hackrf.c | 21 +++++---------------- host/libhackrf/src/hackrf.h | 8 ++++++++ 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/firmware/common/hackrf_core.h b/firmware/common/hackrf_core.h index 8ce6c943..e19829d6 100644 --- a/firmware/common/hackrf_core.h +++ b/firmware/common/hackrf_core.h @@ -345,7 +345,9 @@ extern "C" typedef enum { TRANSCEIVER_MODE_OFF = 0, TRANSCEIVER_MODE_RX = 1, - TRANSCEIVER_MODE_TX = 2 + TRANSCEIVER_MODE_TX = 2, + TRANSCEIVER_MODE_SS = 3, + TRANSCEIVER_MODE_CPLD_UPDATE = 4 } transceiver_mode_t; void delay(uint32_t duration); diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index e842d82b..c5ccb6ad 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -99,6 +99,11 @@ usb_request_status_t usb_vendor_request_set_transceiver_mode( set_transceiver_mode(endpoint->setup.value); usb_transfer_schedule_ack(endpoint->in); return USB_REQUEST_STATUS_OK; + case TRANSCEIVER_MODE_CPLD_UPDATE: + usb_endpoint_init(&usb_endpoint_bulk_out); + start_cpld_update = true; + usb_transfer_schedule_ack(endpoint->in); + return USB_REQUEST_STATUS_OK; default: return USB_REQUEST_STATUS_STALL; } diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index b76ae631..16e5456c 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -168,13 +168,6 @@ t_wav_file_hdr wave_file_hdr = } }; -typedef enum { - TRANSCEIVER_MODE_OFF = 0, - TRANSCEIVER_MODE_RX = 1, - TRANSCEIVER_MODE_TX = 2, - TRANSCEIVER_MODE_SS = 3 - -} transceiver_mode_t; static transceiver_mode_t transceiver_mode = TRANSCEIVER_MODE_RX; #define U64TOA_MAX_DIGIT (31) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 6632fb41..e68c7195 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -907,23 +907,12 @@ int ADDCALL hackrf_cpld_write(hackrf_device* device, { const unsigned int chunk_size = 512; unsigned int i; - int transferred = 0; - int result = libusb_release_interface(device->usb_device, 0); - if (result != LIBUSB_SUCCESS) { - return HACKRF_ERROR_LIBUSB; - } - - result = set_hackrf_configuration(device->usb_device, USB_CONFIG_CPLD_UPDATE); - if( result != LIBUSB_SUCCESS ) - { + int result, transferred = 0; + + result = hackrf_set_transceiver_mode(device, TRANSCEIVER_MODE_CPLD_UPDATE); + if (result != 0) return result; - } - - result = libusb_claim_interface(device->usb_device, 0); - if (result != LIBUSB_SUCCESS) { - return HACKRF_ERROR_LIBUSB; - } - + for (i = 0; i < total_length; i += chunk_size) { result = libusb_bulk_transfer( diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 6f043444..503e4ec3 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -81,6 +81,14 @@ enum rf_path_filter { RF_PATH_FILTER_HIGH_PASS = 2, }; +typedef enum { + TRANSCEIVER_MODE_OFF = 0, + TRANSCEIVER_MODE_RX = 1, + TRANSCEIVER_MODE_TX = 2, + TRANSCEIVER_MODE_SS = 3, + TRANSCEIVER_MODE_CPLD_UPDATE = 4 +} transceiver_mode_t; + typedef struct hackrf_device hackrf_device; typedef struct { From d3ce4779e90ecca6f340532323b546489c325c6f Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Tue, 7 Jul 2015 07:23:48 +0100 Subject: [PATCH 14/32] Fix inconsistent indentation --- firmware/common/hackrf_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/common/hackrf_core.h b/firmware/common/hackrf_core.h index e19829d6..bad03a40 100644 --- a/firmware/common/hackrf_core.h +++ b/firmware/common/hackrf_core.h @@ -347,7 +347,7 @@ typedef enum { TRANSCEIVER_MODE_RX = 1, TRANSCEIVER_MODE_TX = 2, TRANSCEIVER_MODE_SS = 3, - TRANSCEIVER_MODE_CPLD_UPDATE = 4 + TRANSCEIVER_MODE_CPLD_UPDATE = 4 } transceiver_mode_t; void delay(uint32_t duration); From 2ca87b942ade68d11a85f41c201f29d2966f6d2f Mon Sep 17 00:00:00 2001 From: scateu Date: Wed, 8 Jul 2015 18:44:22 +0800 Subject: [PATCH 15/32] Add file repeat TX mode [-R]. --- host/hackrf-tools/src/hackrf_transfer.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 16e5456c..a52bdab4 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -330,6 +330,8 @@ size_t bytes_to_xfer = 0; bool baseband_filter_bw = false; uint32_t baseband_filter_bw_hz = 0; +bool repeat = false; + int rx_callback(hackrf_transfer* transfer) { size_t bytes_to_write; int i; @@ -385,7 +387,15 @@ int tx_callback(hackrf_transfer* transfer) { bytes_read = fread(transfer->buffer, 1, bytes_to_read, fd); if ((bytes_read != bytes_to_read) || (limit_num_samples && (bytes_to_xfer == 0))) { - return -1; + if (repeat) { // added by scateu. repeat mode. + printf("Input file end reached. Rewind to beginning.\n"); + rewind(fd); + fread(transfer->buffer + bytes_read, 1, bytes_to_read - bytes_read, fd); + return 0; + } else { + return -1; // not loopback mode, EOF + } + } else { return 0; } @@ -439,6 +449,7 @@ static void usage() { u64toa((DEFAULT_SAMPLE_RATE_HZ/FREQ_ONE_MHZ),&ascii_u64_data1)); printf("\t[-n num_samples] # Number of samples to transfer (default is unlimited).\n"); printf("\t[-c amplitude] # CW signal source mode, amplitude 0-127 (DC value to DAC).\n"); + printf("\t[-R] # Repeat TX mode (default is off) \n"); printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in MHz.\n\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default < sample_rate_hz.\n" ); } @@ -481,7 +492,7 @@ int main(int argc, char** argv) { float time_diff; unsigned int lna_gain=8, vga_gain=20, txvga_gain=0; - while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:")) != EOF ) + while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:R")) != EOF ) { result = HACKRF_SUCCESS; switch( opt ) @@ -568,6 +579,10 @@ int main(int argc, char** argv) { result = parse_u32(optarg, &litude); break; + case 'R': + repeat = true; + break; + default: printf("unknown argument '-%c %s'\n", opt, optarg); usage(); From 05416031c209a6c81fe3a2ac40d3acbd6ce1d960 Mon Sep 17 00:00:00 2001 From: Peter Shipley Date: Mon, 15 Sep 2014 22:28:32 -0700 Subject: [PATCH 16/32] ChunkSize should be size entire file in bytes minus 8 bytes Ref : https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ --- host/hackrf-tools/src/hackrf_transfer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 16e5456c..f64bd38e 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -984,7 +984,7 @@ int main(int argc, char** argv) { /* Get size of file */ file_pos = ftell(fd); /* Update Wav Header */ - wave_file_hdr.hdr.size = file_pos+8; + wave_file_hdr.hdr.size = file_pos-8; wave_file_hdr.fmt_chunk.dwSamplesPerSec = sample_rate_hz; wave_file_hdr.fmt_chunk.dwAvgBytesPerSec = wave_file_hdr.fmt_chunk.dwSamplesPerSec*2; wave_file_hdr.data_chunk.chunkSize = file_pos - sizeof(t_wav_file_hdr); From af13e756d9afd4e6af6958413559828e81d03501 Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Wed, 8 Jul 2015 16:37:28 -0600 Subject: [PATCH 17/32] turn off RF amplifier at end of transmission, fixes bug #178 --- firmware/common/rf_path.c | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/common/rf_path.c b/firmware/common/rf_path.c index 46aaac44..f33bebb1 100644 --- a/firmware/common/rf_path.c +++ b/firmware/common/rf_path.c @@ -266,6 +266,7 @@ void rf_path_set_direction(const rf_path_direction_t direction) { #ifdef HACKRF_ONE rf_path_set_antenna(0); #endif + rf_path_set_lna(0); /* Set RF path to receive direction when "off" */ switchctrl &= ~SWITCHCTRL_TX; rffc5071_disable(); From 8cfa81f40ce397f24d4cf31c4f018dac74395688 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 10 Jul 2015 10:32:55 -0700 Subject: [PATCH 18/32] Add hackrf_spiflash verbose option, make default not-verbose. --- host/hackrf-tools/src/hackrf_spiflash.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_spiflash.c b/host/hackrf-tools/src/hackrf_spiflash.c index f210f370..098d2ade 100644 --- a/host/hackrf-tools/src/hackrf_spiflash.c +++ b/host/hackrf-tools/src/hackrf_spiflash.c @@ -51,6 +51,7 @@ static struct option long_options[] = { { "length", required_argument, 0, 'l' }, { "read", required_argument, 0, 'r' }, { "write", required_argument, 0, 'w' }, + { "verbose", no_argument, 0, 'v' }, { 0, 0, 0, 0 }, }; @@ -90,6 +91,7 @@ static void usage() printf("\t-r : Read data into file.\n"); printf("\t-w : Write data from file.\n"); printf("\t-d : Serial number of device, if multiple devices\n"); + printf("\t-v: Verbose output.\n"); } int main(int argc, char** argv) @@ -109,8 +111,9 @@ int main(int argc, char** argv) FILE* fd = NULL; bool read = false; bool write = false; + bool verbose = false; - while ((opt = getopt_long(argc, argv, "a:l:r:w:d:", long_options, + while ((opt = getopt_long(argc, argv, "a:l:r:w:d:v", long_options, &option_index)) != EOF) { switch (opt) { case 'a': @@ -135,6 +138,10 @@ int main(int argc, char** argv) serial_number = optarg; break; + case 'v': + verbose = true; + break; + default: fprintf(stderr, "opt error: %d\n", opt); usage(); @@ -233,7 +240,7 @@ int main(int argc, char** argv) while (tmp_length) { xfer_len = (tmp_length > 256) ? 256 : tmp_length; - printf("Reading %d bytes from 0x%06x.\n", xfer_len, address); + if( verbose ) printf("Reading %d bytes from 0x%06x.\n", xfer_len, address); result = hackrf_spiflash_read(device, address, xfer_len, pdata); if (result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_spiflash_read() failed: %s (%d)\n", @@ -272,9 +279,10 @@ int main(int argc, char** argv) fd = NULL; return EXIT_FAILURE; } + if( !verbose ) printf("Writing %d bytes at 0x%06x.\n", length, address); while (length) { xfer_len = (length > 256) ? 256 : length; - printf("Writing %d bytes at 0x%06x.\n", xfer_len, address); + if( verbose ) printf("Writing %d bytes at 0x%06x.\n", xfer_len, address); result = hackrf_spiflash_write(device, address, xfer_len, pdata); if (result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_spiflash_write() failed: %s (%d)\n", From d4767589c3a27004af61be3f0f6784afad918ae3 Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Sat, 11 Jul 2015 11:51:56 +0100 Subject: [PATCH 19/32] Fix KiCad files being detected as Eagle files --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..cd8ca813 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.brd linguist-language=KiCad From a1cbec96c6063c435d0dd091cf8369c6700ec5ff Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Thu, 16 Jul 2015 08:35:32 -0600 Subject: [PATCH 20/32] credit for lines of code belongs in commit log --- host/hackrf-tools/src/hackrf_transfer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 8b1adda0..9aac6a6e 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -387,7 +387,7 @@ int tx_callback(hackrf_transfer* transfer) { bytes_read = fread(transfer->buffer, 1, bytes_to_read, fd); if ((bytes_read != bytes_to_read) || (limit_num_samples && (bytes_to_xfer == 0))) { - if (repeat) { // added by scateu. repeat mode. + if (repeat) { printf("Input file end reached. Rewind to beginning.\n"); rewind(fd); fread(transfer->buffer + bytes_read, 1, bytes_to_read - bytes_read, fd); From 8cd0cf1b0e0b94f39cd9d65650e095c3f69882fb Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Tue, 21 Jul 2015 16:42:24 +0100 Subject: [PATCH 21/32] Use rad1o's PID --- host/libhackrf/53-hackrf.rules | 1 + host/libhackrf/src/hackrf.c | 14 ++++++++++++-- host/libhackrf/src/hackrf.h | 1 + host/misc/udev/53-hackrf.rules.in | 2 ++ host/python/max2837_dump.py | 4 ++++ host/python/set_transceiver_mode.py | 8 ++++++-- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/host/libhackrf/53-hackrf.rules b/host/libhackrf/53-hackrf.rules index 0338ea8c..a982f4a4 100644 --- a/host/libhackrf/53-hackrf.rules +++ b/host/libhackrf/53-hackrf.rules @@ -1,3 +1,4 @@ ATTR{idVendor}=="1d50", ATTR{idProduct}=="604b", SYMLINK+="hackrf-jawbreaker-%k", MODE="660", GROUP="plugdev" ATTR{idVendor}=="1d50", ATTR{idProduct}=="6089", SYMLINK+="hackrf-one-%k", MODE="660", GROUP="plugdev" +ATTR{idVendor}=="1d50", ATTR{idProduct}=="cc15", SYMLINK+="rad1o-%k", MODE="660", GROUP="plugdev" ATTR{idVendor}=="1fc9", ATTR{idProduct}=="000c", SYMLINK+="nxp-dfu-%k", MODE="660", GROUP="plugdev" diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 4471cace..dcba7f65 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -122,6 +122,7 @@ volatile bool do_exit = false; static const uint16_t hackrf_usb_vid = 0x1d50; static const uint16_t hackrf_jawbreaker_usb_pid = 0x604b; static const uint16_t hackrf_one_usb_pid = 0x6089; +static const uint16_t rad1o_usb_pid = 0xcc15; static libusb_context* g_libusb_context = NULL; @@ -362,7 +363,9 @@ hackrf_device_list_t* ADDCALL hackrf_device_list() libusb_get_device_descriptor(list->usb_devices[i], &device_descriptor); if( device_descriptor.idVendor == hackrf_usb_vid ) { - if( (device_descriptor.idProduct == hackrf_one_usb_pid) || (device_descriptor.idProduct == hackrf_jawbreaker_usb_pid) ) { + if((device_descriptor.idProduct == hackrf_one_usb_pid) || + (device_descriptor.idProduct == hackrf_jawbreaker_usb_pid) || + (device_descriptor.idProduct == rad1o_usb_pid)) { int idx = list->devicecount++; list->usb_board_ids[idx] = device_descriptor.idProduct; list->usb_device_index[idx] = i; @@ -431,7 +434,9 @@ libusb_device_handle* hackrf_open_usb(const char* const desired_serial_number) libusb_get_device_descriptor(devices[i], &device_descriptor); if( device_descriptor.idVendor == hackrf_usb_vid ) { - if( (device_descriptor.idProduct == hackrf_one_usb_pid) || (device_descriptor.idProduct == hackrf_jawbreaker_usb_pid) ) { + if((device_descriptor.idProduct == hackrf_one_usb_pid) || + (device_descriptor.idProduct == hackrf_jawbreaker_usb_pid) || + (device_descriptor.idProduct == rad1o_usb_pid)) { printf("USB device %4x:%4x:", device_descriptor.idVendor, device_descriptor.idProduct); if( desired_serial_number != NULL ) { @@ -548,6 +553,11 @@ int ADDCALL hackrf_open(hackrf_device** device) usb_device = libusb_open_device_with_vid_pid(g_libusb_context, hackrf_usb_vid, hackrf_jawbreaker_usb_pid); } + if( usb_device == NULL ) + { + usb_device = libusb_open_device_with_vid_pid(g_libusb_context, hackrf_usb_vid, rad1o_usb_pid); + } + if( usb_device == NULL ) { return HACKRF_ERROR_NOT_FOUND; diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 503e4ec3..a73d7555 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -72,6 +72,7 @@ enum hackrf_board_id { enum hackrf_usb_board_id { USB_BOARD_ID_JAWBREAKER = 0x604B, USB_BOARD_ID_HACKRF_ONE = 0x6089, + USB_BOARD_ID_RAD1O = 0xCC15, USB_BOARD_ID_INVALID = 0xFFFF, }; diff --git a/host/misc/udev/53-hackrf.rules.in b/host/misc/udev/53-hackrf.rules.in index 951c424d..05144a7f 100644 --- a/host/misc/udev/53-hackrf.rules.in +++ b/host/misc/udev/53-hackrf.rules.in @@ -2,5 +2,7 @@ ATTR{idVendor}=="1d50", ATTR{idProduct}=="604b", SYMLINK+="hackrf-jawbreaker-%k", MODE="660", GROUP="@HACKRF_GROUP@" # HackRF One ATTR{idVendor}=="1d50", ATTR{idProduct}=="6089", SYMLINK+="hackrf-one-%k", MODE="660", GROUP="@HACKRF_GROUP@" +# HackRF One +ATTR{idVendor}=="1d50", ATTR{idProduct}=="CC15", SYMLINK+="rad1o-%k", MODE="660", GROUP="@HACKRF_GROUP@" # HackRF DFU ATTR{idVendor}=="1fc9", ATTR{idProduct}=="000c", SYMLINK+="nxp-dfu-%k", MODE="660", GROUP="@HACKRF_GROUP@" diff --git a/host/python/max2837_dump.py b/host/python/max2837_dump.py index c1732b2e..d0e80f48 100755 --- a/host/python/max2837_dump.py +++ b/host/python/max2837_dump.py @@ -32,6 +32,10 @@ else: if device: print 'Find: HackRF One' else: + device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15) + if device: + print 'Find: Rad1o' + else: print 'Not find any HackRF device.' sys.exit() device.set_configuration() diff --git a/host/python/set_transceiver_mode.py b/host/python/set_transceiver_mode.py index c1307532..fe013709 100755 --- a/host/python/set_transceiver_mode.py +++ b/host/python/set_transceiver_mode.py @@ -31,8 +31,12 @@ else: if device: print 'Find: HackRF One' else: - print 'Not find any HackRF device.' - sys.exit() + device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15) + if device: + print 'Find: Rad1o' + else: + print 'Not find any HackRF device.' + sys.exit() device.set_configuration() def set_rx(): From 512156de43d86f79d12ade8a6a3d6d018f751dd3 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Thu, 23 Jul 2015 19:12:40 +0100 Subject: [PATCH 22/32] Sort readme install instructions --- host/README.md | 59 ++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/host/README.md b/host/README.md index e31c5e8e..979ade33 100644 --- a/host/README.md +++ b/host/README.md @@ -1,6 +1,34 @@ This repository contains host software (Linux/Windows) for HackRF, a project to produce a low cost, open source software radio platform. +##How to build the host software on Linux: + +###Prerequisites for Linux (Debian/Ubuntu): + +`sudo apt-get install build-essential cmake libusb-1.0-0-dev` + +###Build host software on Linux: + +`cd host` + +`mkdir build` + +`cd build` + +`cmake ../ -DINSTALL_UDEV_RULES=ON` + +`make` + +`sudo make install` + +`sudo ldconfig` + +##Clean CMake temporary files/dirs: + +`cd host/build` + +`rm -rf *` + ##How to build host software on Windows: ###Prerequisites for cygwin or mingw: @@ -58,8 +86,6 @@ Solution file: `c:\hackrf\host\cmake\hackrf_all.sln` ##How to build host the software on FreeBSD -[Tomek "CeDeROM" CEDRO](http://www.tomek.cedro.info) is working on a Port for you - stay tuned! :-) - You can use the binary package: `# pkg install hackrf` @@ -68,35 +94,6 @@ You can build and install from ports: `# make install` -##How to build the host software on Linux: - -###Prerequisites for Linux (Debian/Ubuntu): - -`sudo apt-get install build-essential cmake libusb-1.0-0-dev` - -###Build host software on Linux: - -`cd host` - -`mkdir build` - -`cd build` - -`cmake ../ -DINSTALL_UDEV_RULES=ON` - -`make` - -`sudo make install` - -`sudo ldconfig` - -##Clean CMake temporary files/dirs: - -`cd host/build` - -`rm -rf *` - - principal author: Michael Ossmann http://greatscottgadgets.com/hackrf/ From c4450ad73f4a9cb3cb34baf563a0414b1b6d988a Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Thu, 23 Jul 2015 22:08:44 -0600 Subject: [PATCH 23/32] bumped .so and .pc version numbers to 0.4 --- host/hackrf-tools/CMakeLists.txt | 2 +- host/libhackrf/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/host/hackrf-tools/CMakeLists.txt b/host/hackrf-tools/CMakeLists.txt index d9f126fb..cc7ff9be 100644 --- a/host/hackrf-tools/CMakeLists.txt +++ b/host/hackrf-tools/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 2.8) project(hackrf-tools C) set(MAJOR_VERSION 0) -set(MINOR_VERSION 3) +set(MINOR_VERSION 4) set(PACKAGE hackrf-tools) set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}) set(VERSION ${VERSION_STRING}) diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index a248f42a..af8316c8 100644 --- a/host/libhackrf/CMakeLists.txt +++ b/host/libhackrf/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 2.8) project(libhackrf C) set(MAJOR_VERSION 0) -set(MINOR_VERSION 3) +set(MINOR_VERSION 4) set(PACKAGE libhackrf) set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}) set(VERSION ${VERSION_STRING}) From 4da9400c5b7552ced66f209087c564340f64d83b Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Fri, 24 Jul 2015 09:16:15 -0600 Subject: [PATCH 24/32] cmake bug fix from roox --- host/libhackrf/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index af8316c8..296ce95c 100644 --- a/host/libhackrf/CMakeLists.txt +++ b/host/libhackrf/CMakeLists.txt @@ -70,7 +70,7 @@ set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix \${prefix}) set(libdir \${exec_prefix}/lib${LIB_SUFFIX}) set(includedir \${prefix}/include) -set(libpkgdata "lib"${LIB_SUFFIX}) +set(libpkgdata lib${LIB_SUFFIX}) if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") set(libpkgdata "libdata") From 059c1cc2a706960a9248ec2d42059172eb4ffc3d Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 24 Jul 2015 16:50:43 +0100 Subject: [PATCH 25/32] Move udev rule to libhackrf/ --- host/CMakeLists.txt | 1 - .../udev => libhackrf}/53-hackrf.rules.in | 0 host/libhackrf/CMakeLists.txt | 64 +++++++++++++++++++ host/misc/CMakeLists.txt | 2 - host/misc/udev/CMakeLists.txt | 61 ------------------ 5 files changed, 64 insertions(+), 64 deletions(-) rename host/{misc/udev => libhackrf}/53-hackrf.rules.in (100%) delete mode 100644 host/misc/CMakeLists.txt delete mode 100644 host/misc/udev/CMakeLists.txt diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 52350c32..874163f8 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -5,7 +5,6 @@ project (hackrf_all) add_subdirectory(libhackrf) add_subdirectory(hackrf-tools) -add_subdirectory(misc) ######################################################################## # Create uninstall target diff --git a/host/misc/udev/53-hackrf.rules.in b/host/libhackrf/53-hackrf.rules.in similarity index 100% rename from host/misc/udev/53-hackrf.rules.in rename to host/libhackrf/53-hackrf.rules.in diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index 296ce95c..c898d233 100644 --- a/host/libhackrf/CMakeLists.txt +++ b/host/libhackrf/CMakeLists.txt @@ -86,6 +86,70 @@ INSTALL( DESTINATION ${libpkgdata}/pkgconfig ) +######################################################################## +# Create Pkg Config File +######################################################################## + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + SET(SYSTEM_IS_LINUX TRUE) + SET(UDEV_OPTION_DEFAULT ON) +else() + SET(SYSTEM_IS_LINUX FALSE) + SET(UDEV_OPTION_DEFAULT OFF) +endif() + +option(INSTALL_UDEV_RULES + "Install udev rules for the HackRF" + ${UDEV_OPTION_DEFAULT} +) + +set(UDEV_RULES_PATH + "/etc/udev/rules.d" + CACHE STRING + "Target directory for udev rule installation. Ensure you have permissions to write to this directory." +) + +if(SYSTEM_IS_LINUX) + if(INSTALL_UDEV_RULES) + if(NOT DEFINED UDEV_RULES_GROUP) + foreach(group usb plugdev) + execute_process(COMMAND "getent" group "${group}" + RESULT_VARIABLE _GETENT_RESULT + OUTPUT_QUIET + ERROR_QUIET) + if(NOT _GETENT_RESULT) + message(STATUS "Setting udev rule group to - ${group}") + set(UDEV_RULES_GROUP ${group}) + break() + endif(NOT _GETENT_RESULT) + endforeach(group) + endif(NOT DEFINED UDEV_RULES_GROUP) + if(DEFINED UDEV_RULES_GROUP) + set(HACKRF_GROUP "${UDEV_RULES_GROUP}" + CACHE STRING "Group to associate HackRF devices with in udev rules") + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/53-hackrf.rules.in + ${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules + @ONLY + ) + message(STATUS "HackRF udev rules will be installed to '${UDEV_RULES_PATH}' upon running 'make install'") + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules + DESTINATION ${UDEV_RULES_PATH} + COMPONENT "udev_rules") + else(UDEV_RULES_GROUP) + message(STATUS "HackRF udev rules will not be installed because no suitable group was found") + message(STATUS "A group can be specified with -DUDEV_RULES_GROUP=") + endif(DEFINED UDEV_RULES_GROUP) + else(INSTALL_UDEV_RULES) + message(STATUS + "HackRF udev rules will not be installed because INSTALL_UDEV_RULES=OFF" + ) + endif(INSTALL_UDEV_RULES) +else(SYSTEM_IS_LINUX) + if(INSTALL_UDEV_RULES) + message(STATUS "udev rules not supported on this platform. Hide this message via -DINSTALL_UDEV_RULES=Off") + endif(INSTALL_UDEV_RULES) +endif(SYSTEM_IS_LINUX) + ######################################################################## # Create uninstall target ######################################################################## diff --git a/host/misc/CMakeLists.txt b/host/misc/CMakeLists.txt deleted file mode 100644 index f728056f..00000000 --- a/host/misc/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -add_subdirectory(udev) diff --git a/host/misc/udev/CMakeLists.txt b/host/misc/udev/CMakeLists.txt deleted file mode 100644 index 1d65e63f..00000000 --- a/host/misc/udev/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - SET(SYSTEM_IS_LINUX TRUE) - SET(UDEV_OPTION_DEFAULT ON) -else() - SET(SYSTEM_IS_LINUX FALSE) - SET(UDEV_OPTION_DEFAULT OFF) -endif() - -option(INSTALL_UDEV_RULES - "Install udev rules for the HackRF" - ${UDEV_OPTION_DEFAULT} -) - -set(UDEV_RULES_PATH - "/etc/udev/rules.d" - CACHE STRING - "Target directory for udev rule installation. Ensure you have permissions to write to this directory." -) - -if(SYSTEM_IS_LINUX) - if(INSTALL_UDEV_RULES) - if(NOT DEFINED UDEV_RULES_GROUP) - foreach(group usb plugdev) - execute_process(COMMAND "getent" group "${group}" - RESULT_VARIABLE _GETENT_RESULT - OUTPUT_QUIET - ERROR_QUIET) - if(NOT _GETENT_RESULT) - message(STATUS "Setting udev rule group to - ${group}") - set(UDEV_RULES_GROUP ${group}) - break() - endif(NOT _GETENT_RESULT) - endforeach(group) - endif(NOT DEFINED UDEV_RULES_GROUP) - if(DEFINED UDEV_RULES_GROUP) - set(HACKRF_GROUP "${UDEV_RULES_GROUP}" - CACHE STRING "Group to associate HackRF devices with in udev rules") - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/53-hackrf.rules.in - ${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules - @ONLY - ) - message(STATUS "HackRF udev rules will be installed to '${UDEV_RULES_PATH}' upon running 'make install'") - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules - DESTINATION ${UDEV_RULES_PATH} - COMPONENT "udev_rules") - else(UDEV_RULES_GROUP) - message(STATUS "HackRF udev rules will not be installed because no suitable group was found") - message(STATUS "A group can be specified with -DUDEV_RULES_GROUP=") - endif(DEFINED UDEV_RULES_GROUP) - else(INSTALL_UDEV_RULES) - message(STATUS - "HackRF udev rules will not be installed because INSTALL_UDEV_RULES=OFF" - ) - endif(INSTALL_UDEV_RULES) -else(SYSTEM_IS_LINUX) - if(INSTALL_UDEV_RULES) - message(STATUS "udev rules not supported on this platform. Hide this message via -DINSTALL_UDEV_RULES=Off") - endif(INSTALL_UDEV_RULES) -endif(SYSTEM_IS_LINUX) From 499c8bc09e32fc4758ff78e8072ff586830f14ee Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Sat, 25 Jul 2015 09:42:47 +0100 Subject: [PATCH 26/32] Update build instructions to include pkg-config --- host/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/README.md b/host/README.md index 979ade33..e3d47989 100644 --- a/host/README.md +++ b/host/README.md @@ -5,7 +5,7 @@ produce a low cost, open source software radio platform. ###Prerequisites for Linux (Debian/Ubuntu): -`sudo apt-get install build-essential cmake libusb-1.0-0-dev` +`sudo apt-get install build-essential cmake libusb-1.0-0-dev`pkg-config ###Build host software on Linux: From 90e16536130fdc88c3b8a039acc1b7218783973d Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Sat, 25 Jul 2015 09:45:50 +0100 Subject: [PATCH 27/32] Update build instructions to include pkg-config --- host/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/README.md b/host/README.md index e3d47989..6b7f8bb4 100644 --- a/host/README.md +++ b/host/README.md @@ -5,7 +5,7 @@ produce a low cost, open source software radio platform. ###Prerequisites for Linux (Debian/Ubuntu): -`sudo apt-get install build-essential cmake libusb-1.0-0-dev`pkg-config +`sudo apt-get install build-essential cmake libusb-1.0-0-dev pkg-config` ###Build host software on Linux: From f5a3692a66f81694d92ed2e580e3d2c0e24b9a93 Mon Sep 17 00:00:00 2001 From: "Patrick C. F. Ernzer" Date: Tue, 25 Aug 2015 12:13:47 +0200 Subject: [PATCH 28/32] rad1o USB idProduct cleanups - udev rule should be lowercase (https://github.com/rad1o/f1rmware/pull/29) - add entries for rad1o storage from https://github.com/rad1o/f1rmware/blob/master/smartflash/90-rad1o-flash.rules - Rad1o -> rad1o - hackrf.h was NOT adjusted to lowercase cc15 --- host/libhackrf/53-hackrf.rules.in | 11 ++++++++--- host/python/max2837_dump.py | 4 ++-- host/python/set_transceiver_mode.py | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/host/libhackrf/53-hackrf.rules.in b/host/libhackrf/53-hackrf.rules.in index 05144a7f..9f98eb55 100644 --- a/host/libhackrf/53-hackrf.rules.in +++ b/host/libhackrf/53-hackrf.rules.in @@ -2,7 +2,12 @@ ATTR{idVendor}=="1d50", ATTR{idProduct}=="604b", SYMLINK+="hackrf-jawbreaker-%k", MODE="660", GROUP="@HACKRF_GROUP@" # HackRF One ATTR{idVendor}=="1d50", ATTR{idProduct}=="6089", SYMLINK+="hackrf-one-%k", MODE="660", GROUP="@HACKRF_GROUP@" -# HackRF One -ATTR{idVendor}=="1d50", ATTR{idProduct}=="CC15", SYMLINK+="rad1o-%k", MODE="660", GROUP="@HACKRF_GROUP@" -# HackRF DFU +# rad1o +ATTR{idVendor}=="1d50", ATTR{idProduct}=="cc15", SYMLINK+="rad1o-%k", MODE="660", GROUP="@HACKRF_GROUP@" +# NXP Semiconductors DFU mode (HackRF and rad1o) ATTR{idVendor}=="1fc9", ATTR{idProduct}=="000c", SYMLINK+="nxp-dfu-%k", MODE="660", GROUP="@HACKRF_GROUP@" +# rad1o "full flash" mode +KERNEL=="sd?", SUBSYSTEM=="block", ENV{ID_VENDOR_ID}=="1fc9", ENV{ID_MODEL_ID}=="0042", SYMLINK+="rad1o-flash-%k", MODE="660", GROUP="@HACKRF_GROUP@" +# rad1o flash disk +KERNEL=="sd?", SUBSYSTEM=="block", ENV{ID_VENDOR_ID}=="1fc9", ENV{ID_MODEL_ID}=="0082", SYMLINK+="rad1o-msc-%k", MODE="660", GROUP="@HACKRF_GROUP@" +# diff --git a/host/python/max2837_dump.py b/host/python/max2837_dump.py index d0e80f48..6624737b 100755 --- a/host/python/max2837_dump.py +++ b/host/python/max2837_dump.py @@ -32,9 +32,9 @@ else: if device: print 'Find: HackRF One' else: - device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15) + device = usb.core.find(idVendor=0x1d50, idProduct=0xcc15) if device: - print 'Find: Rad1o' + print 'Find: rad1o' else: print 'Not find any HackRF device.' sys.exit() diff --git a/host/python/set_transceiver_mode.py b/host/python/set_transceiver_mode.py index fe013709..f12a8976 100755 --- a/host/python/set_transceiver_mode.py +++ b/host/python/set_transceiver_mode.py @@ -31,9 +31,9 @@ else: if device: print 'Find: HackRF One' else: - device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15) + device = usb.core.find(idVendor=0x1d50, idProduct=0xcc15) if device: - print 'Find: Rad1o' + print 'Find: rad1o' else: print 'Not find any HackRF device.' sys.exit() From 7c98d3e14bb68686acfdf67b6642a7012c7dd4da Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 28 Aug 2015 12:48:05 -0700 Subject: [PATCH 29/32] Add W25Q80BV function to fast-read from device. --- firmware/common/w25q80bv.c | 22 ++++++++++++++++++++++ firmware/common/w25q80bv.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/firmware/common/w25q80bv.c b/firmware/common/w25q80bv.c index 2b391d9d..f49ffe3f 100644 --- a/firmware/common/w25q80bv.c +++ b/firmware/common/w25q80bv.c @@ -243,3 +243,25 @@ void w25q80bv_program(uint32_t addr, uint32_t len, const uint8_t* data) w25q80bv_page_program(addr, len, data); } } + +void w25q80bv_read(uint32_t addr, uint32_t len, uint8_t* const data) +{ + uint32_t i; + + /* do nothing if we would overflow the flash */ + if ((len > W25Q80BV_NUM_BYTES) || (addr > W25Q80BV_NUM_BYTES) + || ((addr + len) > W25Q80BV_NUM_BYTES)) + return; + + w25q80bv_wait_while_busy(); + + gpio_clear(PORT_SSP0_SSEL, PIN_SSP0_SSEL); + ssp_transfer(SSP0_NUM, W25Q80BV_FAST_READ); + ssp_transfer(SSP0_NUM, (addr >> 16) & 0xFF); + ssp_transfer(SSP0_NUM, (addr >> 8) & 0xFF); + ssp_transfer(SSP0_NUM, (addr >> 0) & 0xFF); + ssp_transfer(SSP0_NUM, 0xFF); + for (i = 0; i < len; i++) + data[i] = ssp_transfer(SSP0_NUM, 0xFF); + gpio_set(PORT_SSP0_SSEL, PIN_SSP0_SSEL); +} diff --git a/firmware/common/w25q80bv.h b/firmware/common/w25q80bv.h index b11a466a..5eda749d 100644 --- a/firmware/common/w25q80bv.h +++ b/firmware/common/w25q80bv.h @@ -27,6 +27,8 @@ #define W25Q80BV_NUM_PAGES 4096U #define W25Q80BV_NUM_BYTES 1048576U +#define W25Q80BV_READ_DATA 0x03 +#define W25Q80BV_FAST_READ 0x0b #define W25Q80BV_WRITE_ENABLE 0x06 #define W25Q80BV_CHIP_ERASE 0xC7 #define W25Q80BV_READ_STATUS1 0x05 @@ -51,5 +53,6 @@ void w25q80bv_chip_erase(void); void w25q80bv_program(uint32_t addr, uint32_t len, const uint8_t* data); uint8_t w25q80bv_get_device_id(void); void w25q80bv_get_unique_id(w25q80bv_unique_id_t* unique_id); +void w25q80bv_read(uint32_t addr, uint32_t len, uint8_t* const data); #endif//__W25Q80BV_H__ From a4e447cb9ef8bc7f8435cf24f96c6323df6077d4 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 28 Aug 2015 12:49:34 -0700 Subject: [PATCH 30/32] Use W25Q80BV read function to retrieve SPI flash contents. --- firmware/hackrf_usb/usb_api_spiflash.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/firmware/hackrf_usb/usb_api_spiflash.c b/firmware/hackrf_usb/usb_api_spiflash.c index 93c12065..e8791a8f 100644 --- a/firmware/hackrf_usb/usb_api_spiflash.c +++ b/firmware/hackrf_usb/usb_api_spiflash.c @@ -86,10 +86,8 @@ usb_request_status_t usb_vendor_request_write_spiflash( usb_request_status_t usb_vendor_request_read_spiflash( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { - uint32_t i; uint32_t addr; uint16_t len; - uint8_t* u8_addr_pt; if (stage == USB_TRANSFER_STAGE_SETUP) { @@ -99,12 +97,8 @@ usb_request_status_t usb_vendor_request_read_spiflash( || ((addr + len) > W25Q80BV_NUM_BYTES)) { return USB_REQUEST_STATUS_STALL; } else { - /* TODO flush SPIFI "cache" before to read the SPIFI memory */ - u8_addr_pt = (uint8_t*)(addr + SPIFI_DATA_UNCACHED_BASE); - for(i=0; iin, &spiflash_buffer[0], len, NULL, NULL); return USB_REQUEST_STATUS_OK; From 2022cc6351709175319353b8e027a5a10ed8956e Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 28 Aug 2015 13:03:40 -0700 Subject: [PATCH 31/32] Only perform W25Q80BV setup once, at startup. hackrf_usb firmware does not run from SPI flash once the ROM bootloader is done. Simplify assumptions by initializing SPI flash once, early. Do not initialize it every 256 bytes that are read from or written to the device. --- firmware/hackrf_usb/hackrf_usb.c | 4 ++++ firmware/hackrf_usb/usb_api_spiflash.c | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index c5ccb6ad..5f793966 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -47,6 +47,7 @@ #include "sgpio_isr.h" #include "usb_bulk_buffer.h" #include "si5351c.h" +#include "w25q80bv.h" static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF; @@ -224,6 +225,9 @@ int main(void) { #endif cpu_clock_init(); + /* Code is not running from SPI flash, initialize for flash read/write over USB */ + w25q80bv_setup(); + usb_set_descriptor_by_serial_number(); usb_set_configuration_changed_cb(usb_configuration_changed); diff --git a/firmware/hackrf_usb/usb_api_spiflash.c b/firmware/hackrf_usb/usb_api_spiflash.c index e8791a8f..96072394 100644 --- a/firmware/hackrf_usb/usb_api_spiflash.c +++ b/firmware/hackrf_usb/usb_api_spiflash.c @@ -33,14 +33,10 @@ uint8_t spiflash_buffer[W25Q80BV_PAGE_LEN]; usb_request_status_t usb_vendor_request_erase_spiflash( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { - //FIXME This should refuse to run if executing from SPI flash. - if (stage == USB_TRANSFER_STAGE_SETUP) { - w25q80bv_setup(); /* only chip erase is implemented */ w25q80bv_chip_erase(); usb_transfer_schedule_ack(endpoint->in); - //FIXME probably should undo w25q80bv_setup() } return USB_REQUEST_STATUS_OK; } @@ -51,8 +47,6 @@ usb_request_status_t usb_vendor_request_write_spiflash( uint32_t addr = 0; uint16_t len = 0; - //FIXME This should refuse to run if executing from SPI flash. - if (stage == USB_TRANSFER_STAGE_SETUP) { addr = (endpoint->setup.value << 16) | endpoint->setup.index; len = endpoint->setup.length; @@ -62,7 +56,6 @@ usb_request_status_t usb_vendor_request_write_spiflash( } else { usb_transfer_schedule_block(endpoint->out, &spiflash_buffer[0], len, NULL, NULL); - w25q80bv_setup(); return USB_REQUEST_STATUS_OK; } } else if (stage == USB_TRANSFER_STAGE_DATA) { @@ -75,7 +68,6 @@ usb_request_status_t usb_vendor_request_write_spiflash( } else { w25q80bv_program(addr, len, &spiflash_buffer[0]); usb_transfer_schedule_ack(endpoint->in); - //FIXME probably should undo w25q80bv_setup() return USB_REQUEST_STATUS_OK; } } else { @@ -97,7 +89,6 @@ usb_request_status_t usb_vendor_request_read_spiflash( || ((addr + len) > W25Q80BV_NUM_BYTES)) { return USB_REQUEST_STATUS_STALL; } else { - w25q80bv_setup(); w25q80bv_read(addr, len, &spiflash_buffer[0]); usb_transfer_schedule_block(endpoint->in, &spiflash_buffer[0], len, NULL, NULL); From e480a28c0a40b05fbe3658c05a97823c2ce7466e Mon Sep 17 00:00:00 2001 From: Sebastian Koslowski Date: Tue, 27 Oct 2015 20:16:43 +0100 Subject: [PATCH 32/32] Comment style fixup to prevent warning in c90 complier mode --- host/libhackrf/src/hackrf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index a73d7555..ee12f662 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -208,4 +208,4 @@ extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t } // __cplusplus defined. #endif -#endif//__HACKRF_H__ +#endif /*__HACKRF_H__*/