Skip to content

Commit

Permalink
Merge branch 'master' into rad1o
Browse files Browse the repository at this point in the history
  • Loading branch information
schneider42 authored Feb 11, 2017
2 parents 6668448 + 0dee1e3 commit 4117cd3
Show file tree
Hide file tree
Showing 21 changed files with 1,054 additions and 945 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This repository contains hardware designs and software for HackRF, a project to
produce a low cost, open source software radio platform.
This repository contains hardware designs and software for HackRF,
a low cost, open source Software Defined Radio platform.

![HackRF One](https://raw.github.com/mossmann/hackrf/master/doc/HackRF-One-fd0-0009.jpeg)

Expand Down
16 changes: 11 additions & 5 deletions firmware/README
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@ To build and install a standard firmware image for HackRF One:
$ cd hackrf_usb
$ mkdir build
$ cd build
$ cmake .. -DBOARD=HACKRF_ONE
$ cmake ..
$ make
$ hackrf_spiflash -w hackrf_usb.bin

If you have a Jawbreaker, use -DBOARD=JAWBREAKER instead.
If you have a Jawbreaker, add -DBOARD=JAWBREAKER to the cmake command.
If you have a rad1o, use -DBOARD=RAD1O instead.

For loading firmware into RAM with DFU you will also need:

http://dfu-util.gnumonks.org/
It is possible to use a USB Device Firmware Upgrade (DFU) method to load
firmware into RAM. This is normally only required to recover a device that has
had faulty firmware loaded, but it can also be useful for firmware developers.

For loading firmware into RAM with DFU you will need:

http://dfu-util.sourceforge.net/

To start up HackRF One in DFU mode, hold down the DFU button while powering it
on or while pressing and releasing the RESET button. Release the DFU button
after the 3V3 LED illuminates.

A .dfu file is built by default when building firmware. Alternatively you can
load a known good .dfu file from a release package with:
use a known good .dfu file from a release package. Load the firmware into RAM
with:

$ dfu-util --device 1fc9:000c --alt 0 --download hackrf_usb.dfu
71 changes: 67 additions & 4 deletions firmware/common/hackrf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "i2c_bus.h"
#include "i2c_lpc.h"
#include <libopencm3/lpc43xx/cgu.h>
#include <libopencm3/lpc43xx/ccu.h>
#include <libopencm3/lpc43xx/scu.h>
#include <libopencm3/lpc43xx/ssp.h>

Expand Down Expand Up @@ -743,6 +744,72 @@ void cpu_clock_init(void)

CGU_BASE_SSP1_CLK = CGU_BASE_SSP1_CLK_AUTOBLOCK(1)
| CGU_BASE_SSP1_CLK_CLK_SEL(CGU_SRC_PLL1);

/* Disable unused clocks */
/* Start with PLLs */
CGU_PLL0AUDIO_CTRL = CGU_PLL0AUDIO_CTRL_PD(1);

/* Dividers */
CGU_IDIVA_CTRL = CGU_IDIVA_CTRL_PD(1);
CGU_IDIVB_CTRL = CGU_IDIVB_CTRL_PD(1);
CGU_IDIVC_CTRL = CGU_IDIVC_CTRL_PD(1);
CGU_IDIVD_CTRL = CGU_IDIVD_CTRL_PD(1);
CGU_IDIVE_CTRL = CGU_IDIVE_CTRL_PD(1);

/* Base clocks */
CGU_BASE_SPIFI_CLK = CGU_BASE_SPIFI_CLK_PD(1); /* SPIFI is only used at boot */
CGU_BASE_USB1_CLK = CGU_BASE_USB1_CLK_PD(1); /* USB1 is not exposed on HackRF */
CGU_BASE_PHY_RX_CLK = CGU_BASE_PHY_RX_CLK_PD(1);
CGU_BASE_PHY_TX_CLK = CGU_BASE_PHY_TX_CLK_PD(1);
CGU_BASE_LCD_CLK = CGU_BASE_LCD_CLK_PD(1);
CGU_BASE_VADC_CLK = CGU_BASE_VADC_CLK_PD(1);
CGU_BASE_SDIO_CLK = CGU_BASE_SDIO_CLK_PD(1);
CGU_BASE_UART0_CLK = CGU_BASE_UART0_CLK_PD(1);
CGU_BASE_UART1_CLK = CGU_BASE_UART1_CLK_PD(1);
CGU_BASE_UART2_CLK = CGU_BASE_UART2_CLK_PD(1);
CGU_BASE_UART3_CLK = CGU_BASE_UART3_CLK_PD(1);
CGU_BASE_OUT_CLK = CGU_BASE_OUT_CLK_PD(1);
CGU_BASE_AUDIO_CLK = CGU_BASE_AUDIO_CLK_PD(1);
CGU_BASE_CGU_OUT0_CLK = CGU_BASE_CGU_OUT0_CLK_PD(1);
CGU_BASE_CGU_OUT1_CLK = CGU_BASE_CGU_OUT1_CLK_PD(1);

/* Disable unused peripheral clocks */
CCU1_CLK_APB1_CAN1_CFG = 0;
CCU1_CLK_APB1_I2S_CFG = 0;
CCU1_CLK_APB1_MOTOCONPWM_CFG = 0;
CCU1_CLK_APB3_ADC0_CFG = 0;
CCU1_CLK_APB3_ADC1_CFG = 0;
CCU1_CLK_APB3_CAN0_CFG = 0;
CCU1_CLK_APB3_DAC_CFG = 0;
CCU1_CLK_M4_DMA_CFG = 0;
CCU1_CLK_M4_EMC_CFG = 0;
CCU1_CLK_M4_EMCDIV_CFG = 0;
CCU1_CLK_M4_ETHERNET_CFG = 0;
CCU1_CLK_M4_LCD_CFG = 0;
CCU1_CLK_M4_QEI_CFG = 0;
CCU1_CLK_M4_RITIMER_CFG = 0;
CCU1_CLK_M4_SCT_CFG = 0;
CCU1_CLK_M4_SDIO_CFG = 0;
CCU1_CLK_M4_SPIFI_CFG = 0;
CCU1_CLK_M4_TIMER0_CFG = 0;
CCU1_CLK_M4_TIMER1_CFG = 0;
CCU1_CLK_M4_TIMER2_CFG = 0;
CCU1_CLK_M4_TIMER3_CFG = 0;
CCU1_CLK_M4_UART1_CFG = 0;
CCU1_CLK_M4_USART0_CFG = 0;
CCU1_CLK_M4_USART2_CFG = 0;
CCU1_CLK_M4_USART3_CFG = 0;
CCU1_CLK_M4_USB1_CFG = 0;
CCU1_CLK_M4_VADC_CFG = 0;
// CCU1_CLK_SPIFI_CFG = 0;
// CCU1_CLK_USB1_CFG = 0;
// CCU1_CLK_VADC_CFG = 0;
// CCU2_CLK_APB0_UART1_CFG = 0;
// CCU2_CLK_APB0_USART0_CFG = 0;
// CCU2_CLK_APB2_USART2_CFG = 0;
// CCU2_CLK_APB2_USART3_CFG = 0;
// CCU2_CLK_APLL_CFG = 0;
// CCU2_CLK_SDIO_CFG = 0;
}


Expand Down Expand Up @@ -868,10 +935,6 @@ void pin_setup(void) {

scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_NOPULL);

/* Disable unused clock outputs. They generate noise. */
scu_pinmux(CLK0, SCU_CLK_IN | SCU_CONF_FUNCTION7);
scu_pinmux(CLK2, SCU_CLK_IN | SCU_CONF_FUNCTION7);

/* Configure USB indicators */
#if (defined JELLYBEAN || defined JAWBREAKER)
scu_pinmux(SCU_PINMUX_USB_LED0, SCU_CONF_FUNCTION3);
Expand Down
92 changes: 70 additions & 22 deletions firmware/hackrf_usb/usb_api_sweep.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,53 @@
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define FREQ_GRANULARITY 1000000
#define MIN_FREQ 1
#define MAX_FREQ 6000
#define MAX_FREQ_COUNT 1000
#define MAX_RANGES 10
#define THROWAWAY_BUFFERS 2

volatile bool start_sweep_mode = false;
static uint64_t sweep_freq;
bool odd = true;
static uint16_t frequencies[MAX_FREQ_COUNT];
static uint16_t frequency_count = 0;
static uint16_t frequencies[MAX_RANGES * 2];
static unsigned char data[9 + MAX_RANGES * 2 * sizeof(frequencies[0])];
static uint16_t num_ranges = 0;
static uint32_t dwell_blocks = 0;
static uint32_t step_width = 0;
static uint32_t offset = 0;
static enum sweep_style style = LINEAR;

usb_request_status_t usb_vendor_request_init_sweep(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
uint32_t dwell_time;
uint32_t num_samples;
int i;
if (stage == USB_TRANSFER_STAGE_SETUP) {
dwell_time = (endpoint->setup.index << 16) | endpoint->setup.value;
dwell_blocks = dwell_time / 0x4000;
frequency_count = endpoint->setup.length / sizeof(uint16_t);
usb_transfer_schedule_block(endpoint->out, &frequencies,
endpoint->setup.length, NULL, NULL);
num_samples = (endpoint->setup.index << 16) | endpoint->setup.value;
dwell_blocks = num_samples / 0x4000;
if(1 > dwell_blocks) {
return USB_REQUEST_STATUS_STALL;
}
num_ranges = (endpoint->setup.length - 9) / (2 * sizeof(frequencies[0]));
if((1 > num_ranges) || (MAX_RANGES < num_ranges)) {
return USB_REQUEST_STATUS_STALL;
}
usb_transfer_schedule_block(endpoint->out, &data,
endpoint->setup.length, NULL, NULL);
} else if (stage == USB_TRANSFER_STAGE_DATA) {
sweep_freq = frequencies[0];
set_freq(sweep_freq*FREQ_GRANULARITY);
step_width = ((uint32_t)(data[3]) << 24) | ((uint32_t)(data[2]) << 16)
| ((uint32_t)(data[1]) << 8) | data[0];
if(1 > step_width) {
return USB_REQUEST_STATUS_STALL;
}
offset = ((uint32_t)(data[7]) << 24) | ((uint32_t)(data[6]) << 16)
| ((uint32_t)(data[5]) << 8) | data[4];
style = data[8];
if(INTERLEAVED < style) {
return USB_REQUEST_STATUS_STALL;
}
for(i=0; i<(num_ranges*2); i++) {
frequencies[i] = ((uint16_t)(data[10+i*2]) << 8) + data[9+i*2];
}
sweep_freq = (uint64_t)frequencies[0] * FREQ_GRANULARITY;
set_freq(sweep_freq + offset);
start_sweep_mode = true;
usb_transfer_schedule_ack(endpoint->in);
}
Expand All @@ -64,8 +86,9 @@ usb_request_status_t usb_vendor_request_init_sweep(

void sweep_mode(void) {
unsigned int blocks_queued = 0;
unsigned int phase = 0;
unsigned int ifreq = 0;
unsigned int phase = 1;
bool odd = true;
uint16_t range = 0;

uint8_t *buffer;
bool transfer = false;
Expand All @@ -88,8 +111,16 @@ void sweep_mode(void) {
}

if (transfer) {
*(uint16_t*)buffer = 0x7F7F;
*(uint16_t*)(buffer+2) = sweep_freq;
*buffer = 0x7f;
*(buffer+1) = 0x7f;
*(buffer+2) = sweep_freq & 0xff;
*(buffer+3) = (sweep_freq >> 8) & 0xff;
*(buffer+4) = (sweep_freq >> 16) & 0xff;
*(buffer+5) = (sweep_freq >> 24) & 0xff;
*(buffer+6) = (sweep_freq >> 32) & 0xff;
*(buffer+7) = (sweep_freq >> 40) & 0xff;
*(buffer+8) = (sweep_freq >> 48) & 0xff;
*(buffer+9) = (sweep_freq >> 56) & 0xff;
if (blocks_queued > THROWAWAY_BUFFERS) {
usb_transfer_schedule_block(
&usb_endpoint_bulk_in,
Expand All @@ -102,10 +133,27 @@ void sweep_mode(void) {
}

if ((dwell_blocks + THROWAWAY_BUFFERS) <= blocks_queued) {
if(++ifreq >= frequency_count)
ifreq = 0;
sweep_freq = frequencies[ifreq];
set_freq(sweep_freq*FREQ_GRANULARITY);
if(INTERLEAVED == style) {
if(!odd && ((sweep_freq + step_width) >= ((uint64_t)frequencies[1+range*2] * FREQ_GRANULARITY))) {
range = (range + 1) % num_ranges;
sweep_freq = (uint64_t)frequencies[range*2] * FREQ_GRANULARITY;
} else {
if(odd) {
sweep_freq += step_width/4;
} else {
sweep_freq += 3*step_width/4;
}
}
odd = !odd;
} else {
if((sweep_freq + step_width) >= ((uint64_t)frequencies[1+range*2] * FREQ_GRANULARITY)) {
range = (range + 1) % num_ranges;
sweep_freq = (uint64_t)frequencies[range*2] * FREQ_GRANULARITY;
} else {
sweep_freq += step_width;
}
}
set_freq(sweep_freq + offset);
blocks_queued = 0;
}
}
Expand Down
11 changes: 8 additions & 3 deletions firmware/hackrf_usb/usb_api_sweep.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@
* Boston, MA 02110-1301, USA.
*/

#ifndef __USB_API_SCAN_H__
#define __USB_API_SCAN_H__
#ifndef __USB_API_SWEEP_H__
#define __USB_API_SWEEP_H__

#include <stdbool.h>
#include <usb_type.h>
#include <usb_request.h>

extern volatile bool start_sweep_mode;

enum sweep_style {
LINEAR = 0,
INTERLEAVED = 1,
};

usb_request_status_t usb_vendor_request_init_sweep(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);

void sweep_mode(void);

#endif /* __USB_API_SPCAN_H__ */
#endif /* __USB_API_SWEEP_H__ */
26 changes: 26 additions & 0 deletions host/cmake/set_release.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#set(RELEASE "")

if(NOT DEFINED RELEASE)
execute_process(
COMMAND git log -n 1 --format=%h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_EXIT_VALUE
ERROR_QUIET
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_EXIT_VALUE)
set(RELEASE "unknown")
else (GIT_EXIT_VALUE)
execute_process(
COMMAND git status -s --untracked-files=no
OUTPUT_VARIABLE DIRTY
)
if ( NOT "${DIRTY}" STREQUAL "" )
set(DIRTY_FLAG "*")
else()
set(DIRTY_FLAG "")
endif()
set(RELEASE "git-${GIT_VERSION}${DIRTY_FLAG}")
endif (GIT_EXIT_VALUE)
endif()
6 changes: 2 additions & 4 deletions host/hackrf-tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@

cmake_minimum_required(VERSION 2.8)
project(hackrf-tools C)
set(MAJOR_VERSION 0)
set(MINOR_VERSION 5)
set(PACKAGE hackrf-tools)
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION})
set(VERSION ${VERSION_STRING})
include(${PROJECT_SOURCE_DIR}/../cmake/set_release.cmake)
add_definitions(-DTOOL_RELEASE="${RELEASE}")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/modules)

if(MSVC)
Expand Down
5 changes: 1 addition & 4 deletions host/hackrf-tools/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ set(INSTALL_DEFAULT_BINDIR "bin" CACHE STRING "Appended to CMAKE_INSTALL_PREFIX"
INCLUDE(FindPkgConfig)

SET(TOOLS
hackrf_max2837
hackrf_si5351c
hackrf_transfer
hackrf_rffc5071
hackrf_spiflash
hackrf_cpldjtag
hackrf_info
hackrf_operacake
hackrf_debug
)

if(MSVC)
Expand Down
7 changes: 0 additions & 7 deletions host/hackrf-tools/src/hackrf_cpldjtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ int main(int argc, char** argv)
usage();
return EXIT_FAILURE;
}

if (result != HACKRF_SUCCESS) {
fprintf(stderr, "argument error: %s (%d)\n",
hackrf_error_name(result), result);
usage();
return EXIT_FAILURE;
}
}

if (path == NULL) {
Expand Down
Loading

0 comments on commit 4117cd3

Please sign in to comment.