mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-29 01:06:27 -05:00
b690165da3
* 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. * PCB: Change PCB stackup, Tg, clarify solder mask color, use more metric. * PCB: Move HackRF header P9 to B.CrtYd layer. * PCB: Change a Tg reference I missed. * PCB: Update footprints for parts with mismatched CAD->tape rotation. Adjust a few layer choice and line thickness bits. * PCB: Got cold feet, switched back to rectangular pads. * PCB: Add Eco layers to be visible and Gerber output. * PCB: Use aux origin for plotting, for tidier coordinates. * PCB: Output Gerber job file, because why not? * Schematic: Correct footprints for two reference-related components. * Schematic: Remove manfuacturer and part number for DNP component. * Schematic: Specify resistor value, manufacturer, part number for reference oscillator series termination. * PCB: Update netlist and footprints from schematic. * Netlist: Updated component values, footprints. * PCB: Nudge some components and traces to address DRC clearance violations. * PCB: Allow KiCad to update zone timestamps (again?!). * PCB: Generate *all* Gerber layers. * Schematic, PCB: Update revision to 20181025. * PCB: Adjust fab layer annotations orientation and font size. * PCB: Hide mounting hole reference designators on silk layer. * PCB: Shrink U1, U3 pads to get 0.2mm space between pads. * PCB: Set pad-to-mask clearance to zero, leave up to fab. Set minimum mask web to 0.2mm for non-black options. * PCB: Revise U1 pad shape, mask, paste, thermal drills. Clearance is improved at corner pads. * PCB: Tweak U3 for better thermal pad/drill/mask/paste design. * PCB: Change solder mask color to blue. * Schematic, PCB: Update revision to 20181029. * PCB: Bump minimum mask web down a tiny bit because KiCad is having trouble with math. * Update schematic * 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. * Clock Manager: Actually store chosen clock reference Similarly-named local was covering a member and discarding the value. * Clock Manager: Reference type which contains source, frequency. * Setup: Display reference source, frequency in frequency correction screen. * LPC43xx API: Add extern "C" for use from C++. * Use LPC43xx API for SGPIO, GPDMA, I2S initialization. * I2S: Add BASE_AUDIO_CLK management. * Add MOTOCON_PWM clock/reset structure. * Serial: Fix dumb typos. * Serial: Remove extra reference operator. * Serial: Cut-and-paste error in structure type name. * Move SCU structure from PAL to LPC43xx API. It'd be nice if I gave some thought to where code should live before I commit it. * VAA power: Move code to HackRF board file It doesn't belong in PAL. * MAX5 CPLD: Add SAMPLE and EXTEST methods. * Flash image: Change packing scheme to use flash more efficiently. Application is now a single image for both M4 bootstrap and M0. Baseband images come immediately after application binary. No need to align to large blocks (and waste lots of flash). * Clock Manager: Remove PLL1 power down function. * Move and rename peripherals reset function to board module. * Remove unused peripheral/clock management. * Clock Manager: Extract switch to IRC into separate function. * Clock Manager: More explicit shutdown of clocks, clock generator. * Move initialization to board module. * ChibiOS: Rename "application" board, add "baseband" board. There are now two ChibiOS "boards", one which runs the application and does the hardware setup. The other board, "baseband", does very little setup. * Clock Manager: Remove unused crystal enable/disable code. * Clock Manager: Restore clock configuration to SPIFI bootloader state before app shutdown. * Reset peripherals on app shutdown. Be careful not to reset M0APP (the core we're running on) or GPIO (which is holding the hardware in a stable state). * M4/baseband hal_lld_init: use IDIVA, which is configured earlier by M0. This was causing problems during restart into HackRF mode. Baseband hal_lld_init changed M4 clock from IDIVA (set by M0) to PLL1, which was unceremoniously turned off during shutdown. * Audio app: Stop audio PLL on shutdown. * M4 HAL: Make LPC43XX_M4_CLK_SRC optional. This was changing the BASE_M4_CLK when a baseband was run. * LPC43xx C++ layer: Fix IDIVx constructor IDIV narrow field width. * Application board: hide the peripherals_reset function, as it isn't useful except during hardware init. * Consolidate hardware init code to some degree. ClockManager is super-overloaded and murky in its purpose. Migrate audio from IDIVC to IDIVD, to more closely resemble initial clock scheme, so it's simpler to get back to it during shutdown. * Migrate some startup code to application board. * Si5351: Use correct methods for reset(). update_output_enable_control() doesn't reset the enabled outputs to the reset state, unless the object is freshly initialized, which it isn't when performing firmware shutdown. For similar reasons, use set_clock_control() instead of setting internal state and then using the update function. * GPIO: Set SPIFI CS pin to match input buffer state coming out of bootloader. * Change application board.c to .cpp, with required dependent changes * Board: Clean up SCU configuration code/data. * I2S: Add shutdown code and use it. * LPC43xx: Consolidate a bunch of structures that had been scattered all over. ...because I'm an undisciplined coder. * I2S: Fix ordering of branch and base clock disable. Core was hanging, presumably because the register interface on the branch/peripheral was unresponsive after the base clock was disabled. * Controls: Save and expose raw navigation wheel switch state I need to do some work on debouncing and ignoring simultaneous key presses. * Controls: Add debug view for switches state. * Controls: Ignore all key presses until all keys are released. This should address some mechanical quirks of the navigation wheel used on the PortaPack. * Clock Manager: Wait for only the necessary PLL to lock. Wasn't working on PortaPacks without a built-in clock reference, as that uses the other PLL. TODO: Switching PLLs may be kind of pointless now... * CMake: Pull HackRF project from GitHub and build. * CMake: Remove commented code. * CMake: Clone HackRF via HTTPS, not SSH. * CMake: Extra pause for slow post-DFU firmware boot-up. * CMake: TODO to fix SVF/XSVF file source. * CMake: Ask HackRF hackrf_usb to make DFU binary. * Travis-CI: Add dfu-util, now that HackRF firmware is being built for inclusion. * Travis-CI: Update build environment to Ubuntu xenial Previously Trusty. * Travis-CI: Incorrectly structured my request for dfu-util package. I'm soooo talented. * ldscript: Mark flash, ram with correct R/W/X flags. * ldscript: Enlarge M0 flash region to 1Mbyte, the size of the HackRF SPI flash. * Receiver: Hide PPM adjustment if clock source is not HackRF crystal. * Documentation: Update product photos and README. * Documentation: Add TCXO feature to README description. * Application: Rearrange files to match HAVOC directory structure. * Map view in AIS (#213) * Added GeoMapView to AISRecentEntryDetailView * Added autoupdate in AIS map * Revert "Map view in AIS (#213)" This reverts commit262c030224
. This commit will be cherry-picked onto a clean branch, then re-committed after a troublesome pull request is reverted. * Revert "Upstream merge to make new revision of PortaPack work (#206)" This reverts commit920b98f7c9
. This pull request was missing some changes and was preventing firmware from functioning on older PortaPacks. * CPLD: Pull bitstream from HackRF project. * SGPIO: Identify pins on CPLD by their new functions. Pull down HOST_SYNC_EN. * CPLD: Don't load HackRF CPLD bitstream into RAM. Trying to converge CPLD implementations, so this shouldn't be necesssary. HOWEVER, it would be good to *check* the CPLD contents and provide a way to update, if necessary. * CPLD: Tweak clock generator config to match CPLD timing changes in HackRF. * PinConfig: Drive CPLD pins correctly. * CMake: Use jboone/hackrf master branch, now that CPLD fixes are there. * CMake: Fix HackRF CPLD SVF dependency. Build would break on the first pass, but work if you restarted make. * CMake: Fix my misuse of the HackRF CMake configuration -- was building from too deep in the directory tree * CMake: Work-around for CMake 3.5 not supporting ExternalProject_Add SOURCE_SUBDIR. * CMake: Choose a CMP0005 policy to quiet CMake warnings. * Settings: Show active clock reference. Only show PPM adjustment for HackRF source. * Setup: Format clock reference frequency in MHz, not Hz. * Radio Settings: Change reference clock text color. Make consistent color with other un-editable text. TODO: This is a bit of a hack to get ui::Text objects to support custom colors, like the Label structures used elsewhere. * Pin config: VREGMODE=1, add other pins for completeness, comment detail * Pin setup: More useful comments. * Pin setup: Change some defaults, only set up PortaPack pins if detected. * Pin setup: Disable LPC pull-ups on PP CPLD data bus, as CPLD is pulling up. * Baseband: Allow larger HackRF firmware image. * HackRF: Remove USER_INTERFACE CMake variable. * CPLD: Make use of HackRF CPLD tool to generate code. * Release: Add generation of MD5SUMS, SHA256SUMS during "make release" * Clock generator: Match clock output currents to HackRF firmware. Someday, we will share a code base again... * CMake: Make "firmware" target part of the "all" target. So now an unqualified "make" will make the firmware binary. * CMake: Change how HackRF firmware is incorporated into binary. Use the separate HackRF "RAM" binary. Get rid of the strip-dfu utility, since there's no longer a need to extract the binary from the DFU. * CMake: Renamed GIT_REVISION* -> GIT_VERSION* to match HackRF build env. * CMake: Bring git version handling closer to HackRF for code reuse. * Travis-CI: Rework CI release artifact output. * Travis-CI: Don't assign PROJECT_NAME within deploy-nightly.sh * Travis-CI: Oops, don't include distro package for compiler... ...when also installing it from a third-party PPA. * Travis-CI: Update GCC package, old one seems "retired"? * Travis-CI: OK, the gcc-arm-none-eabi package is NOT current. Undoing... * Travis-CI: Path oopsies. * Travis-CI: More path confusion. I think this will do it. *touch wood* * Travis-CI: Update build message sent to FreeNode #portapack IRC. * Travis-CI: Break out BUILD_DATE from BUILD_NAME. * Travis-CI: Introduce build directories, include MD5 and SHA256 hashes. * Travis-CI: Fix MD5SUMS/SHA256SUMS paths. * Travis-CI: Fix typo generating name for binary links. * Power: Keep 1V8 off until after VAA is brought up. * Power: Bring up VAA in several steps to keep voltage swing small. * About: Show longer commit/tag version string. * Versioning: Report non-CI builds with "local-" version prefix. * Travis-CI: Report new nightly build site in IRC notification. * Change use of GIT_VERSION to VERSION_STRING Required by prior merge. * Git: add "hackrf" submodule. * CMake: Use hackrf submodule for build, stop pulling during build. * Travis: Fix build paths due to CMake submodule changes. * Travis: Explicitly update submodules recursively * Revert "Travis: Explicitly update submodules recursively" This reverts commit b246438d805f431e727e01b7407540e932e89ee1. * Travis: Try to sort out hackrf submodule output paths... * Travis: I don't know what I'm doing. * CMake: "make firmware" problem due to target vs. path used for dependency. * HackRF: Incorporate YAML security fix. * CMake: Fix more places where targets should be used... ...instead of paths to outputs. * CMake: Add DFU file to "make firmware" outputs * HackRF: Update submodule for CMake m0_bin.s path fix. * added encoder support to alphanum * added encoder support to freq-keypad * UI Redesign - added BtnGrid & NewButton widgets and created a new button-based layout, with both encoder and touchscreen are supported. * Scanner changes: - using SCANNER.TXT for frequencies, ranges also supported. file format is the same as any other frequency file, thus can be edited via the Frequency Manager. - add nfm bw selector & time-to-wait to the UI - add SCANNER.TXT to sdcard dir orignal idea & scanner file adopted from user 'bicurico' * small changes to scanner * remember last category on frequency manager * fix: cast int16_t instead of uint16_t (although i doubt we will have more than 32767 buttons in the array...) * added a missing last_category_id on freq manager
695 lines
36 KiB
C++
Executable File
695 lines
36 KiB
C++
Executable File
/*
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
|
Copyright (C) 2014 Jared Boone, ShareBrained Technology
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
#include "ch.h"
|
|
#include "hal.h"
|
|
|
|
#include <array>
|
|
|
|
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
|
/**
|
|
* @brief PAL setup.
|
|
* @details Digital I/O ports static configuration as defined in @p board.h.
|
|
* This variable is used by the HAL when initializing the PAL driver.
|
|
*/
|
|
/**
|
|
* CoolRunner (HackRF) CPLD:
|
|
* CoolRunner-II devices have internal pull-ups on TDI, TMS, and TCK.
|
|
* It is not necessary to externally terminate JTAG pins with internal termination; they can be
|
|
* left floating. External pull-ups on pins with internal termination is allowed, but not
|
|
* necessary. External pull-down termination is not recommended as it would conflict with
|
|
* the internal pull-ups
|
|
*
|
|
* LPC43xx pull-ups come on line when 3V3 supply voltage reaches about 2V.
|
|
*
|
|
* 3V3 supply:
|
|
* Ramps up in about 1ms.
|
|
*
|
|
* 1V8 supply:
|
|
* Ramps up in about 1ms.
|
|
* EN1V8 has a 10K pull-down on the HackRF and is pulled up (very gently) by the LPC43xx
|
|
* bootloader at boot time. So until the EN1V8 pin is reconfigured as an output, the enable
|
|
* pin on the 1V8 supply sits at about 0.55V, which feels untidy...
|
|
* 1V8 supply is activated when GPIO is driven high by user code.
|
|
*/
|
|
const PALConfig pal_default_config = {
|
|
.P = {
|
|
{ // GPIO0
|
|
.data
|
|
= (1 << 15) // P1_20: CS_XCVR
|
|
| (1 << 14) // P2_10: AMP_BYPASS
|
|
| (0 << 13) // P1_18: SGPIO12, HOST_Q_INVERT
|
|
| (0 << 12) // P1_17: SGPIO11, HOST_DIRECTION
|
|
| (1 << 11) // P1_4: SSP1_MOSI
|
|
| (1 << 10) // P1_3: SSP1_MISO
|
|
| (0 << 9) // P1_2: 10K PD, BOOT1
|
|
| (1 << 8) // P1_1: 10K PU, BOOT0
|
|
| (1 << 7) // P2_7: 10K PU, ISP
|
|
| (0 << 6) // P3_6: SPIFI_MISO
|
|
| (1 << 5) // P6_6: SGPIO5, HOST_DATA5
|
|
| (1 << 4) // P1_0: SGPIO7, HOST_DATA7
|
|
| (1 << 3) // P1_16: SGPIO3, HOST_DATA3
|
|
| (1 << 2) // P1_15: SGPIO2, HOST_DATA2
|
|
| (1 << 1) // P0_1: SGPIO1, HOST_DATA1
|
|
| (1 << 0) // P0_0: SGPIO0, HOST_DATA0
|
|
,
|
|
.dir
|
|
= (1 << 15) // P1_20: CS_XCVR
|
|
| (1 << 14) // P2_10: AMP_BYPASS
|
|
| (1 << 13) // P1_18: SGPIO12, HOST_Q_INVERT
|
|
| (0 << 12) // P1_17: SGPIO11, HOST_DIRECTION
|
|
| (0 << 11) // P1_4: SSP1_MOSI
|
|
| (0 << 10) // P1_3: SSP1_MISO
|
|
| (0 << 9) // P1_2: 10K PD, BOOT1
|
|
| (0 << 8) // P1_1: 10K PU, BOOT0
|
|
| (0 << 7) // P2_7: 10K PU, ISP
|
|
| (0 << 6) // P3_6: SPIFI_MISO
|
|
| (0 << 5) // P6_6: SGPIO5, HOST_DATA5
|
|
| (0 << 4) // P1_0: SGPIO7, HOST_DATA7
|
|
| (0 << 3) // P1_16: SGPIO3, HOST_DATA3
|
|
| (0 << 2) // P1_15: SGPIO2, HOST_DATA2
|
|
| (0 << 1) // P0_1: SGPIO1, HOST_DATA1
|
|
| (0 << 0) // P0_0: SGPIO0, HOST_DATA0
|
|
},
|
|
{ // GPIO1
|
|
.data
|
|
= (1 << 15) // P3_5: SPIFI_SIO2
|
|
| (1 << 14) // P3_4: SPIFI_SIO3
|
|
| (1 << 13) // P2_13: PortaPack DIR
|
|
| (1 << 12) // P2_12: !RX_AMP_PWR
|
|
| (0 << 11) // P2_11: RX_AMP
|
|
| (0 << 10) // P2_9: 10K PD, BOOT3, PortaPack LCD_WRX
|
|
| (1 << 9) // P1_6: SD_CMD
|
|
| (1 << 8) // P1_5: SD_POW, PortaPack CPLD.TDO(O) (input with pull up)
|
|
| (1 << 7) // P1_14: SGPIO10, HOST_DISABLE
|
|
| (1 << 6) // P1_13: SD_CD
|
|
| (1 << 5) // P1_12: SD_DAT3
|
|
| (1 << 4) // P1_11: SD_DAT2
|
|
| (1 << 3) // P1_10: SD_DAT1
|
|
| (1 << 2) // P1_9: SD_DAT0
|
|
| (1 << 1) // P1_8: PortaPack CPLD.TMS(I)
|
|
| (0 << 0) // P1_7: !MIX_BYPASS
|
|
,
|
|
.dir
|
|
= (0 << 15) // P3_5: SPIFI_SIO2
|
|
| (0 << 14) // P3_4: SPIFI_SIO3
|
|
| (0 << 13) // P2_13: PortaPack DIR
|
|
| (1 << 12) // P2_12: !RX_AMP_PWR
|
|
| (1 << 11) // P2_11: RX_AMP
|
|
| (0 << 10) // P2_9: 10K PD, BOOT3, PortaPack LCD_WRX
|
|
| (0 << 9) // P1_6: SD_CMD
|
|
| (0 << 8) // P1_5: SD_POW, PortaPack CPLD.TDO(O) (input with pull up)
|
|
| (0 << 7) // P1_14: SGPIO10, HOST_DISABLE
|
|
| (0 << 6) // P1_13: SD_CD
|
|
| (0 << 5) // P1_12: SD_DAT3
|
|
| (0 << 4) // P1_11: SD_DAT2
|
|
| (0 << 3) // P1_10: SD_DAT1
|
|
| (0 << 2) // P1_9: SD_DAT0
|
|
| (0 << 1) // P1_8: PortaPack CPLD.TMS(I) (output only when needed, pull up internal to CPLD)
|
|
| (1 << 0) // P1_7: !MIX_BYPASS
|
|
},
|
|
{ // GPIO2
|
|
.data
|
|
= (0 << 15) // P5_6: TX_AMP
|
|
| (1 << 14) // P5_5: MIXER_RESETX, 10K PU
|
|
| (1 << 13) // P5_4: MIXER_ENX, 10K PU
|
|
| (1 << 12) // P5_3: RX_MIX_BP
|
|
| (0 << 11) // P5_2: TX_MIX_BP
|
|
| (0 << 10) // P5_1: LP
|
|
| (1 << 9) // P5_0: !VAA_ENABLE
|
|
| (0 << 8) // P6_12: LED3 (TX)
|
|
| (1 << 7) // P5_7: CS_AD
|
|
| (0 << 6) // P4_6: XCVR_EN, 10K PD
|
|
| (0 << 5) // P4_5: RXENABLE
|
|
| (0 << 4) // P4_4: TXENABLE
|
|
| (1 << 3) // P4_3: SGPIO9, HOST_CAPTURE
|
|
| (0 << 2) // P4_2: LED2 (RX)
|
|
| (0 << 1) // P4_1: LED1 (USB)
|
|
| (1 << 0) // P4_0: HP
|
|
,
|
|
.dir
|
|
= (1 << 15) // P5_6: TX_AMP
|
|
| (1 << 14) // P5_5: MIXER_RESETX, 10K PU
|
|
| (1 << 13) // P5_4: MIXER_ENX, 10K PU
|
|
| (1 << 12) // P5_3: RX_MIX_BP
|
|
| (1 << 11) // P5_2: TX_MIX_BP
|
|
| (1 << 10) // P5_1: LP
|
|
| (1 << 9) // P5_0: !VAA_ENABLE
|
|
| (1 << 8) // P6_12: LED3 (TX)
|
|
| (1 << 7) // P5_7: CS_AD
|
|
| (1 << 6) // P4_6: XCVR_EN, 10K PD
|
|
| (1 << 5) // P4_5: RXENABLE
|
|
| (1 << 4) // P4_4: TXENABLE
|
|
| (0 << 3) // P4_3: SGPIO9, HOST_CAPTURE
|
|
| (1 << 2) // P4_2: LED2 (RX)
|
|
| (1 << 1) // P4_1: LED1 (USB)
|
|
| (1 << 0) // P4_0: HP
|
|
},
|
|
{ // GPIO3
|
|
.data
|
|
= (1 << 15) // P7_7: PortaPack GPIO3_15(IO)
|
|
| (1 << 14) // P7_6: PortaPack GPIO3_14(IO)
|
|
| (1 << 13) // P7_5: PortaPack GPIO3_13(IO)
|
|
| (1 << 12) // P7_4: PortaPack GPIO3_12(IO)
|
|
| (1 << 11) // P7_3: PortaPack GPIO3_11(IO)
|
|
| (1 << 10) // P7_2: PortaPack GPIO3_10(IO)
|
|
| (1 << 9) // P7_1: PortaPack GPIO3_9(IO)
|
|
| (1 << 8) // P7_0: PortaPack GPIO3_8(IO)
|
|
| (1 << 7) // P6_11: VREGMODE
|
|
| (0 << 6) // P6_10: EN1V8, 10K PD
|
|
| (1 << 5) // P6_9: !TX_AMP_PWR, 10K PU
|
|
| (1 << 4) // P6_5: HackRF CPLD.TMS(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
|
| (1 << 3) // P6_4: MIXER_SDATA
|
|
| (1 << 2) // P6_3: SGPIO4, HOST_DATA4
|
|
| (1 << 1) // P6_2: HackRF CPLD.TDI(I), PortaPack I2S0_RX_SDA(O), PortaPack CPLD.TDI(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
|
| (1 << 0) // P6_1: HackRF CPLD.TCK(I), PortaPack CPLD.TCK(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
|
,
|
|
.dir
|
|
= (0 << 15) // P7_7: PortaPack GPIO3_15(IO)
|
|
| (0 << 14) // P7_6: PortaPack GPIO3_14(IO)
|
|
| (0 << 13) // P7_5: PortaPack GPIO3_13(IO)
|
|
| (0 << 12) // P7_4: PortaPack GPIO3_12(IO)
|
|
| (0 << 11) // P7_3: PortaPack GPIO3_11(IO)
|
|
| (0 << 10) // P7_2: PortaPack GPIO3_10(IO)
|
|
| (0 << 9) // P7_1: PortaPack GPIO3_9(IO)
|
|
| (0 << 8) // P7_0: PortaPack GPIO3_8(IO)
|
|
| (1 << 7) // P6_11: VREGMODE
|
|
| (1 << 6) // P6_10: EN1V8, 10K PD
|
|
| (1 << 5) // P6_9: !TX_AMP_PWR, 10K PU
|
|
| (0 << 4) // P6_5: HackRF CPLD.TMS(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
|
| (0 << 3) // P6_4: MIXER_SDATA
|
|
| (0 << 2) // P6_3: SGPIO4, HOST_DATA4
|
|
| (0 << 1) // P6_2: HackRF CPLD.TDI(I), PortaPack I2S0_RX_SDA(O), PortaPack CPLD.TDI(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
|
| (0 << 0) // P6_1: HackRF CPLD.TCK(I), PortaPack CPLD.TCK(I) (output only when needed, pull-up internal to CPLD when 1V8 present)
|
|
},
|
|
{ // GPIO4
|
|
.data
|
|
= (1 << 11) // P9_6: SGPIO8, SGPIO_CLK
|
|
,
|
|
.dir
|
|
= (0 << 11) // P9_6: SGPIO8, SGPIO_CLK
|
|
},
|
|
{ // GPIO5
|
|
.data
|
|
= (1 << 18) // P9:5: HackRF CPLD.TDO(O) (input with pull up)
|
|
| (1 << 16) // P6_8: MIX_BYPASS
|
|
| (0 << 15) // P6_7: TX
|
|
| (1 << 14) // P4_10: SGPIO15, CPLD (unused)
|
|
| (1 << 13) // P4_9: SGPIO14, CPLD (unused)
|
|
| (0 << 12) // P4_8: SGPIO13, HOST_SYNC_EN
|
|
| (1 << 11) // P3_8: SPIFI_CS
|
|
| (1 << 10) // P3_7: SPIFI_MOSI
|
|
| (1 << 9) // P3_2: I2S0_RX_SDA
|
|
| (1 << 8) // P3_1: I2S0_RX_WS
|
|
| (0 << 7) // P2_8: BOOT2
|
|
| (0 << 6) // P2_6: MIXER_SCLK
|
|
| (1 << 5) // P2_5: RX
|
|
| (1 << 4) // P2_4: PortaPack LCD_RDX
|
|
| (0 << 3) // P2_3: PortaPack LCD_TE
|
|
| (1 << 2) // P2_2: SGPIO6, HOST_DATA6
|
|
| (0 << 1) // P2_1: PortaPack ADDR
|
|
| (1 << 0) // P2_0: PortaPack IO_STBX
|
|
,
|
|
.dir
|
|
= (0 << 18) // P9_5: HackRF CPLD.TDO(O) (input with pull up)
|
|
| (1 << 16) // P6_8: MIX_BYPASS
|
|
| (1 << 15) // P6_7: TX
|
|
| (0 << 14) // P4_10: SGPIO15, CPLD (unused)
|
|
| (0 << 13) // P4_9: SGPIO14, CPLD (unused)
|
|
| (0 << 12) // P4_8: SGPIO13, HOST_SYNC_EN
|
|
| (0 << 11) // P3_8: SPIFI_CS
|
|
| (0 << 10) // P3_7: SPIFI_MOSI
|
|
| (0 << 9) // P3_2: I2S0_RX_SDA
|
|
| (0 << 8) // P3_1: I2S0_RX_WS
|
|
| (0 << 7) // P2_8: BOOT2
|
|
| (0 << 6) // P2_6: MIXER_SCLK
|
|
| (1 << 5) // P2_5: RX
|
|
| (0 << 4) // P2_4: PortaPack LCD_RDX
|
|
| (0 << 3) // P2_3: PortaPack LCD_TE
|
|
| (0 << 2) // P2_2: SGPIO6, HOST_DATA6
|
|
| (0 << 1) // P2_1: PortaPack ADDR
|
|
| (0 << 0) // P2_0: PortaPack IO_STBX
|
|
},
|
|
{ // GPIO6
|
|
.data = 0,
|
|
.dir = 0
|
|
},
|
|
{ // GPIO7
|
|
.data = 0,
|
|
.dir = 0
|
|
},
|
|
},
|
|
.SCU = {
|
|
/* Configure GP_CLKIN as soon as possible. It's an output at boot time, and the Si5351C doesn't
|
|
* reset when the reset button is pressed, so it could still be output enabled.
|
|
*/
|
|
{ 4, 7, scu_config_normal_drive_t { .mode=1, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* GP_CLKIN/P72/MCU_CLK: SI5351C.CLK7(O) */
|
|
|
|
/* HackRF: LEDs. Configured early so we can use them to indicate boot status. */
|
|
{ 4, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* LED1: LED1.A(I) */
|
|
{ 4, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* LED2: LED2.A(I) */
|
|
{ 6, 12, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* LED3: LED3.A(I) */
|
|
|
|
/* Power control */
|
|
{ 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !VAA_ENABLE: 10K PU, Q3.G(I), power to VAA */
|
|
{ 6, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* EN1V8/P70: 10K PD, TPS62410.EN2(I), 1V8LED.A(I) */
|
|
{ 6, 11, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* VREGMODE/P69: TPS62410.MODE/DATA(I) */
|
|
|
|
/* HackRF: I2C0 */
|
|
/* Glitch filter operates at 3ns instead of 50ns due to the WM8731
|
|
* returning an ACK very fast (170ns) and confusing the I2C state
|
|
* machine into thinking there was a bus error. It looks like the
|
|
* MCU sees SDA fall before SCL falls, indicating a START at the
|
|
* point an ACK is expected. With the glitch filter off or set to
|
|
* 3ns, it's probably still a bit tight timing-wise, but improves
|
|
* reliability on some problem units.
|
|
*/
|
|
{ 25, 1,
|
|
scu_config_sfsi2c0_t {
|
|
.scl_efp=1, // SCL: 3ns glitch
|
|
.scl_ehd=0, // SCL: Standard/Fast mode
|
|
.scl_ezi=1, // SCL: Input enabled
|
|
.scl_zif=0, // SCL: Enable input glitch filter
|
|
.sda_efp=1, // SDA: 3ns glitch
|
|
.sda_ehd=0, // SDA: Standard/Fast mode
|
|
.sda_ezi=1, // SDA: Input enabled
|
|
.sda_zif=0 // SDA: Enable input glitch filter
|
|
}
|
|
},
|
|
|
|
/* Radio section control */
|
|
{ 1, 3, scu_config_normal_drive_t { .mode=5, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* SSP1_MISO/P41: MAX2837.DOUT(O) */
|
|
{ 1, 4, scu_config_normal_drive_t { .mode=5, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SSP1_MOSI/P40: MAX2837.DIN(I), MAX5864.DIN(I) */
|
|
{ 1, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !MIX_BYPASS/P35: U1.VCTL1(I), U11.VCTL2(I), U9.V2(I) */
|
|
{ 1, 19, scu_config_normal_drive_t { .mode=1, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SSP1_SCK/P39: MAX2837.SCLK(I), MAX5864.SCLK(I) */
|
|
{ 1, 20, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CS_XCVR/P53: MAX2837.CS(I) */
|
|
{ 2, 5, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RX/P43: U7.VCTL1(I), U10.VCTL1(I), U2.VCTL1(I) */
|
|
{ 2, 6, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIXER_SCLK/P31: 33pF, RFFC5072.SCLK(I) */
|
|
{ 2, 10, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* AMP_BYPASS/P50: U14.V2(I), U12.V2(I) */
|
|
{ 2, 11, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RX_AMP/P49: U12.V1(I), U14.V3(I) */
|
|
{ 2, 12, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !RX_AMP_PWR/P52: 10K PU, Q1.G(I), power to U13 (RX amp) */
|
|
{ 4, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* HP/P44: U6.VCTL1(I), U5.VCTL2(I) */
|
|
{ 4, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TXENABLE/P55: MAX2837.TXENABLE(I) */
|
|
{ 4, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RXENABLE/P56: MAX2837.RXENABLE(I) */
|
|
{ 4, 6, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* XCVR_EN: 10K PD, MAX2837.ENABLE(I) */
|
|
{ 5, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* LP/P45: U6.VCTL2(I), U5.VCTL1(I) */
|
|
{ 5, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TX_MIX_BP/P46: U9.V1(I) */
|
|
{ 5, 3, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* RX_MIX_BP/P47: U9.V3(I) */
|
|
{ 5, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIXER_ENX/P32: 10K PU, 33pF, RFFC5072.ENX(I) */
|
|
{ 5, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIXER_RESETX/P33: 10K PU, 33pF, RFFC5072.RESETX(I) */
|
|
{ 5, 6, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TX_AMP/P48: U12.V3(I), U14.V1(I) */
|
|
{ 5, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CS_AD/P54: MAX5864.CS(I) */
|
|
{ 6, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* MIXER_SDATA/P27: 33pF, RFFC5072.SDATA(IO) */
|
|
{ 6, 7, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* TX/P42: U7.VCTL2(I), U10.VCTL2(I), U2.VCTL2(I) */
|
|
{ 6, 8, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* MIX_BYPASS/P34: U1.VCTL2(I), U11.VCTL1(I) */
|
|
{ 6, 9, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* !TX_AMP_PWR/P51: 10K PU, Q2.G(I), power to U25 (TX amp) */
|
|
|
|
/* SGPIO for sample transfer interface to HackRF CPLD. */
|
|
{ 0, 0, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO0/P75/BANK2F3M3: CPLD.89/HOST_DATA0(IO) */
|
|
{ 0, 1, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO1/BANK2F3M5: CPLD.79/HOST_DATA1(IO) */
|
|
{ 1, 15, scu_config_normal_drive_t { .mode=2, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO2/BANK2F3M9: CPLD.74/HOST_DATA2(IO) */
|
|
{ 1, 16, scu_config_normal_drive_t { .mode=2, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO3/BANK2F3M10: CPLD.72/HOST_DATA3(IO) */
|
|
{ 6, 3, scu_config_normal_drive_t { .mode=2, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO4/BANK2F3M14: CPLD.67/HOST_DATA4(IO) */
|
|
{ 6, 6, scu_config_normal_drive_t { .mode=2, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO5/BANK2F3M15: CPLD.64/HOST_DATA5(IO) */
|
|
{ 2, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO6/BANK2F3M16: CPLD.61/HOST_DATA6(IO) */
|
|
{ 1, 0, scu_config_normal_drive_t { .mode=6, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SGPIO7/P76/BANK2F3M7: CPLD.77/HOST_DATA7(IO) */
|
|
{ 9, 6, scu_config_normal_drive_t { .mode=6, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* SGPIO8/SGPIO_CLK/P60: SI5351C.CLK2(O) */
|
|
{ 4, 3, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=1 } }, /* SGPIO9/P77/BANK2F3M1: CPLD.91/HOST_CAPTURE(O) */
|
|
{ 1, 14, scu_config_normal_drive_t { .mode=6, .epd=0, .epun=0, .ehs=1, .ezi=0, .zif=0 } }, /* SGPIO10/P78/BANK2F3M8: CPLD.76/HOST_DISABLE(I) */
|
|
{ 1, 17, scu_config_normal_drive_t { .mode=6, .epd=1, .epun=1, .ehs=1, .ezi=0, .zif=0 } }, /* SGPIO11/P79/BANK2F3M11: CPLD.71/HOST_DIRECTION(I) */
|
|
{ 1, 18, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO12/BANK2F3M12: CPLD.70/HOST_INVERT(I) */
|
|
{ 4, 8, scu_config_normal_drive_t { .mode=4, .epd=1, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO13/BANK2F3M2: CPLD.90/HOST_SYNC_EN(I) */
|
|
{ 4, 9, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO14/BANK2F3M4: CPLD.81/CPLD_P81 */
|
|
{ 4, 10, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SGPIO15/BANK2F3M6: CPLD.78/CPLD_P78 */
|
|
|
|
/* HackRF: CPLD */
|
|
{ 6, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CPLD_TCK: CPLD.TCK(I), PortaPack CPLD.TCK(I) */
|
|
{ 6, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* CPLD_TDI: CPLD.TDI(I), PortaPack I2S0_RX_SDA(O), PortaPack CPLD.TDI(I) */
|
|
{ 6, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* CPLD_TMS: CPLD.TMS(I) */
|
|
{ 9, 5, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* CPLD_TDO: CPLD.TDO(O) */
|
|
|
|
/* PortaPack CPLD */
|
|
{ 1, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* SD_POW: PortaPack CPLD.TDO(O) */
|
|
{ 1, 8, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* SD_VOLT0: PortaPack CPLD.TMS(I) */
|
|
|
|
/* Miscellaneous */
|
|
{ 1, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P1_1/P74: 10K PU, BOOT0 */
|
|
{ 1, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P1_2/P73: 10K PD, BOOT1 */
|
|
{ 2, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* ISP: 10K PU, Unused */
|
|
{ 6, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_RX_MCLK: Unused */
|
|
{ 15, 4, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_RX_SCK: Unused */
|
|
}
|
|
};
|
|
#endif
|
|
|
|
static const std::array<scu_setup_t, 26> pins_setup_portapack { {
|
|
{ 2, 0, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* U0_TXD: PortaPack P2_0/IO_STBX */
|
|
{ 2, 1, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* U0_RXD: PortaPack P2_1/ADDR */
|
|
{ 2, 3, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SDA: PortaPack P2_3/LCD_TE */
|
|
{ 2, 4, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SCL: PortaPack P2_4/LCD_RDX */
|
|
{ 2, 8, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P2_8: 10K PD, BOOT2, DFU switch, PortaPack P2_8/<unused> */
|
|
{ 2, 9, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_9: 10K PD, BOOT3, PortaPack P2_9/LCD_WRX */
|
|
{ 2, 13, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_13: PortaPack P2_13/DIR */
|
|
{ 7, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_8: PortaPack GPIO3_8(IO) */
|
|
{ 7, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_9: PortaPack GPIO3_9(IO) */
|
|
{ 7, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_10: PortaPack GPIO3_10(IO) */
|
|
{ 7, 3, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_11: PortaPack GPIO3_11(IO) */
|
|
{ 7, 4, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_12: PortaPack GPIO3_12(IO) */
|
|
{ 7, 5, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_13: PortaPack GPIO3_13(IO) */
|
|
{ 7, 6, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_14: PortaPack GPIO3_14(IO) */
|
|
{ 7, 7, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_15: PortaPack GPIO3_15(IO) */
|
|
|
|
/* PortaPack: Audio */
|
|
{ 3, 0, scu_config_normal_drive_t { .mode=2, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* I2S0_TX_SCK: PortaPack I2S0_TX_SCK(I) */
|
|
{ 3, 1, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* I2S0_RX_WS: PortaPack I2S0_TX_WS(I). Input enabled to fold back into RX. */
|
|
{ 3, 2, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=0, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_RX_SDA: PortaPack I2S0_TX_SDA(I) */
|
|
{ 24, 2, scu_config_normal_drive_t { .mode=6, .epd=1, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* I2S0_TX_CLK: PortaPack I2S0_TX_MCLK */
|
|
|
|
/* PortaPack: SD card socket */
|
|
{ 24, 0, scu_config_normal_drive_t { .mode=4, .epd=1, .epun=1, .ehs=0, .ezi=1, .zif=1 } }, /* SD_CLK: PortaPack SD.CLK, enable input buffer for timing feedback? */
|
|
{ 1, 6, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* SD_CMD: PortaPack SD.CMD(IO) */
|
|
{ 1, 9, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* SD_DAT0: PortaPack SD.DAT0(IO) */
|
|
{ 1, 10, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* SD_DAT1: PortaPack SD.DAT1(IO) */
|
|
{ 1, 11, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* SD_DAT2: PortaPack SD.DAT2(IO) */
|
|
{ 1, 12, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* SD_DAT3: PortaPack SD.DAT3(IO) */
|
|
{ 1, 13, scu_config_normal_drive_t { .mode=7, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=0 } }, /* SD_CD: PortaPack SD.CD(O) */
|
|
} };
|
|
|
|
static const std::array<scu_setup_t, 6> pins_setup_spifi { {
|
|
{ 3, 3, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SPIFI_SCK: W25Q80BV.CLK(I), enable input buffer for timing feedback */
|
|
{ 3, 4, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SPIFI_SIO3/P82: W25Q80BV.HOLD(IO) */
|
|
{ 3, 5, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SPIFI_SIO2/P81: W25Q80BV.WP(IO) */
|
|
{ 3, 6, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SPIFI_MISO: W25Q80BV.DO(IO) */
|
|
{ 3, 7, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SPIFI_MOSI: W25Q80BV.DI(IO) */
|
|
{ 3, 8, scu_config_normal_drive_t { .mode=3, .epd=0, .epun=1, .ehs=1, .ezi=1, .zif=1 } }, /* SPIFI_CS/P68: W25Q80BV.CS(I) */
|
|
} };
|
|
|
|
static void setup_pin(const scu_setup_t& pin_setup) {
|
|
LPC_SCU->SFSP[pin_setup.port][pin_setup.pin] = pin_setup.config;
|
|
}
|
|
|
|
template<size_t N>
|
|
void setup_pins(const std::array<scu_setup_t, N>& pins_setup) {
|
|
for(const auto& pin_setup : pins_setup) {
|
|
setup_pin(pin_setup);
|
|
}
|
|
}
|
|
|
|
static void configure_spifi(void) {
|
|
setup_pins(pins_setup_spifi);
|
|
|
|
/* Tweak SPIFI mode */
|
|
LPC_SPIFI->CTRL =
|
|
(0xffff << 0) /* Timeout */
|
|
| (0x1 << 16) /* CS high time in "clocks - 1" */
|
|
| (0 << 21) /* 0: Attempt speculative prefetch on data accesses */
|
|
| (0 << 22) /* 0: No interrupt on command ended */
|
|
| (0 << 23) /* 0: SCK driven low after rising edge at which last bit of command is captured. Stays low while CS# is high. */
|
|
| (0 << 27) /* 0: Cache prefetching enabled */
|
|
| (0 << 28) /* 0: Quad protocol, IO3:0 */
|
|
| (1 << 29) /* 1: Read data sampled on falling edge of clock */
|
|
| (1 << 30) /* 1: Read data is sampled using feedback clock from SCK pin */
|
|
| (0 << 31) /* 0: DMA request disabled */
|
|
;
|
|
|
|
/* Throttle up the SPIFI interface to 96MHz (IDIVA=PLL1 / 3) */
|
|
LPC_CGU->IDIVB_CTRL.word =
|
|
( 0 << 0) /* PD */
|
|
| ( 2 << 2) /* IDIV (/3) */
|
|
| ( 1 << 11) /* AUTOBLOCK */
|
|
| ( 9 << 24) /* PLL1 */
|
|
;
|
|
}
|
|
|
|
void configure_pins_portapack(void) {
|
|
LPC_GPIO->DIR[1] |= (1 << 13) | (1 << 10);
|
|
LPC_GPIO->DIR[3] |= (0xff << 8);
|
|
LPC_GPIO->DIR[5] |= (1 << 4) | (1 << 1) | (1 << 0);
|
|
setup_pins(pins_setup_portapack);
|
|
}
|
|
|
|
static const motocon_pwm_resources_t motocon_pwm_resources = {
|
|
.base = { .clk = &LPC_CGU->BASE_APB1_CLK, .stat = &LPC_CCU1->BASE_STAT, .stat_mask = (1 << 1) },
|
|
.branch = { .cfg = &LPC_CCU1->CLK_APB1_MOTOCON_PWM_CFG, .stat = &LPC_CCU1->CLK_APB1_MOTOCON_PWM_STAT },
|
|
.reset = { .output_index = 38 },
|
|
};
|
|
|
|
static const scu_setup_t pin_setup_vaa_enablex_pwm = { 5, 0, scu_config_normal_drive_t { .mode=1, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } };
|
|
static const scu_setup_t pin_setup_vaa_enablex_gpio = { 5, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } };
|
|
|
|
/* VAA powers:
|
|
* MAX5864 analog section.
|
|
* MAX2837 registers and other functions.
|
|
* RFFC5072 analog section.
|
|
*
|
|
* Beware that power applied to pins of the MAX2837 may
|
|
* show up on VAA and start powering other components on the
|
|
* VAA net. So turn on VAA before driving pins from MCU to
|
|
* MAX2837.
|
|
*/
|
|
void vaa_power_on(void) {
|
|
/* Very twitchy process for powering up VAA without glitching the 3.3V rail, which can send the
|
|
* microcontroller into reset.
|
|
*
|
|
* Controlling timing while running from SPIFI flash is tricky, hence use of a PWM peripheral...
|
|
*/
|
|
|
|
/* Configure and enable MOTOCONPWM peripheral clocks.
|
|
* Assume IDIVC is running the post-bootloader configuration, outputting 96MHz derived from PLL1.
|
|
*/
|
|
base_clock_enable(&motocon_pwm_resources.base);
|
|
branch_clock_enable(&motocon_pwm_resources.branch);
|
|
peripheral_reset(&motocon_pwm_resources.reset);
|
|
|
|
/* Combination of pulse duration and duty cycle was arrived at empirically, to keep supply glitching
|
|
* to +/- 0.15V.
|
|
*/
|
|
const uint32_t cycle_period = 256;
|
|
uint32_t enable_period = 2;
|
|
LPC_MCPWM->TC2 = 0;
|
|
LPC_MCPWM->MAT2 = cycle_period - enable_period;
|
|
LPC_MCPWM->LIM2 = cycle_period;
|
|
|
|
/* Switch !VAA_ENABLE pin from GPIO to MOTOCONPWM peripheral output, now that the peripheral is configured. */
|
|
setup_pin(pin_setup_vaa_enablex_pwm); // P5_0 /GPIO2[ 9]/MCOB2: !VAA_ENABLE, 10K PU
|
|
|
|
/* Start the PWM operation. */
|
|
LPC_MCPWM->CON_SET = (1 << 16);
|
|
|
|
/* Wait until VAA rises to approximately 90% of final voltage. */
|
|
/* Timing assumes we're running immediately after the bootloader: 96 MHz from IRC+PLL1
|
|
*/
|
|
while(enable_period < cycle_period) {
|
|
{ volatile uint32_t delay = 2000; while(delay--); }
|
|
enable_period <<= 1;
|
|
LPC_MCPWM->MAT2 = cycle_period - enable_period;
|
|
}
|
|
|
|
/* Hold !VAA_ENABLE active using a GPIO, so we can reclaim and shut down the MOTOCONPWM peripheral. */
|
|
LPC_GPIO->CLR[2] = (1 << 9); // !VAA_ENABLE
|
|
LPC_GPIO->DIR[2] |= (1 << 9);
|
|
setup_pin(pin_setup_vaa_enablex_gpio); // P5_0 /GPIO2[ 9]/MCOB2: !VAA_ENABLE, 10K PU
|
|
|
|
peripheral_reset(&motocon_pwm_resources.reset);
|
|
branch_clock_disable(&motocon_pwm_resources.branch);
|
|
base_clock_disable(&motocon_pwm_resources.base);
|
|
}
|
|
|
|
void vaa_power_off(void) {
|
|
// TODO: There's a lot of other stuff that must be done to prevent
|
|
// leakage from +3V3 into VAA.
|
|
LPC_GPIO->W2[9] = 1;
|
|
}
|
|
|
|
/**
|
|
* @brief Early initialization code.
|
|
* @details This initialization must be performed just after stack setup
|
|
* and before any other initialization.
|
|
*/
|
|
extern "C" void __early_init(void) {
|
|
/*
|
|
* Upon exit from bootloader into SPIFI boot mode:
|
|
*
|
|
* Enabled:
|
|
* PLL1: IRC, M=/24, N=/1, P=/1, autoblock, direct = 288 MHz
|
|
* IDIVA: IRC /1 = 12 MHz
|
|
* IDIVB: PLL1 /9, autoblock = 32 MHz
|
|
* IDIVC: PLL1 /3, autoblock = 96 MHz
|
|
* IDIVD: IRC /1 = 12 MHz
|
|
* IDIVE: IRC /1 = 12 MHz
|
|
* BASE_M4_CLK: IDIVC, autoblock
|
|
* BASE_SPIFI_CLK: IDIVB, autoblock
|
|
*
|
|
* Disabled:
|
|
* XTAL_OSC
|
|
* PLL0USB
|
|
* PLL0AUDIO
|
|
*/
|
|
/* LPC43xx M4 takes about 500 usec to get to __early_init
|
|
* Before __early_init, LPC bootloader runs and starts our code. In user code, the process stack
|
|
* is initialized, hardware floating point is initialized, and stacks are zeroed,
|
|
*/
|
|
const uint32_t CORTEX_M4_CPUID = 0x410fc240;
|
|
const uint32_t CORTEX_M4_CPUID_MASK = 0xff0ffff0;
|
|
|
|
if( (SCB->CPUID & CORTEX_M4_CPUID_MASK) == CORTEX_M4_CPUID ) {
|
|
/* Enable unaligned exception handler */
|
|
SCB_CCR |= (1 << 3);
|
|
|
|
/* Enable MemManage, BusFault, UsageFault exception handlers */
|
|
SCB_SHCSR |= (1 << 18) | (1 << 17) | (1 << 16);
|
|
|
|
/* "The reset delay is counted in IRC clock cycles. If the core frequency
|
|
* CCLK is much higher than the IRC frequency, add a software delay of
|
|
* fCCLK/fIRC clock cycles between resetting and accessing any of the
|
|
* peripheral blocks."
|
|
*/
|
|
|
|
/* Don't reset these peripherals, as they're operating during initialization:
|
|
* WWDT, CREG, SCU, SPIFI
|
|
*/
|
|
LPC_RGU->RESET_CTRL[0] =
|
|
(1U << 16) // LCD_RST
|
|
| (1U << 17) // USB0_RST
|
|
| (1U << 18) // USB1_RST
|
|
| (1U << 19) // DMA_RST
|
|
| (1U << 20) // SDIO_RST
|
|
| (1U << 21) // EMC_RST
|
|
| (1U << 22) // ETHERNET_RST
|
|
| (1U << 28) // GPIO_RST
|
|
;
|
|
LPC_RGU->RESET_CTRL[1] =
|
|
(1U << 0) // TIMER0_RST
|
|
| (1U << 1) // TIMER1_RST
|
|
| (1U << 2) // TIMER2_RST
|
|
| (1U << 3) // TIMER3_RST
|
|
| (1U << 4) // RITIMER_RST
|
|
| (1U << 5) // SCT_RST
|
|
| (1U << 6) // MOTOCONPWM_RST
|
|
| (1U << 7) // QEI_RST
|
|
| (1U << 8) // ADC0_RST
|
|
| (1U << 9) // ADC1_RST
|
|
| (1U << 10) // DAC_RST
|
|
| (1U << 12) // UART0_RST
|
|
| (1U << 13) // UART1_RST
|
|
| (1U << 14) // UART2_RST
|
|
| (1U << 15) // UART3_RST
|
|
| (1U << 16) // I2C0_RST
|
|
| (1U << 17) // I2C1_RST
|
|
| (1U << 18) // SSP0_RST
|
|
| (1U << 19) // SSP1_RST
|
|
| (1U << 20) // I2S_RST
|
|
| (1U << 22) // CAN1_RST
|
|
| (1U << 23) // CAN0_RST
|
|
| (1U << 24) // M0APP_RST
|
|
| (1U << 25) // SGPIO_RST
|
|
| (1U << 26) // SPI_RST
|
|
| (1U << 28) // ADCHS_RST
|
|
;
|
|
|
|
configure_spifi();
|
|
|
|
LPC_CCU1->CLK_M4_M0APP_CFG.RUN = true;
|
|
LPC_CREG->M0APPMEMMAP = LPC_SPIFI_DATA_CACHED_BASE + 0x0;
|
|
LPC_RGU->RESET_CTRL[1] = 0;
|
|
|
|
/* Prevent the M4 from doing any more initializing by sleep-waiting forever...
|
|
* ...until the M0 resets the M4 with some code to run.
|
|
*/
|
|
while(1) {
|
|
__WFE();
|
|
}
|
|
}
|
|
}
|
|
|
|
extern "C" void __late_init(void) {
|
|
/*
|
|
* System initializations.
|
|
* - HAL initialization, this also initializes the configured device drivers
|
|
* and performs the board-specific initializations.
|
|
* - Kernel initialization, the main() function becomes a thread and the
|
|
* RTOS is active.
|
|
*/
|
|
halInit();
|
|
|
|
/* After this call, scheduler, systick, heap, etc. are available. */
|
|
/* By doing chSysInit() here, it runs before C++ constructors, which may
|
|
* require the heap.
|
|
*/
|
|
chSysInit();
|
|
}
|
|
|
|
/**
|
|
* @brief Board-specific initialization code.
|
|
* @todo Add your board-specific code, if any.
|
|
*/
|
|
extern "C" void boardInit(void) {
|
|
vaa_power_on();
|
|
LPC_GPIO->W3[6] = 1;
|
|
}
|
|
|
|
extern "C" void _default_exit(void) {
|
|
LPC_GPIO->W3[6] = 0;
|
|
vaa_power_off();
|
|
|
|
chSysDisable();
|
|
|
|
systick_stop();
|
|
|
|
/* Don't reset these peripherals, as they're operating during shutdown:
|
|
* WWDT, CREG, SCU, SPIFI, GPIO, M0APP
|
|
*/
|
|
LPC_RGU->RESET_CTRL[0] =
|
|
(1U << 16) // LCD_RST
|
|
| (1U << 17) // USB0_RST
|
|
| (1U << 18) // USB1_RST
|
|
| (1U << 19) // DMA_RST
|
|
| (1U << 20) // SDIO_RST
|
|
| (1U << 21) // EMC_RST
|
|
| (1U << 22) // ETHERNET_RST
|
|
//| (1U << 28) // GPIO_RST
|
|
;
|
|
LPC_RGU->RESET_CTRL[1] =
|
|
(1U << 0) // TIMER0_RST
|
|
| (1U << 1) // TIMER1_RST
|
|
| (1U << 2) // TIMER2_RST
|
|
| (1U << 3) // TIMER3_RST
|
|
| (1U << 4) // RITIMER_RST
|
|
| (1U << 5) // SCT_RST
|
|
| (1U << 6) // MOTOCONPWM_RST
|
|
| (1U << 7) // QEI_RST
|
|
| (1U << 8) // ADC0_RST
|
|
| (1U << 9) // ADC1_RST
|
|
| (1U << 10) // DAC_RST
|
|
| (1U << 12) // UART0_RST
|
|
| (1U << 13) // UART1_RST
|
|
| (1U << 14) // UART2_RST
|
|
| (1U << 15) // UART3_RST
|
|
| (1U << 16) // I2C0_RST
|
|
| (1U << 17) // I2C1_RST
|
|
| (1U << 18) // SSP0_RST
|
|
| (1U << 19) // SSP1_RST
|
|
| (1U << 20) // I2S_RST
|
|
| (1U << 22) // CAN1_RST
|
|
| (1U << 23) // CAN0_RST
|
|
//| (1U << 24) // M0APP_RST
|
|
| (1U << 25) // SGPIO_RST
|
|
| (1U << 26) // SPI_RST
|
|
| (1U << 28) // ADCHS_RST
|
|
;
|
|
}
|