mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-07-26 10:38:52 +00:00
7ea3eec016
* Initial commit and pr for HackRF Pro (praline) arch-port to mayhem-firmware. Please see https://github.com/portapack-mayhem/mayhem-firmware/issues/2957. Added flash specifics for -DBOARD=PRALINE. This firmware only builds with toolchain v9.2.1 if hackrf codebase has -B arm in firmware/hackrf_usb/CMakeLists.txt. * Updated CMakeLists.txt per coordination with @HtoToo. For -DBOARD=PRALINE FLASH_MB_SIZE and FLASH_MB_LIMIT_SIZE are now 4. Removed praline specific variable for FLASH limits. * Updated chibios-portapack's board.cpp to support initialization of the HachRF-Pro (praline) FPGA. Added append_fpga_bitstream.py tool to ensure that praline_fgpa.bin bitstream can be appended to -DBOARD=PRALINE produced firmware. In order to ensure successful execution of append_fpga_bitstream.py to append the fpga bitstream we should expect that the bistsream will be located at 0x180000 in flash. This requires that FLASH_MB_LIMIT_SIZE must be 1.5, and FLASH_BYTES_LIMIT_SIZE must be 1535 * 1024. If we want to allow more or less space for the base firmware image sans the fpga bitstream the location of the bistream must be moved to a location other than 0x180000. * Updated location of praline_fpga.bin bitstream to 0x380000 to allow more room for firmware. Firmware now has 3.5MB, or 2MB more available than before as coordinated with @HTotoo. * Expanded #ifndef PRALINE to include og and r9 gpio and pin setup as coordinated with @HTotoo. * Added note for PRALINE FLASH_MB_LIMIT_SIZE and FLASH_BYTES_LIMIT_SIZE to explain why we are using the 3.5 and 3584 values respectively as coordinated with @HTotoo. * Next round of modifications derived heavily, if not entirely from work done by @banandana at https://github.com/Banandana/mayhem-firmware. This commit should power on the HackRF Pro (praline) display, power on the fpga, and enable gpio, and provide debug utilties. There is still a lot of work to be done to fully enable the new praline board with this build and firmware architectural porting effort. However, hackrf-one boards do not seem to be adversely impacted by the #ifdef PRALINE statements, and CMakeLists updates, as far as I have been able to test. * Ran format-code.sh. Updates for this commit are only due to formatting. Tested builds and they seem to work as exptected. * Addressed fixes in firmware/application and firmware/baseband. Stream now flows to capture and looking glass. Issues were related to thread management. Issues were originally addressed by @banandana. * Ran format-code.sh to allow for consistency with autoamted clang checks. * Update hackrf ref repo to mayhem-portapack-hackrf next from https://github.com/portapack-mayhem/hackrf * Addressed format edits necessary to pass clang-format check. * Starting addressing Si5351 Clocks for radio sampling. These updates correctly set the Si5351 clock at start up. There appears to be an issue during runtime when testing with RX Test Init, Capture and Looking glass. * Updated clock_manager.cpp to restore correct function introduced by @banandana when testing with Rx Test Init. * Switched to using decimation for setting the sample rate without changing the Si5351 clock. This assumes that for the praline board Si5351 CLK0 runs at fixed 8 MHz (constant) and the FPGA decimates to get the desired sample rate. For example, for a 1 MHz sample rate -> Si5351 outputs 8 MHz, FPGA decimates by 8. There is still more work needed here, and potential verification that this is the correct way to operate with this new archteitecture. * After deliberating on hackrf_usb hackrf_core.c and radio.c, and reviewing firmware/application/hw/si5351.cpp the original approach of using the aproach detailed in hackrf_core.c sample_rate_frac_set() lines 580-582, via the implementation in firmware/application/hw/si5351.cpp seems like the best place to continue testing efforts. * Tested at ~2.4GHz (2.3 - 2.5) with lookgin glass and was able to receive signals. Added a Signal Path debug app to test gains, and readio mode (receive/transmit). * Added two debug apps for the RFFC507x. Status View and Tuning View. This helped debug some of the potential issues with tuning. * update submodule * format code * Small touch up merging latest next and ensuring build for HackRF One. * Fix ui addition of max2831 debug display. * Reverted edits to re: firmware/baseband/sd_over_usb/scsi.c and firmware/application/portapack.cpp. Source now builds, had to pull latest hackrf submodule. * Skipped detect hardware for praline board to avoid backscreen in HackRF Pro praline board. * Added UI debug display for max2831 like the rffc507x. Added Filter Band display and Mixer status to Signal Path Status debug display. * Added ability to set Q: INV, or Q:NOR in Signal Path Status Debug view for testing. Also added display entries for the FGPA Ctrl register fir debugging. * Added System Diagnostics which allows testing sample rate, q-inv, and dc blk * Corrected LP - GPIO4[8], and GPIO4[9] issue which was preventing RF Amp, and LPF from chaning state. HackRF Pro (praline) now correctly changes state of LPF and RF Amp as expected. * Corrected LP - GPIO4[8], and GPIO4[9] issue which was preventing RF Amp, and LPF from chaning state. HackRF Pro (praline) now correctly changes state of LPF and RF Amp as expected. * Added consistency for testing. * Added ui to debug whether rffc5072 is locking correctly. Also addressed rf_amp fixed in on state, such that it may now be able to be toggled in HackRF Pro praline setups. * Updated format to support automated tests. * format code * Updated rffc5072 status view in ui_debug to help with debugging. Made updated recommendtions for merge from PR comments. Made updates to ensure resetx isn't reconfigured for output in rffc507x.cpp. * Ran ./format-code.sh * Added reference comment that addresses debugging in PRALINE to detail that when the capture app was requesting 15 MHz, it matched 15100000 which resulted in the 8.5M setting. To get the actual 15M setting (22.6 MHz bandwidth), I had to force a request at least 22 MHz while debugging. * Debugging tunning ENX and frequency locking in low band. * Addressed pin differences between HackRF One and HackRF Pro (praline), resolved ENX configuration. * Cirrected pins, and debugging tuning for low band. High band now goes past 2.7GHz into 3.3 GHz. * Updated ui_debug to track ENX updates and support tracing which calls may be changing ENX. * Removed clkin reference in ui_debug.cpp to allow space for more information about CLK0, CLK1, CLK4, and CLK5. * Removed clkin reference in ui_debug.cpp to allow space for more information about CLK0, CLK1, CLK4, and CLK5. * Ran format-code.sh * Updated rffc507xx.cpp, and ensured hackrf submodule at f1dcd554. --------- Co-authored-by: gullradriel <gullradriel@users.noreply.github.com>
287 lines
7.9 KiB
C++
287 lines
7.9 KiB
C++
/*
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
*
|
|
* This file is part of PortaPack.
|
|
*
|
|
* 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 "cpld_update.hpp"
|
|
|
|
#include "hackrf_gpio.hpp"
|
|
#include "portapack_hal.hpp"
|
|
#include "portapack.hpp"
|
|
|
|
#include "jtag_target_gpio.hpp"
|
|
#include "cpld_max5.hpp"
|
|
#include "cpld_xilinx.hpp"
|
|
#include "portapack_cpld_data.hpp"
|
|
#include "hackrf_cpld_data.hpp"
|
|
|
|
#include "crc.hpp"
|
|
|
|
#define REV_20150901_CHECKSUM 0xE0EF80FB
|
|
#define REV_20170522_CHECKSUM 0xD1BEB722
|
|
|
|
namespace portapack {
|
|
namespace cpld {
|
|
|
|
CpldUpdateStatus update_if_necessary(const Config config) {
|
|
jtag::GPIOTarget target{
|
|
portapack::gpio_cpld_tck,
|
|
portapack::gpio_cpld_tms,
|
|
portapack::gpio_cpld_tdi,
|
|
portapack::gpio_cpld_tdo};
|
|
jtag::JTAG jtag{target};
|
|
CPLD cpld{jtag};
|
|
|
|
/* Unknown state */
|
|
cpld.reset();
|
|
cpld.run_test_idle();
|
|
|
|
/* Run-Test/Idle */
|
|
if (!cpld.idcode_ok()) {
|
|
return CpldUpdateStatus::Idcode_check_failed;
|
|
}
|
|
|
|
cpld.sample();
|
|
cpld.bypass();
|
|
cpld.enable();
|
|
|
|
/* If silicon ID doesn't match, there's a serious problem. Leave CPLD
|
|
* in passive state.
|
|
*/
|
|
if (!cpld.silicon_id_ok()) {
|
|
return CpldUpdateStatus::Silicon_id_check_failed;
|
|
}
|
|
|
|
/* Verify CPLD contents against current bitstream. */
|
|
auto ok = cpld.verify(config.block_0, config.block_1);
|
|
|
|
/* CPLD verifies incorrectly. Erase and program with current bitstream. */
|
|
if (!ok) {
|
|
ok = cpld.program(config.block_0, config.block_1);
|
|
}
|
|
|
|
/* If programming OK, reset CPLD to user mode. Otherwise leave it in
|
|
* passive (ISP) state.
|
|
*/
|
|
if (ok) {
|
|
cpld.disable();
|
|
cpld.bypass();
|
|
|
|
/* Initiate SRAM reload from flash we just programmed. */
|
|
cpld.sample();
|
|
cpld.clamp();
|
|
cpld.disable();
|
|
}
|
|
|
|
return ok ? CpldUpdateStatus::Success : CpldUpdateStatus::Program_failed;
|
|
}
|
|
|
|
static CpldUpdateStatus enter_maintenance_mode(CPLD& cpld) {
|
|
/* Unknown state */
|
|
cpld.reset();
|
|
cpld.run_test_idle();
|
|
|
|
/* Run-Test/Idle */
|
|
if (!cpld.idcode_ok()) {
|
|
return CpldUpdateStatus::Idcode_check_failed;
|
|
}
|
|
|
|
cpld.sample();
|
|
cpld.bypass();
|
|
cpld.enable();
|
|
|
|
/* If silicon ID doesn't match, there's a serious problem. Leave CPLD
|
|
* in passive state.
|
|
*/
|
|
if (!cpld.silicon_id_ok()) {
|
|
return CpldUpdateStatus::Silicon_id_check_failed;
|
|
}
|
|
|
|
return CpldUpdateStatus::Success;
|
|
}
|
|
|
|
static void exit_maintenance_mode(CPLD& cpld) {
|
|
cpld.disable();
|
|
cpld.bypass();
|
|
|
|
/* Initiate SRAM reload from flash we just programmed. */
|
|
cpld.sample();
|
|
cpld.clamp();
|
|
cpld.disable();
|
|
}
|
|
|
|
static uint32_t get_firmware_crc(CPLD& cpld) {
|
|
CRC<32> crc{0x04c11db7, 0xffffffff, 0xffffffff};
|
|
cpld.prepare_read(0x0000);
|
|
|
|
for (size_t i = 0; i < 3328; i++) {
|
|
uint16_t data = cpld.read();
|
|
crc.process_byte((data >> 0) & 0xff);
|
|
crc.process_byte((data >> 8) & 0xff);
|
|
crc.process_byte((data >> 16) & 0xff);
|
|
crc.process_byte((data >> 24) & 0xff);
|
|
}
|
|
|
|
cpld.prepare_read(0x0001);
|
|
|
|
for (size_t i = 0; i < 512; i++) {
|
|
uint16_t data = cpld.read();
|
|
crc.process_byte((data >> 0) & 0xff);
|
|
crc.process_byte((data >> 8) & 0xff);
|
|
crc.process_byte((data >> 16) & 0xff);
|
|
crc.process_byte((data >> 24) & 0xff);
|
|
}
|
|
|
|
return crc.checksum();
|
|
}
|
|
|
|
CpldUpdateStatus update_autodetect(const Config config_rev_20150901, const Config config_rev_20170522) {
|
|
jtag::GPIOTarget target{
|
|
portapack::gpio_cpld_tck,
|
|
portapack::gpio_cpld_tms,
|
|
portapack::gpio_cpld_tdi,
|
|
portapack::gpio_cpld_tdo};
|
|
jtag::JTAG jtag{target};
|
|
CPLD cpld{jtag};
|
|
|
|
if (portapack::display.read_display_status())
|
|
return CpldUpdateStatus::Success; // LCD is ready
|
|
|
|
CpldUpdateStatus result = enter_maintenance_mode(cpld);
|
|
if (result != CpldUpdateStatus::Success)
|
|
return result;
|
|
|
|
uint32_t checksum = get_firmware_crc(cpld);
|
|
|
|
if (checksum == REV_20170522_CHECKSUM) {
|
|
// H2 firmware present
|
|
if (!cpld.program(config_rev_20150901.block_0, config_rev_20150901.block_1))
|
|
return CpldUpdateStatus::Program_failed;
|
|
} else if (checksum == REV_20150901_CHECKSUM) {
|
|
// H1 firmware present
|
|
if (!cpld.program(config_rev_20170522.block_0, config_rev_20170522.block_1))
|
|
return CpldUpdateStatus::Program_failed;
|
|
} else {
|
|
// no firmware present
|
|
if (!cpld.program(config_rev_20150901.block_0, config_rev_20150901.block_1))
|
|
return CpldUpdateStatus::Program_failed;
|
|
}
|
|
|
|
exit_maintenance_mode(cpld);
|
|
|
|
if (portapack::display.read_display_status())
|
|
return CpldUpdateStatus::Success; // LCD is ready
|
|
|
|
if (checksum != REV_20150901_CHECKSUM && checksum != REV_20170522_CHECKSUM) {
|
|
// try the other one
|
|
CpldUpdateStatus result = enter_maintenance_mode(cpld);
|
|
|
|
if (result != CpldUpdateStatus::Success)
|
|
return result;
|
|
|
|
if (!cpld.program(config_rev_20170522.block_0, config_rev_20170522.block_1))
|
|
return CpldUpdateStatus::Program_failed;
|
|
|
|
exit_maintenance_mode(cpld);
|
|
|
|
if (portapack::display.read_display_status())
|
|
return CpldUpdateStatus::Success; // LCD is ready
|
|
}
|
|
|
|
return CpldUpdateStatus::Program_failed;
|
|
}
|
|
|
|
} /* namespace cpld */
|
|
} /* namespace portapack */
|
|
|
|
namespace hackrf {
|
|
namespace cpld {
|
|
|
|
#ifdef PRALINE
|
|
|
|
/* PRALINE has no HackRF CPLD - stub these functions out */
|
|
bool load_sram() {
|
|
return true;
|
|
}
|
|
void load_sram_no_verify() {
|
|
return;
|
|
}
|
|
bool verify_eeprom() {
|
|
return true;
|
|
}
|
|
void init_from_eeprom() {
|
|
return;
|
|
}
|
|
|
|
#else
|
|
|
|
static jtag::GPIOTarget jtag_target_hackrf() {
|
|
return {
|
|
hackrf::one::gpio_cpld_tck,
|
|
hackrf::one::gpio_cpld_tms,
|
|
hackrf::one::gpio_cpld_tdi,
|
|
hackrf::one::gpio_cpld_tdo,
|
|
};
|
|
}
|
|
|
|
bool load_sram() {
|
|
auto jtag_target_hackrf_cpld = jtag_target_hackrf();
|
|
hackrf::one::cpld::CPLD hackrf_cpld{jtag_target_hackrf_cpld};
|
|
|
|
hackrf_cpld.write_sram(hackrf::one::cpld::verify_blocks);
|
|
const auto ok = hackrf_cpld.verify_sram(hackrf::one::cpld::verify_blocks);
|
|
|
|
return ok;
|
|
}
|
|
|
|
void load_sram_no_verify() {
|
|
// CoolRunner II family has Hybrid memory CPLD architecture (SRAM+NVM)
|
|
// It seems that after using a TX App the CPLD_SRAM part needs to be re_loaded to solve #637 ghost beat.
|
|
// load_sram() it is already called at each boot in portapack.cpp, including verify CPLD part.
|
|
// Here we skipped CPLD verify part, just to be quicker (in case any CPLD problem it will be detected in the boot process).
|
|
|
|
auto jtag_target_hackrf_cpld = jtag_target_hackrf();
|
|
hackrf::one::cpld::CPLD hackrf_cpld{jtag_target_hackrf_cpld};
|
|
|
|
hackrf_cpld.write_sram(hackrf::one::cpld::verify_blocks);
|
|
|
|
return;
|
|
}
|
|
|
|
bool verify_eeprom() {
|
|
auto jtag_target_hackrf_cpld = jtag_target_hackrf();
|
|
hackrf::one::cpld::CPLD hackrf_cpld{jtag_target_hackrf_cpld};
|
|
|
|
const auto ok = hackrf_cpld.verify_eeprom(hackrf::one::cpld::verify_blocks);
|
|
|
|
return ok;
|
|
}
|
|
|
|
void init_from_eeprom() {
|
|
auto jtag_target_hackrf_cpld = jtag_target_hackrf();
|
|
hackrf::one::cpld::CPLD hackrf_cpld{jtag_target_hackrf_cpld};
|
|
|
|
hackrf_cpld.init_from_eeprom();
|
|
}
|
|
|
|
#endif // PRALINE
|
|
|
|
} /* namespace cpld */
|
|
} /* namespace hackrf */
|