mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
920b98f7c9
* Power: Turn off additional peripheral clock branches. * Update schematic with new symbol table and KiCad standard symbols. Fix up wires. * Schematic: Update power net labels. * Schematic: Update footprint names to match library changes. * Schematic: Update header vendor and part numbers. * Schematic: Specify (arbitrary) value for PDN# net. * Schematic: Remove fourth fiducial. Not standard practice, and was taking up valuable board space. * Schematic: Add reference oscillator -- options for clipped sine or HCMOS output. * Schematic: Update copyright year. * Schematic: Remove CLKOUT to CPLD. It was a half-baked idea. * Schematic: Add (experimental) GPS circuit. Add note about charging circuit. Update date and revision to match PCB. * PCB: Update from schematic change: now revision 20180819. Diff was extensive due to net renumbering... * PCB: Fix GPS courtyard to accommodate crazy solder paste recommendation in integration manual. PCB: Address DRC clearance violation between via and oscillator pad. * PCB: Update copyright on drawing. * Update schematic and PCB date and revision. * gitignore: Sublime Text editor project/workspace files * Power: Power up or power down peripheral clock at appropriate times, so firmware doesn't freeze... * Clocking: Fix incorrect shift for CGU IDIVx_CTRL.PD field. * LPC43xx: Add CGU IDIVx struct/union type. * Power: Switch off unused IDIV dividers. Make note of active IDIVs and their use. * HackRF Mode: Upgrade firmware to 2018.01.1 (API 1.02) * MAX V CPLD: Refactor class to look more like Xilinx CoolRunner II CPLD class. * MAX V CPLD: Add BYPASS, SAMPLE support. Rename enter_isp -> enable, exit_isp -> disable. Use SAMPLE at start of flash process, which somehow addresses the problem where CFM wouldn't load into SRAM (and become the active bitstream) after flashing. * MAX V CPLD: Reverse verify data checking logic to make it a little faster. * CPLD: After reprogramming flash, immediately clamp I/O signals, load to SRAM, and "execute" the new bitstream. * Si5351: Refactor code, make one of the registers more type-safe. Clock Manager: Track selected reference clock source for later use in user interface. * Clock Manager: Add note about PPM only affecting Si5351C PLLA, which always runs from the HackRF 25MHz crystal. It is assumed an external clock does not need adjustment, though I am open to being convinced otherwise... * PPM UI: Show "EXT" when showing PPM adjustment and reference clock is external. * CPLD: Add pins and logic for new PortaPack hardware feature(s). * CPLD: Bitstream to support new hardware features. * Clock Generator: Add a couple more setter methods for ClockControl registers. * Clock Manager: Use shared MCU CLKIN clock control configuration constant. * Clock Manager: Reduce MCU CLKIN driver current. 2mA should be plenty. * Clock Manager: Remove redundant clock generator output enable. * Bootstrap: Remove unnecessary ldscript hack to locate SPIFI mode change code in RAM. * Bootstrap: Get CPU operating at max frequency as soon as possible. Update SPIFI speed comment. Make some more LPC43xx types into unions with uint32_t. * Bootstrap: Explicitly configure IDIVB for SPIFI, despite LPC43xx bootloader setting it. * Clock Manager: Init peripherals before CPLD reconfig. Do the clock generator setup after, so we can check presence of PortaPack reference clock with the help of the latest CPLD bitstream. * Clock Manager: Reverse sense of conditional that determines crystal or non-crystal reference source. This is for an expected upcoming change where multiple external options can be differentiated. * Bootstrap: Consolidate clock configuration, update SPIFI rate comment. * Clock Manager: Use IDIVA for clock source for all peripherals, instead of PLL1. Should make switching easier going forward. Don't use IRC as clock during initial clock manager configuration. Until we switch to GP_CLKIN, we should go flat out... * ChibiOS M0: Change default clock speed to 204MHz, since bootstrap now maxes out clock speed before starting M0 execution. * PortaPack IO: Expose method to set reference oscillator enable pin. * Pin configuration: Do SPIFI pin config with other pins, in preparation for eliminating separate bootloader. * Pin configuration: Disable input buffers on pins that are never read. * Revert "ChibiOS M0: Change default clock speed to 204MHz, since bootstrap now maxes out clock speed before starting M0 execution." This reverts commit c0e2bb6cc4cc656769323bdbb8ee5a16d2d5bb03. * Remove unused board files. * Add LPC43xx functions. * chibios: Replace code with per-peripheral structs defining clocks, interrupts, and reset bits. * LPC43xx: Add MCPWM peripheral struct. * clock generator: Use recommended PLL reset register value. Datasheet recommends a value. AN619 is quiet on the topic, claims the low nibble is default 0b0000. * GPIO: Tweak masking of SCU function. I don't remember why I thought this was necessary... * HAL: Explicitly turn on timer peripheral clocks used as systicks, during init. * SCU: Add struct to hold pin configuration. * PAL: Add functions to address The Glitch. https://greatscottgadgets.com/2018/02-28-we-fixed-the-glitch/ * PAL/board: New IO initialization code Declare initial state for SCU pin config, GPIOs. Apply initial state during PAL init. Perform VAA slow turn-on to address The Glitch. * Merge M0 and M4 to eliminate need for bootstrap firmware During _early_init, detect if we're running on the M4 or M0. If M4: do M4-specific core initialization, reset peripherals, speed up SPIFI clock, start M0, go to sleep. If M0: do all the other things. * Pins: Miscellaneous SCU configuration tweaks. * Little code clarity improvement. * bootstrap: Remove, not necessary. * Clock Manager: Large re-working to support external references. * Fix merge conflicts
264 lines
6.9 KiB
C++
264 lines
6.9 KiB
C++
/*
|
|
* Copyright (C) 2014 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_max5.hpp"
|
|
|
|
#include "jtag.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <array>
|
|
|
|
namespace cpld {
|
|
namespace max5 {
|
|
|
|
void CPLD::bypass() {
|
|
shift_ir(instruction_t::BYPASS);
|
|
jtag.runtest_tck(18003);
|
|
}
|
|
|
|
void CPLD::sample() {
|
|
shift_ir(instruction_t::SAMPLE);
|
|
jtag.runtest_tck(93);
|
|
for(size_t i=0; i<80; i++) {
|
|
jtag.shift_dr(3, 0b111);
|
|
}
|
|
}
|
|
|
|
void CPLD::clamp() {
|
|
shift_ir(instruction_t::CLAMP);
|
|
jtag.runtest_tck(93);
|
|
}
|
|
|
|
void CPLD::enable() {
|
|
shift_ir(instruction_t::ISC_ENABLE);
|
|
jtag.runtest_tck(18003); // 1ms
|
|
}
|
|
|
|
void CPLD::disable() {
|
|
shift_ir(instruction_t::ISC_DISABLE);
|
|
jtag.runtest_tck(18003); // 1ms
|
|
}
|
|
|
|
/* Sector erase:
|
|
* Involves shifting in the instruction to erase the device and applying
|
|
* an erase pulse or pulses. The erase pulse is automatically generated
|
|
* internally by waiting in the run, test, or idle state for the
|
|
* specified erase pulse time of 500 ms for the CFM block and 500 ms for
|
|
* each sector of the user flash memory (UFM) block.
|
|
*/
|
|
void CPLD::bulk_erase() {
|
|
erase_sector(0x0011);
|
|
erase_sector(0x0001);
|
|
erase_sector(0x0000);
|
|
}
|
|
|
|
bool CPLD::program(
|
|
const std::array<uint16_t, 3328>& block_0,
|
|
const std::array<uint16_t, 512>& block_1
|
|
) {
|
|
bulk_erase();
|
|
|
|
/* Program:
|
|
* involves shifting in the address, data, and program instruction and
|
|
* generating the program pulse to program the flash cells. The program
|
|
* pulse is automatically generated internally by waiting in the run/test/
|
|
* idle state for the specified program pulse time of 75 μs. This process
|
|
* is repeated for each address in the CFM and UFM blocks.
|
|
*/
|
|
program_block(0x0000, block_0);
|
|
program_block(0x0001, block_1);
|
|
|
|
const auto verify_ok = verify(block_0, block_1);
|
|
|
|
if( verify_ok ) {
|
|
/* Do "something". Not sure what, but it happens after verify. */
|
|
/* Starts with a sequence the same as Program: Block 0. */
|
|
/* Perhaps it is a write to tell the CPLD that the bitstream
|
|
* verified OK, and it's OK to load and execute? And despite only
|
|
* one bit changing, a write must be a multiple of a particular
|
|
* length (64 bits)? */
|
|
sector_select(0x0000);
|
|
shift_ir(instruction_t::ISC_PROGRAM);
|
|
jtag.runtest_tck(93); // 5 us
|
|
|
|
/* TODO: Use data from cpld_block_0, with appropriate bit(s) changed */
|
|
/* Perhaps this is the "ISP_DONE" bit? */
|
|
jtag.shift_dr(16, block_0[0] & 0xfbff);
|
|
jtag.runtest_tck(1800); // 100us
|
|
jtag.shift_dr(16, block_0[1]);
|
|
jtag.runtest_tck(1800); // 100us
|
|
jtag.shift_dr(16, block_0[2]);
|
|
jtag.runtest_tck(1800); // 100us
|
|
jtag.shift_dr(16, block_0[3]);
|
|
jtag.runtest_tck(1800); // 100us
|
|
}
|
|
|
|
return verify_ok;
|
|
}
|
|
|
|
bool CPLD::verify(
|
|
const std::array<uint16_t, 3328>& block_0,
|
|
const std::array<uint16_t, 512>& block_1
|
|
) {
|
|
/* Verify */
|
|
const auto block_0_success = verify_block(0x0000, block_0);
|
|
const auto block_1_success = verify_block(0x0001, block_1);
|
|
return block_0_success && block_1_success;
|
|
}
|
|
|
|
uint32_t CPLD::crc() {
|
|
crc_t crc { 0x04c11db7, 0xffffffff, 0xffffffff };
|
|
block_crc(0, 3328, crc);
|
|
block_crc(1, 512, crc);
|
|
return crc.checksum();
|
|
}
|
|
|
|
void CPLD::sector_select(const uint16_t id) {
|
|
shift_ir(instruction_t::ISC_ADDRESS_SHIFT);
|
|
jtag.runtest_tck(93); // 5us
|
|
jtag.shift_dr(13, id); // Sector ID
|
|
}
|
|
|
|
bool CPLD::idcode_ok() {
|
|
shift_ir(instruction_t::IDCODE);
|
|
const auto idcode_read = jtag.shift_dr(idcode_length, 0);
|
|
return (idcode_read == idcode);
|
|
}
|
|
|
|
std::array<uint16_t, 5> CPLD::read_silicon_id() {
|
|
sector_select(0x0089);
|
|
shift_ir(instruction_t::ISC_READ);
|
|
jtag.runtest_tck(93); // 5us
|
|
|
|
std::array<uint16_t, 5> silicon_id;
|
|
silicon_id[0] = jtag.shift_dr(16, 0xffff);
|
|
silicon_id[1] = jtag.shift_dr(16, 0xffff);
|
|
silicon_id[2] = jtag.shift_dr(16, 0xffff);
|
|
silicon_id[3] = jtag.shift_dr(16, 0xffff);
|
|
silicon_id[4] = jtag.shift_dr(16, 0xffff);
|
|
return silicon_id;
|
|
}
|
|
|
|
/* Check ID:
|
|
* The silicon ID is checked before any Program or Verify process. The
|
|
* time required to read this silicon ID is relatively small compared to
|
|
* the overall programming time.
|
|
*/
|
|
bool CPLD::silicon_id_ok() {
|
|
const auto silicon_id = read_silicon_id();
|
|
|
|
return (
|
|
(silicon_id[0] == 0x8232) &&
|
|
(silicon_id[1] == 0x2aa2) &&
|
|
(silicon_id[2] == 0x4a82) &&
|
|
(silicon_id[3] == 0x8c0c) &&
|
|
(silicon_id[4] == 0x0000)
|
|
);
|
|
}
|
|
|
|
uint32_t CPLD::usercode() {
|
|
shift_ir(instruction_t::USERCODE);
|
|
jtag.runtest_tck(93); // 5us
|
|
return jtag.shift_dr(32, 0xffffffff);
|
|
}
|
|
|
|
void CPLD::erase_sector(const uint16_t id) {
|
|
sector_select(id);
|
|
shift_ir(instruction_t::ISC_ERASE);
|
|
jtag.runtest_tck(9000003); // 500ms
|
|
}
|
|
|
|
void CPLD::program_block(
|
|
const uint16_t id,
|
|
const uint16_t* const data,
|
|
const size_t count
|
|
) {
|
|
sector_select(id);
|
|
shift_ir(instruction_t::ISC_PROGRAM);
|
|
jtag.runtest_tck(93); // 5us
|
|
|
|
for(size_t i=0; i<count; i++) {
|
|
jtag.shift_dr(16, data[i]);
|
|
jtag.runtest_tck(1800);
|
|
}
|
|
}
|
|
|
|
bool CPLD::verify_block(
|
|
const uint16_t id,
|
|
const uint16_t* const data,
|
|
const size_t count
|
|
) {
|
|
sector_select(id);
|
|
shift_ir(instruction_t::ISC_READ);
|
|
jtag.runtest_tck(93); // 5us
|
|
|
|
bool success = true;
|
|
for(size_t i=0; i<count; i++) {
|
|
const auto from_device = jtag.shift_dr(16, 0xffff);
|
|
if( from_device != data[i] ) {
|
|
if( (id == 0) && (i == 0) ) {
|
|
// Account for bit that indicates bitstream is valid.
|
|
if( (from_device & 0xfbff) != (data[i] & 0xfbff) ) {
|
|
success = false;
|
|
}
|
|
} else {
|
|
success = false;
|
|
}
|
|
}
|
|
}
|
|
return success;
|
|
}
|
|
|
|
bool CPLD::is_blank_block(const uint16_t id, const size_t count) {
|
|
sector_select(id);
|
|
shift_ir(instruction_t::ISC_READ);
|
|
jtag.runtest_tck(93); // 5us
|
|
|
|
bool success = true;
|
|
for(size_t i=0; i<count; i++) {
|
|
const auto from_device = jtag.shift_dr(16, 0xffff);
|
|
if( from_device != 0xffff ) {
|
|
success = false;
|
|
}
|
|
}
|
|
return success;
|
|
}
|
|
|
|
void CPLD::block_crc(const uint16_t id, const size_t count, crc_t& crc) {
|
|
sector_select(id);
|
|
shift_ir(instruction_t::ISC_READ);
|
|
jtag.runtest_tck(93); // 5us
|
|
|
|
for(size_t i=0; i<count; i++) {
|
|
const uint16_t from_device = jtag.shift_dr(16, 0xffff);
|
|
crc.process_bytes(&from_device, sizeof(from_device));
|
|
}
|
|
}
|
|
|
|
bool CPLD::is_blank() {
|
|
const auto block_0_blank = is_blank_block(0x0000, 3328);
|
|
const auto block_1_blank = is_blank_block(0x0001, 512);
|
|
return block_0_blank && block_1_blank;
|
|
}
|
|
|
|
} /* namespace max5 */
|
|
} /* namespace cpld */
|