Files

copied
Last update 2 years 1 month by Gianpaolo Macario
Filesfirmwarecommon
..
rad1o
xapp058
LPC4320_M4_memory.ld
LPC4330_M4_memory.ld
LPC43xx_M0_memory.ld
LPC43xx_M4_M0_image_from_text.ld
LPC43xx_M4_memory.ld
README
bitband.c
bitband.h
clkin.c
clkin.h
configure_file.cmake
cpld_jtag.c
cpld_jtag.h
cpld_xc2c.c
cpld_xc2c.h
crc.c
crc.h
fault_handler.c
fault_handler.h
firmware_info.c
firmware_info.h
gpdma.c
gpdma.h
gpio.h
gpio_lpc.c
gpio_lpc.h
hackrf_core.c
hackrf_core.h
hackrf_ui.c
hackrf_ui.h
i2c_bus.c
i2c_bus.h
i2c_lpc.c
i2c_lpc.h
m0_bin.s.cmake
m0_sleep.c
max2837.c
max2837.h
max2837_regs.def
max2837_target.c
max2837_target.h
max2839.c
max2839.h
max2839_regs.def
max2839_target.c
max2839_target.h
max283x.c
max283x.h
max2871.c
max2871.h
max2871_regs.c
max2871_regs.h
max5864.c
max5864.h
max5864_target.c
max5864_target.h
mixer.c
mixer.h
operacake.c
operacake.h
operacake_sctimer.c
operacake_sctimer.h
platform_detect.c
platform_detect.h
portapack.c
portapack.h
rf_path.c
rf_path.h
rffc5071.c
rffc5071.h
rffc5071_regs.def
rffc5071_spi.c
rffc5071_spi.h
rom_iap.c
rom_iap.h
sct.h
sgpio.c
sgpio.h
si5351c.c
si5351c.h
spi_bus.c
spi_bus.h
spi_ssp.c
spi_ssp.h
streaming.c
streaming.h
tuning.c
tuning.h
ui_portapack.c
ui_portapack.h
ui_rad1o.c
ui_rad1o.h
usb.c
usb.h
usb_queue.c
usb_queue.h
usb_request.c
usb_request.h
usb_standard_request.c
usb_standard_request.h
usb_type.h
w25q80bv.c
w25q80bv.h
w25q80bv_target.c
w25q80bv_target.h
platform_detect.c
/* * Copyright 2022 Great Scott Gadgets <info@greatscottgadgets.com> * * This file is part of HackRF. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #include "platform_detect.h" #include "firmware_info.h" #include "gpio_lpc.h" #include "hackrf_core.h" #include <libopencm3/lpc43xx/scu.h> #include <libopencm3/lpc43xx/adc.h> static board_id_t platform = BOARD_ID_UNDETECTED; static board_rev_t revision = BOARD_REV_UNDETECTED; static struct gpio_t gpio2_9_on_P5_0 = GPIO(2, 9); static struct gpio_t gpio3_6_on_P6_10 = GPIO(3, 6); #define P5_0_PUP (1 << 0) #define P5_0_PDN (1 << 1) #define P6_10_PUP (1 << 2) #define P6_10_PDN (1 << 3) /* * Jawbreaker has a pull-down on P6_10 and nothing on P5_0. * rad1o has a pull-down on P6_10 and a pull-down on P5_0. * HackRF One OG has a pull-down on P6_10 and a pull-up on P5_0. * HackRF One r9 has a pull-up on P6_10 and a pull-down on P5_0. */ #define JAWBREAKER_RESISTORS (P6_10_PDN) #define RAD1O_RESISTORS (P6_10_PDN | P5_0_PDN) #define HACKRF1_OG_RESISTORS (P6_10_PDN | P5_0_PUP) #define HACKRF1_R9_RESISTORS (P6_10_PUP | P5_0_PDN) /* * LEDs are configured so that they flash if the detected hardware platform is * not supported by the firmware binary. Only two LEDs are flashed for a * hardware detection failure, but three LEDs are flashed if CPLD configuration * fails. */ static struct gpio_t gpio_led1 = GPIO(2, 1); static struct gpio_t gpio_led2 = GPIO(2, 2); static struct gpio_t gpio_led3 = GPIO(2, 8); uint8_t adc_read(uint8_t pin) { pin &= 0x7; uint8_t pin_mask = (1 << pin); ADC0_CR = ADC_CR_SEL(pin_mask) | ADC_CR_CLKDIV(45) | ADC_CR_CLKS(2) | ADC_CR_PDN | ADC_CR_START(1); while (!(ADC0_GDR & ADC_DR_DONE) || (((ADC0_GDR >> 24) & 0x7) != pin)) {} return (ADC0_GDR >> 6) & 0x03FF; } void adc_off(void) { ADC0_CR = 0; } /* * Starting with r6, HackRF One has pin straps on ADC pins that indicate * hardware revision. Those pins were unconnected prior to r6, so we test for * the unconnected state by averaging several ADC readings. */ #define NUM_SAMPLES (10) #define LOW_THRESHOLD (2 * NUM_SAMPLES) #define HIGH_THRESHOLD (253 * NUM_SAMPLES) typedef enum { PIN_STRAP_HIGH, PIN_STRAP_LOW, PIN_STRAP_ABSENT, } pin_strap_t; pin_strap_t check_pin_strap(uint8_t pin) { int i; uint32_t sum = 0; for (i = 0; i < NUM_SAMPLES; i++) { sum += adc_read(pin); } adc_off(); if (sum > HIGH_THRESHOLD) { return PIN_STRAP_HIGH; } else if (sum < LOW_THRESHOLD) { return PIN_STRAP_LOW; } else { return PIN_STRAP_ABSENT; } } void detect_hardware_platform(void) { uint8_t detected_resistors = 0; scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); gpio_input(&gpio_led1); gpio_output(&gpio_led2); gpio_output(&gpio_led3); gpio_input(&gpio2_9_on_P5_0); gpio_input(&gpio3_6_on_P6_10); /* activate internal pull-down */ scu_pinmux(P5_0, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); scu_pinmux(P6_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); delay_us_at_mhz(4, 96); /* tri-state for a moment before testing input */ scu_pinmux(P5_0, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); scu_pinmux(P6_10, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); delay_us_at_mhz(4, 96); /* if input rose quickly, there must be an external pull-up */ detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? P5_0_PUP : 0; detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? P6_10_PUP : 0; /* activate internal pull-up */ scu_pinmux(P5_0, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); scu_pinmux(P6_10, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); delay_us_at_mhz(4, 96); /* tri-state for a moment before testing input */ scu_pinmux(P5_0, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); scu_pinmux(P6_10, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); delay_us_at_mhz(4, 96); /* if input fell quickly, there must be an external pull-down */ detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? 0 : P5_0_PDN; detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? 0 : P6_10_PDN; switch (detected_resistors) { case JAWBREAKER_RESISTORS: if (!(supported_platform() & PLATFORM_JAWBREAKER)) { halt_and_flash(3000000); } platform = BOARD_ID_JAWBREAKER; return; case RAD1O_RESISTORS: if (!(supported_platform() & PLATFORM_RAD1O)) { halt_and_flash(3000000); } platform = BOARD_ID_RAD1O; return; case HACKRF1_OG_RESISTORS: if (!(supported_platform() & PLATFORM_HACKRF1_OG)) { halt_and_flash(3000000); } platform = BOARD_ID_HACKRF1_OG; break; case HACKRF1_R9_RESISTORS: if (!(supported_platform() & PLATFORM_HACKRF1_R9)) { halt_and_flash(3000000); } platform = BOARD_ID_HACKRF1_R9; break; default: platform = BOARD_ID_UNRECOGNIZED; halt_and_flash(1000000); } pin_strap_t adc0_3 = check_pin_strap(3); pin_strap_t adc0_4 = check_pin_strap(4); pin_strap_t adc0_7 = check_pin_strap(7); if ((adc0_3 == PIN_STRAP_ABSENT) && (adc0_4 == PIN_STRAP_ABSENT) && (adc0_7 == PIN_STRAP_ABSENT) && (platform == BOARD_ID_HACKRF1_OG)) { revision = BOARD_REV_HACKRF1_OLD; } else if ( (adc0_3 == PIN_STRAP_HIGH) && (adc0_4 == PIN_STRAP_HIGH) && (platform == BOARD_ID_HACKRF1_OG)) { revision = BOARD_REV_HACKRF1_R6; } else if ( (adc0_3 == PIN_STRAP_LOW) && (adc0_4 == PIN_STRAP_HIGH) && (platform == BOARD_ID_HACKRF1_OG)) { revision = BOARD_REV_HACKRF1_R7; } else if ( (adc0_3 == PIN_STRAP_HIGH) && (adc0_4 == PIN_STRAP_LOW) && (platform == BOARD_ID_HACKRF1_OG)) { revision = BOARD_REV_HACKRF1_R8; } else if ( (adc0_3 == PIN_STRAP_LOW) && (adc0_4 == PIN_STRAP_LOW) && (platform == BOARD_ID_HACKRF1_R9)) { revision = BOARD_REV_HACKRF1_R9; } else { revision = BOARD_REV_UNRECOGNIZED; } if ((revision > BOARD_REV_HACKRF1_OLD) && (adc0_7 == PIN_STRAP_LOW)) { revision |= BOARD_REV_GSG; } } board_id_t detected_platform(void) { return platform; } board_rev_t detected_revision(void) { return revision; } uint32_t supported_platform(void) { return firmware_info.supported_platform; }
Report a bug