diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index d6777d4..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: Teensy CI -on: - push: - paths: - - '.github/workflows/build.yml' - - 'diff/**' - -jobs: - build: - name: Build - runs-on: ubuntu-22.04 - defaults: - run: - shell: bash - working-directory: teensy - steps: - - uses: actions/checkout@v5 - - - name: Install PlatformIO - run: | - curl -fsSL -o get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py - python3 get-platformio.py - rm get-platformio.py - - echo $PATH - mkdir -p ~/.local/bin - ln -s ~/.platformio/penv/bin/platformio ~/.local/bin/platformio - ln -s ~/.platformio/penv/bin/pio ~/.local/bin/pio - ln -s ~/.platformio/penv/bin/piodebuggdb ~/.local/bin/piodebuggdb - - - name: Pre-build to fetch sources - run: | - # Build but ignore failure, will install pre-requisites - pio run -e teensy36 || true - pio run -e teensy41 || true - - - name: Patch Teensy/Arduino Source - run: | - # Arduino - patch -d ~/.platformio/ -p0 < diff/arduino.py.diff - - # Teensy3.6 - patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.c.diff - patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.h.diff - patch -d ~/.platformio/ -p0 < diff/teensy3/usb_inst.cpp.diff - patch -d ~/.platformio/ -p0 < diff/teensy3/yield.cpp.diff - - # Teensy4.1 - # patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.c.diff - # patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.h.diff - # patch -d ~/.platformio/ -p0 < diff/teensy4/usb_inst.cpp.diff - # patch -d ~/.platformio/ -p0 < diff/teensy4/yield.cpp.diff - - - name: Build for Teensy 3.1 - run: | - pio run -e teensy31 - - - name: Build for Teensy 3.6 - run: | - pio run -e teensy36 - - # - name: Build for Teensy 4.1 - # run: | - # pio run -e teensy41 - - - name: Prepare firmware folder - run: | - mkdir build - cp .pio/build/teensy31/firmware.hex build/teensy31_firmware.hex - cp .pio/build/teensy36/firmware.hex build/teensy36_firmware.hex - # cp .pio/build/teensy41/firmware.hex build/teensy41_firmware.hex - - - name: Upload Teensy Firmware - uses: actions/upload-artifact@v4 - with: - name: teensy_firmware - path: build diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 64abc3b..0000000 --- a/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch -# PlatformIO installer -get-platformio.py diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 557c5e8..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "scripts/BusPirate-BPIO2-flatbuffer-interface"] - path = scripts/BusPirate-BPIO2-flatbuffer-interface - url = https://github.com/DangerousPrototypes/BusPirate-BPIO2-flatbuffer-interface diff --git a/README.md b/README.md index 18e8d32..46a15f9 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,12 @@ tips on what hardware is needed. Here's a short list: -* [EC](https://en.wikipedia.org/wiki/Embedded_controller) & - CPU [UART](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter) (aka serial port), both open and closed case +* EC & CPU [UART](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter) (aka serial port), both open and closed case * EC [JTAG](https://en.wikipedia.org/wiki/JTAG) * PD SWD * SOC SPI Flash (BIOS) -## CCD (Closed Case Debug) +## CCD EC & CPU UARTs can be accessed without opening the DUT (Device Under Test, aka the framework laptop) up by connecting to the USB Type-C ports on the @@ -22,10 +21,11 @@ right of the device (side with the power button). The USB Type-C port needs to be told to go to debug accessory mode (see [USB Type-C Cable and Connector Specifications](https://www.usb.org/document-library/usb-type-cr-cable-and-connector-specification-release-23), section "Chapter B, Debug Accessory Mode"). -Then the UART TX and RX can be connected to the SBU lines (see [below section](#making-a-framework-ccd-adaptor-from-scratch) for pinout). +Then the UART TX and RX can be connected to the SBU lines (TODO: which way?). -The one of the ports is going to have EC UART (generally top right port of -a 13 inch), another has the CPU UART. +The upper port is going to have EC UART. + +The lower port is going to have CPU UART. Note: Inserting the debugger into the DUT in the flipped orientation will swap RX and TX, resulting in not much happening. @@ -34,16 +34,15 @@ Note 2: This is similar to [Chrome OS CCD](https://chromium.googlesource.com/chr **but not quite**. Chromebooks use D+ & D- USB from the GSC over the SBU lines instead of simple UART signals. -Note 3: If you happen to have a [Chrome OS Servo v4](https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/main/docs/servo_v4.md) -there's a way it can be configured to do this kind of UART debugging, +Note 3: If you happen to have a [Chrome OS Servo v4](https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/main/docs/servo_v4.md) there's a way it can be configured to do this kind of UART debugging (TODO: add this in), despite UART not being common on chromebooks. That feature was added to debug -some Android phones. If you're still interested in this method, -`dut-control sbu_uart_sel:uart` is what you're looking for, and -perhaps `dut-control sbu_flip_sel:on`. +some Android phones. Thank you [@DHowett for the blog post](https://www.howett.net/posts/2023-04-framework-ec-card) that inspired this document and tool incubation. +TODO: Add Josh Cook's https://i2clabs.com.au/ec-debug-expansion-card/ + ### Making a Framework CCD Adaptor from Scratch One needs a [USB Type-C Male breakout board](https://www.digikey.com/en/products/detail/saiko-systems-ltd./BRK-USB-CPV3.0/15283090) @@ -52,27 +51,22 @@ will probably work fine). Note: A female breakout board does not work as Type-C cables do not pass both CC signals. -Type C Male (toward DUT) | UART Interface Board (eg: FTDI) ---------------------------------- | ------------------------ -A5 (CC1) | 5.1 kΩ resistor to GND (Note 1) -B5 (CC2) | 5.1 kΩ resistor to GND -A8 (SBU 1) dut uart TX (Note 3) | 1k (Note 2) resistor to debugger TX -B8 (SBU 2) dut uart RX | 1k resistor to debugger RX -A4, A9, B4, B9 (VBUS) | Do not inject power into this from an interface board! The DUT will also be sourcing 5V on this, use only as a signal that the DUT is alive. -A1, A12, B1, B12 (GND) | GND +Type C Male (toward DUT) | UART Interface Board (eg: FTDI) +------------------------ | ------------------------ +A8 (SBU 1) | 1k (Note 1) resistor to TX (TODO: which way?) +B8 (SBU 2) | 1k resistor to RX +A4, A9, B4, B9 (VBUS) | VBUS, 5V +A5 (CC1) | 22 kΩ resistor to VBUS (Note 2) +B5 (CC2) | 56 kΩ resistor to VBUS +A1, A12, B1, B12 (GND) | GND -Note 1: The table above describes the Rd/Rd (both pullup to GND) configuration, -this makes the DUT provide voltage on VBUS (useful in some cases if you want -to power sections of a debug card). - -Note 2: The 1k resistor is for safety and power sequencing (eg: not +Note 1: The 1k resistor is for safety and power sequencing (eg: not killing either the DUT or the interface board if it's off while the other is on, or if the RX/TX is flipped). Feel free to substitute with something else (or 0 ohm) in a pinch. -Note 3: On a laptop, A8 (SBU 1) (aka dut TX) pin is on the same side of the -Type-C port as the keyboard (aka [C panel](https://www.blackview.hk/blog/computers/laptop-a-b-c-d-sides)). -B9 (SBU 2) (aka dut RX) is toward the bottom of the device (D panel) +Note 2: The table above describes the Rp/Rp (both pullup to VBUS) configuration. +Rd/Rd to GND should also work. ## Open Case Debugging @@ -88,105 +82,34 @@ This connector provides a way to program/debug the EC, see the EC booting, then see the CPU boot logs. While the EC is very chatty and even offers a console, the CPU will probably -not say anything unless the software (firmware and/or OS) [is told to use the -serial port](#cpu-uart). - -This connector is usually placed near the EC chip, usually bottom right area -of the board, near the keyboard connector and possibly even near the BIOS chip. -This area of the board is usually farther away from the main CPU, memory, -storage and beefy power stuff for space reasons. +not say anything unless the software (firmware and/or OS) is told to use the +serial port. -This connector generally comes unpopulated on mass production boards, -one needs to buy and solder it to make use of the signals. +TODO: Describe connector location. 10 pin connector, 0.5mm pitch, flat flex cable: -* [Connector](https://www.hirose.com/product/p/CL0580-0412-7-10), -[DigiKey (H125812CT-ND)](https://www.digikey.com/en/products/detail/hirose-electric-co-ltd/FH19C-10S-0-5SH-10/4283386) +* [Connector](https://www.molex.com/en-us/products/part-detail/5034801000), +[DigiKey (WM1389CT-ND)](https://www.digikey.com/en/products/detail/molex/5034801000/2356624) * [Flex Cable](https://www.molex.com/en-us/products/part-detail/0151660111), [DigiKey (WM21810-ND)](https://www.digikey.com/en/products/detail/molex/0151660111/3280993). +TODO: figure out if we have this publicly documented somewhere else on github. + Pinout: -| Pin | Name | Function | -|-----|--------------------|-------------------| -| 1 | `3VL_EC` | | -| 2 | `UART_0_CRXD_DTXD` | CPU UART RX | -| 3 | `EC_JTAG_TMS` | EC JTAG TMS | -| 4 | `EC_JTAG_TCK` | EC JTAG/SWD Clock | -| 5 | `EC_JTAG_TDO` | EC JTAG/SWD Data | -| 6 | `ECTX_DRX` | EC UART TX | -| 7 | `ECRX_DTX` | EC UART RX | -| 8 | `UART_0_CTXD_DRXD` | CPU UART TX | -| 9 | `EC_RST#` | EC Reset | -| 10 | `GND` | Ground | - -#### TGL JECDB and JSWDB - -TigerLake (11th Gen Intel Core) has a slightly different pinout on JECDB: - -| Pin | Name | Function | -|-----|--------------------|-------------------| -| 1 | `3VL_EC` | | -| 2 | `EC_JTAG_TDI` | EC JTAG TDI | -| 3 | `EC_JTAG_TMS` | EC JTAG TMS | -| 4 | `EC_JTAG_TCK` | EC JTAG/SWD Clock | -| 5 | `EC_JTAG_TDO` | EC JTAG/SWD Data | -| 6 | `ECTX_DRX` | EC UART TX | -| 7 | `ECRX_DTX` | EC UART RX | -| 8 | `UART_0_CTXD_DRXD` | CPU UART TX | -| 9 | `GPIO170_STRAP` | | -| 10 | `GND` | Ground | - -Because TGL didn't have UART on JECDB, it also had `JSWDB`, which ADL/RPL(Iris) -carried forward, but eventually got removed because it was redundant: - -| Pin | Name | Function | -|-----|--------------------|-------------------| -| 1 | NC | | -| 2 | NC | | -| 3 | NC | | -| 4 | NC | | -| 5 | `GND` | Ground | -| 6 | NC | | -| 7 | NC | | -| 8 | `EC_UART0_RX` | EC UART RX | -| 9 | `EC_UART0_TX` | EC UART TX | -| 10 | `UART_2_CTXD_DRXD` | CPU UART TX | -| 11 | `UART_2_CRXD_DTXD` | CPU UART RX | -| 12 | `GND` | Ground | - -#### Voltage References - -Warning: Do not inject voltage on any pins when the device on the other side -(EC or CPU, as applicable) is off. Doing so will cause current leaks that -will cause troubles using the debugger and at worst might damange the DUT. - -All EC pins are referenced to the `3VL_EC` rail (and also happens to be -3.3V on every device we made so far). - -`EC_RST#` is an OD rail with a pullup on the DUT. Do not output high on -this rail as it might cause a short when the board gets reset in other ways. - -CPU UARTs unfortunatelly do not have a voltage reference pin. -In order to avoid leaks we generally implemented a pattern of open drain -level shifters on the DUT side. All you have to do to use these pins safely -is use an open drain for `DEBUG_TX_DUT_RX` and a hiz input -(without a debugger pullup) for `DEBUG_RX_DUT_TX`. The CPU UART pins are -generally 3.3V. In a pinch they can be used directly with a uart interface, -but those pins should only be connected after CPU turns on, and -disconnected before a shutdown or a reboot. - -#### Flashing Nuvoton EC - -Except the Laptop 13 Intel 11th-13th Gen, all Framework Computer systems use Nuvoton EC chips. -They have a convenient mechanism to update the EC firmware through the UART pins. - -Pull EC UART TX low with 4.7k-10k Ohm resistor while resetting it and the IC stays in bootloader mode. -Then the uartupdatetool can be used to flash it through UART TX/RX. -Find the source for this tool in the EC repository unter `utils/uut`. - -After flashing is done, the IC does not reset by itself, so just toggle the reset pin once more. +1. 3VL_EC +2. UART_0_CRXD_DTXD +3. EC_JTAG_TMS +4. EC_JTAG_TCK +5. EC_JTAG_TDO +6. EC_UART0_TX +7. EC_UART0_RX +8. UART_0_CTXD_DRXD +9. EC_RST# +10. GND + +TODO: Figure out & Document voltage references across all boards. ### JSPI @@ -197,64 +120,27 @@ from a failed BIOS upgrade. Note: While one can reflash the BIOS with this connector the CPU might not always boot any BIOS (eg: self signed coreboot). -This connector is usually placed near the BIOS chip. It's labeled -on the silkscreen using the "JSPI" label. - -This connector generally comes unpopulated on mass production boards, -one needs to buy and solder it to make use of the signals. +TODO: Describe connector location. 6 pin connector, 0.5mm pitch, flat flex cable: -* [Connector](https://www.hirose.com/product/p/CL0580-0409-2-10), -[Digikey (H125824CT-ND)](https://www.digikey.com/en/products/detail/hirose-electric-co-ltd/FH19C-6S-0-5SH-10/4283419) +* [Connector](https://www.molex.com/en-us/products/part-detail/5034800600), +[Digikey (WM1387CT-ND)](https://www.digikey.com/en/products/detail/molex/5034800600/2356622) * [Flex Cable](https://www.molex.com/en-us/products/part-detail/0151660063), [Digikey (WM25052-ND)](https://www.digikey.com/en/products/detail/molex/0151660063/3280945) (ignore the 10 pin picture on molex's website, it's 6 pin) Pinout: -1. `GND` -2. `SOC_SPI_0_CLK` -3. `SOC_SPI_0_MISO` -4. `SOC_SPI_0_MOSI` -5. `SOC_SPI_0_CS#` -6. `SPI_VCC` - -#### Voltage References - -All SPI pins are referenced to the `SPI_VCC` rail. `SPI_VCC` is generally -what powers the spi flash chip as well. - -Board | `SPI_VCC` ---------- | ---- -Sakura | 1.8V -Tulip | 1.8V -Dogwood | 1.8V -Lilac | 1.8V -Marigold | 1.8V -Azalea | 1.8V -Lotus | 1.8V -Tulip | 1.8V -ADL | 3.3V -Sunflower | 3.3V -Iris | 3.3V -Banshee | 3.3V -TGL | 3.3V - -On later boards we have guaranteed to have 33 ohm resistors between the SPI flash -and the CPU, meaning if a debugger is used, the debugger will win a drive fight. - -Injecting VCC into the motherboard is not recommended. The CPU should be -turned on, kept in a quiet state, then the SPI flash programmed based -on the voltage reference. Turning on either `SPI_VCC` or raising the -voltage of any of the SPI pins while the CPU is off causes leaks that might -damage hardware. - -#### ROM Flash - -The flash chip itself uses WSON8 8x6mm footprint. -Unfortunately it cannot be flashed using the traditional clips that work on SOIC8 chips. -But you can get special pogo pin connectors to press onto the chips leads and flash it. -Or get a WSON8 socket. +1. GND +2. SOC_SPI_0_CLK +3. SOC_SPI_0_D1 +4. SOC_SPI_0_D0 +5. SOC_SPI_0_CS#0 +6. 3V_SPI + +TODO: Figure out & Document voltage references across all boards. + +TODO: Figure out how to avoid leaks when flashing ### JPD @@ -262,112 +148,27 @@ This connector can be used to flash and debug the PD chips. Unless you're really into USB Type-C and have the Cypress SDK ready you probably don't care about this. -This connector is generally placed near the top of the board (though possibly -under a heatsink, particularly on the 16 inch). Usually on each side of the -device near the type-C ports. - -This connector generally comes unpopulated on mass production boards, -one needs to buy and solder it to make use of the signals. +TODO: Describe connector location. 6 pin connector, 0.5mm pitch, flat flex cable: -* [Connector](https://www.hirose.com/product/p/CL0580-0409-2-10), -[Digikey (H125824CT-ND)](https://www.digikey.com/en/products/detail/hirose-electric-co-ltd/FH19C-6S-0-5SH-10/4283419) * [Flex Cable](https://www.molex.com/en-us/products/part-detail/0151660063), [Digikey (WM25052-ND)](https://www.digikey.com/en/products/detail/molex/0151660063/3280945) (ignore the 10 pin picture on molex's website, it's 6 pin) +* [Connector](https://www.molex.com/en-us/products/part-detail/5034800600), +[Digikey (WM1387CT-ND)](https://www.digikey.com/en/products/detail/molex/5034800600/2356622) Pinout: -1. `VCC` -2. `GND` -3. `XRES` -4. `SWD_CLK` -5. `SWD_IO` - -## EC UART - -Once connected to the EC UART (either open case or closed case, see above), the -Embedded Controller's command prompt can be reached. The UART settings are -`115200 8N1`. - -`help` will give a list of available commands. `help $command` for help -specific to a certain command. - -Interesting commands: -* `powerbtn` - simulates button press -* `apshutdown` - forces CPU off -* `version` - gives the EC version (generally matches BIOS version) - -## CPU UART - -Once connected to the CPU UART (either open case or closed case, see above) -the port can be used for a variety of uses: - -### Linux - -Once the `Advanced > Serial Console` BIOS option is enabled, a new `/dev/ttyS4` -device will show up under Linux (at least on AMD systems). - -This serial device is useful to manage a linux system even in cases where doing -it over the display is less desired (ex: debugging crashes, lights out -management over the text console without KVMs involving screen output) - -#### Kernel console - -`console=ttyS4,115200` can be added to the kernel command line (just before an -entry of `console=tty0`, otherwise you might not see any more output on the -normal screen). This way the kernel will output any messages to the UART -console as well. `loglevel=9` is also useful for debugging the kernel messages -while doing this. If there's someone listening on the other end of the UART -port any kernel crashes or restarts might be easier to root cause. - -#### Getty - -One can login to the linux system via this UART console, a -[getty](https://en.wikipedia.org/wiki/Getty_(unix)) can be started: -`sudo systemctl enable --now getty@ttyS4.service` - -Note: the getty will use the currently configured baud rate. If you're already -using the kernel console instructions above, this will be 115200, otherwise -you might have to adjust the systemd job for the desired serial settings. - -Once the service is enabled a login prompt will appear on the uart console. -With the appropriate authetication the system can be managed over the UART -console with no other graphics or networking running. - -#### Hardware Support - -| Codename | Type-C Port | Commandline parameter | Function | Flipped? | BIOS Ver | -|-----------|--------------|---------------------------|----------|----------|----------| -| Dogwood | Top Back | `console=ttyS4,115200` | Full TTY | No | 3.00+ | -| Lotus | Middle Right | | | | N/A | -| Tulip | Middle Right | `console=ttyS4,115200` | Full TTY | Yes | 3.00+ | -| Lilac | Back Left | `console=ttyS4,115200` | Full TTY | No | 3.00+ | -| Azalea | Front Right | | | | N/A | -| TGL | N/A | | | | | -| ADL/Iris | Back Left | `console=ttyS0,115200n8` | | | N/A | -| Marigold | Front Right | `console=ttyS0,115200n8` | | No | N/A | -| Sakura | Front Right | `console=ttyS0,115200n8` | Full TTY | No | 3.00+ | -| Sunflower | Front Right | `console=uart,0xfe03e000` | Log only | No | 3.00+ | - -ADL, Iris, Azalea, Lotus, Marigold have support in hardware but the BIOS does not expose it to the OS. - -### BIOS - -The BIOS settings can be managed through the CPU UART console by enabling -`Advanced > Console Redirect Configuration > Console Serial Redirect`. -It's also worth double-checking if the -`Advanced > Console Redirect Configuration > MMIO_UART0 (FCH) > PortEnable` -setting is set to Enabled. - -Once that's done, the BIOS should be visible as soon as the next reboot on the -UART console. The uart settings of the serial monitor match the settings -configured in the bios, the default is 115200 8N1. - -Normal boot keys like F2 and F12 should also work to interrupt the boot process. +1. VCC +2. GND +3. XRES +4. SWD_CLK +5. SWD_IO +## Framework Light Debug Tool -## Dependencies +A tool to interface to all of the above interfaces was developed. It can either +be used in a open case or closed case configuration. It's in an expansion +card form factor, so it can be docked inside a DUT. -Note that on Fedora installing libftdi is not enough to satisfy the library dependencies -One has to install libftdi-devel +TODO: Link or perhaps delete section for now. diff --git a/light/.gitignore b/light/.gitignore deleted file mode 100644 index 6f49e84..0000000 --- a/light/.gitignore +++ /dev/null @@ -1 +0,0 @@ -references/ diff --git a/light/README.md b/light/README.md deleted file mode 100644 index 29fdeae..0000000 --- a/light/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Framework Light Debug Tool - -A tool to connect to the computer debug interfaces was developed. It can either be used in a open case or closed case configuration. It's in an expansion card form factor, so it can be docked inside a DUT. - -It's based around an FT4232 for ease of development and broad software tool support. - diff --git a/light/kicad/fp-info-cache b/light/fp-info-cache similarity index 100% rename from light/kicad/fp-info-cache rename to light/fp-info-cache diff --git a/light/kicad/libraries/5034800600.kicad_sym b/light/libraries/5034800600.kicad_sym similarity index 100% rename from light/kicad/libraries/5034800600.kicad_sym rename to light/libraries/5034800600.kicad_sym diff --git a/light/kicad/libraries/5034801000.kicad_sym b/light/libraries/5034801000.kicad_sym similarity index 100% rename from light/kicad/libraries/5034801000.kicad_sym rename to light/libraries/5034801000.kicad_sym diff --git a/light/kicad/libraries/SN74AVC4T774RSVR.kicad_sym b/light/libraries/SN74AVC4T774RSVR.kicad_sym similarity index 100% rename from light/kicad/libraries/SN74AVC4T774RSVR.kicad_sym rename to light/libraries/SN74AVC4T774RSVR.kicad_sym diff --git a/light/kicad/libraries/footprints.pretty/503480-0600_MOL.kicad_mod b/light/libraries/footprints.pretty/503480-0600_MOL.kicad_mod similarity index 100% rename from light/kicad/libraries/footprints.pretty/503480-0600_MOL.kicad_mod rename to light/libraries/footprints.pretty/503480-0600_MOL.kicad_mod diff --git a/light/kicad/libraries/footprints.pretty/CON_5034801000_MOL.kicad_mod b/light/libraries/footprints.pretty/CON_5034801000_MOL.kicad_mod similarity index 100% rename from light/kicad/libraries/footprints.pretty/CON_5034801000_MOL.kicad_mod rename to light/libraries/footprints.pretty/CON_5034801000_MOL.kicad_mod diff --git a/light/kicad/libraries/footprints.pretty/RSV0016A.kicad_mod b/light/libraries/footprints.pretty/RSV0016A.kicad_mod similarity index 100% rename from light/kicad/libraries/footprints.pretty/RSV0016A.kicad_mod rename to light/libraries/footprints.pretty/RSV0016A.kicad_mod diff --git a/light/kicad/light.kicad_pcb b/light/light.kicad_pcb similarity index 100% rename from light/kicad/light.kicad_pcb rename to light/light.kicad_pcb diff --git a/light/kicad/light.kicad_prl b/light/light.kicad_prl similarity index 100% rename from light/kicad/light.kicad_prl rename to light/light.kicad_prl diff --git a/light/kicad/light.kicad_pro b/light/light.kicad_pro similarity index 100% rename from light/kicad/light.kicad_pro rename to light/light.kicad_pro diff --git a/light/kicad/light.kicad_sch b/light/light.kicad_sch similarity index 100% rename from light/kicad/light.kicad_sch rename to light/light.kicad_sch diff --git a/light/kicad/sym-lib-table b/light/sym-lib-table similarity index 100% rename from light/kicad/sym-lib-table rename to light/sym-lib-table diff --git a/scripts/BusPirate-BPIO2-flatbuffer-interface b/scripts/BusPirate-BPIO2-flatbuffer-interface deleted file mode 160000 index 36a5302..0000000 --- a/scripts/BusPirate-BPIO2-flatbuffer-interface +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 36a53023d3119349145d1a2e7ad9041fa6f7c4aa diff --git a/scripts/buspirate_ctrl.py b/scripts/buspirate_ctrl.py deleted file mode 100755 index 4528909..0000000 --- a/scripts/buspirate_ctrl.py +++ /dev/null @@ -1,633 +0,0 @@ -#!/usr/bin/env python3 -"""Bus Pirate 5 control tool using BPIO2 binmode. - -Uses BPIO (CDC 1) for GPIO control and creates a Python PTY bridge so -external tools (uartupdatetool, tio) can talk through BPIO's UART. -No bridge mode, no USB reset, no button press needed. - -The BP5 binmode port (CDC 1) is a single serial device — only one -process can use it at a time. To control GPIO while a PTY bridge is -running, use signals (see below) or combinable flags. - -Wiring: - BP5 IO3 --> EC VCC1_RST (reset, active low) - BP5 IO4 (TX) --> EC CR_SIN1 (UART RX) - BP5 IO5 (RX) <-- EC CR_SOUT1 (UART TX) - BP5 IO7 --[4.7-10K R]--> EC CR_SOUT1/FLPRG1 (flash mode strap) - BP5 GND --- EC GND - -Usage: - ./buspirate_ctrl.py --reset # Toggle EC reset - ./buspirate_ctrl.py --reset-hold # Hold EC in reset - ./buspirate_ctrl.py --log # Print EC UART output (Ctrl+C to stop) - ./buspirate_ctrl.py --log --reset # Reset EC, print boot log - ./buspirate_ctrl.py --pty-bridge # PTY bridge (Ctrl+C to stop) - ./buspirate_ctrl.py --pty-bridge --reset # Bridge, then reset (captures boot log) - ./buspirate_ctrl.py --pty-bridge --enter-flash-mode # Bridge + enter flash mode - ./buspirate_ctrl.py --flash ./result/ # Full flash workflow (build dir) - ./buspirate_ctrl.py --flash ~/Downloads/ec.bin # Flash single ec.bin (monitor from script dir) - ./buspirate_ctrl.py --flash ./result/ --no-reset # Flash without reboot - ./buspirate_ctrl.py --flash ./result/ --log # Flash, reset, print boot log - -Signal control (while --pty-bridge is running): - kill -USR1 # Toggle EC reset - kill -USR2 # Enter EC flash mode -""" - -import argparse -import collections -import errno -import fcntl -import os -import select -import signal -import struct -import subprocess -import sys -import threading -import time -from pathlib import Path - -import serial.tools.list_ports - -# Add upstream pybpio library to path -sys.path.insert(0, str(Path(__file__).parent / "BusPirate-BPIO2-flatbuffer-interface" / "python")) -from pybpio.bpio_client import BPIOClient - - -# --------------------------------------------------------------------------- -# Constants -# --------------------------------------------------------------------------- - -IO_RST = 3 -IO_FLPRG = 7 - -BP5_USB_VID = 0x1209 -BP5_USB_PID = 0x7331 - -PTY_OVERFLOW_MAXLEN = 1024 * 1024 # 1MB max buffered data - - -# --------------------------------------------------------------------------- -# Port detection -# --------------------------------------------------------------------------- - -def find_bp5_binport(): - """Find Bus Pirate 5 binmode (CDC 1) serial port. - - Matches USB VID:PID 1209:7331, then selects the port with - interface string "Bus Pirate BIN". Falls back to sorted port - list index 1 if interface strings are unavailable. - """ - env_port = os.environ.get("BP5_BINPORT") - if env_port: - return env_port - - bp5_ports = [p for p in serial.tools.list_ports.comports() - if p.vid == BP5_USB_VID and p.pid == BP5_USB_PID] - - if not bp5_ports: - return None - - for p in bp5_ports: - iface = (p.interface or "").lower() - if "bin" in iface: - return p.device - - if len(bp5_ports) >= 2: - return sorted(p.device for p in bp5_ports)[1] - - return None - - -# --------------------------------------------------------------------------- -# PTY Bridge -# --------------------------------------------------------------------------- - -TIOCPKT = 0x5420 - - -class PtyBridge: - """Bidirectional bridge between BPIO UART and a PTY. - - All BPIO data is buffered in a Python deque. Nothing is written to - the PTY master until a reader (tio, uartupdatetool) connects. - - TIOCPKT (packet mode) on the master generates status bytes when the - slave's termios changes, which is how we detect a reader connecting. - We delay 200ms after detection so tio's tcflush completes before - we flush, preventing data loss. - """ - - def __init__(self, bp, debug=False): - self.bp = bp - self.debug = debug - self._shutdown = threading.Event() - self._slave_ready = threading.Event() - self._buf = collections.deque(maxlen=PTY_OVERFLOW_MAXLEN) - - # Create PTY pair - self._master_fd, self._slave_fd = os.openpty() - os.set_blocking(self._master_fd, False) - self.pty_path = os.ttyname(self._slave_fd) - - # Enable packet mode — reads from master get a status byte prefix. - # Slave termios changes (tio connecting) produce status events. - # Writes to master are unaffected by TIOCPKT. - fcntl.ioctl(self._master_fd, TIOCPKT, struct.pack('i', 1)) - - # Start worker threads - self._reader_thread = threading.Thread( - target=self._pty_reader_loop, daemon=True, name="pty-reader") - self._async_thread = threading.Thread( - target=self._bpio_async_loop, daemon=True, name="bpio-async") - self._reader_thread.start() - self._async_thread.start() - - def _flush_buf(self): - """Try to flush Python buffer to PTY master.""" - while self._buf: - chunk = self._buf[0] - try: - os.write(self._master_fd, chunk) - self._buf.popleft() - except OSError as e: - if e.errno == errno.EAGAIN: - return # Kernel buffer full, retry later - raise - - def _write_to_master(self, data): - """Buffer data. Only flush to PTY if a reader is connected.""" - if not data: - return - self._buf.append(bytes(data)) - if self._slave_ready.is_set(): - self._flush_buf() - - def _bpio_async_loop(self): - """Poll BPIO for async UART data and buffer/forward to PTY.""" - while not self._shutdown.is_set(): - try: - if self._slave_ready.is_set(): - self._flush_buf() - - pkt = self.bp.check_async_data(timeout=0.05) - if pkt and pkt.get('data_read'): - data = bytes(pkt['data_read']) - if self.debug: - printable = ''.join( - chr(b) if 0x20 <= b < 0x7f else '.' - for b in data) - print(f"[bpio→pty] {len(data)}B: {printable}", - file=sys.stderr) - self._write_to_master(data) - except Exception as e: - if not self._shutdown.is_set(): - print(f"bpio-async error: {e}", file=sys.stderr) - break - - def _pty_reader_loop(self): - """Read from PTY master (TIOCPKT mode) and forward to BPIO.""" - poll = select.poll() - poll.register(self._master_fd, select.POLLIN) - - while not self._shutdown.is_set(): - try: - events = poll.poll(100) # 100ms timeout - if not events: - continue - for fd, event in events: - if event & select.POLLIN: - data = os.read(self._master_fd, 4096) - if not data: - continue - # TIOCPKT: first byte is status, rest is payload - status = data[0] - if status == 0: - # Real data from reader (user typed in tio) - payload = data[1:] - if payload: - if self.debug: - printable = ''.join( - chr(b) if 0x20 <= b < 0x7f else '.' - for b in payload) - print(f"[pty→bpio] {len(payload)}B: " - f"{printable}", file=sys.stderr) - self.bp.data_request( - data_write=payload, bytes_read=0) - else: - # Status change — reader connected (termios set) - if not self._slave_ready.is_set(): - # Wait for tio init (tcflush) to finish - time.sleep(0.2) - self._slave_ready.set() - buflen = sum(len(c) for c in self._buf) - print(f"Reader connected, flushing " - f"{buflen} buffered bytes") - if event & (select.POLLHUP | select.POLLERR): - time.sleep(0.1) - except OSError as e: - if e.errno == errno.EIO: - time.sleep(0.1) - continue - if not self._shutdown.is_set(): - print(f"pty-reader error: {e}", file=sys.stderr) - return - - def stop(self): - """Shut down the bridge.""" - self._shutdown.set() - self._reader_thread.join(timeout=2) - self._async_thread.join(timeout=2) - os.close(self._master_fd) - os.close(self._slave_fd) - - def __enter__(self): - return self - - def __exit__(self, *exc): - self.stop() - - -# --------------------------------------------------------------------------- -# GPIO functions -# --------------------------------------------------------------------------- - -def gpio_reset(bp): - """Assert RST briefly, then release.""" - bp.configuration_request( - io_direction_mask=(1 << IO_RST), - io_direction=(1 << IO_RST), - io_value_mask=(1 << IO_RST), - io_value=0, - ) - time.sleep(0.5) - bp.configuration_request( - io_direction_mask=(1 << IO_RST), - io_direction=0, # input (released) - ) - - -def gpio_reset_hold(bp): - """Assert RST and hold it low.""" - bp.configuration_request( - io_direction_mask=(1 << IO_RST), - io_direction=(1 << IO_RST), - io_value_mask=(1 << IO_RST), - io_value=0, - ) - - -def gpio_enter_flash_mode(bp, debug=False): - """Assert FLPRG1 low, reset EC, wait for strap sampling, drive FLPRG1 high.""" - # Set IO_FLPRG (FLPRG1 strap) as output low - bp.configuration_request( - io_direction_mask=(1 << IO_FLPRG), - io_direction=(1 << IO_FLPRG), - io_value_mask=(1 << IO_FLPRG), - io_value=0, - ) - # Hold EC in reset - bp.configuration_request( - io_direction_mask=(1 << IO_RST), - io_direction=(1 << IO_RST), - io_value_mask=(1 << IO_RST), - io_value=0, - ) - time.sleep(0.5) - # Release RST, keep FLPRG1 low - bp.configuration_request( - io_direction_mask=(1 << IO_RST), - io_direction=0, - ) - time.sleep(1.0) # Wait for EC to sample FLPRG1 strap - # Drive FLPRG1 HIGH (neutralizes the 10K resistor on shared EC TX/FLPRG1 line) - bp.configuration_request( - io_direction_mask=(1 << IO_FLPRG), - io_direction=(1 << IO_FLPRG), - io_value_mask=(1 << IO_FLPRG), - io_value=(1 << IO_FLPRG), - ) - time.sleep(0.1) - if debug: - print("Flash mode entry complete") - - -def gpio_release_all(bp): - """Release all controlled GPIOs to input.""" - bp.configuration_request( - io_direction_mask=(1 << IO_RST) | (1 << IO_FLPRG), - io_direction=0, - ) - - -# --------------------------------------------------------------------------- -# BP5 lifecycle -# --------------------------------------------------------------------------- - -def setup_bp5(port, debug=False): - """Open BPIO client, verify connection, enable PSU and UART.""" - bp = BPIOClient(port, debug=debug) - - # Set write timeout so we don't block forever if BP5 isn't responding - bp.serial_port.write_timeout = 2 - - # Flush any stale data from previous sessions - bp.serial_port.reset_input_buffer() - bp.serial_port.reset_output_buffer() - time.sleep(0.1) - - st = None - for attempt in range(3): - try: - st = bp.status_request() - except serial.SerialTimeoutException: - if debug: - print(f" Status request attempt {attempt+1}/3: write timeout") - if st: - break - time.sleep(0.5) - - if not st: - bp.close() - sys.exit( - "BPIO2 status check failed.\n\n" - "The BP5 default binmode is SUMP, not BPIO2.\n" - "Connect to the BP5 terminal and run:\n" - " binmode -> select 2 (BPIO2 flatbuffer interface) -> save y\n" - "This only needs to be done once.") - - fw_maj = st.get('version_firmware_major', 0) - fw_min = st.get('version_firmware_minor', 0) - print(f"Connected: FW v{fw_maj}.{fw_min}") - - print("Enabling PSU (3.3V for IO buffers)...") - bp.configuration_request(psu_enable=True, psu_set_mv=3300) - time.sleep(0.2) - - print("Configuring UART mode (115200 8N1)...") - bp.configuration_request(mode="UART", mode_configuration={'speed': 115200}) - - return bp - - -def cleanup_bp5(bp): - """Disable PSU, return to HiZ, close.""" - try: - bp.configuration_request(psu_disable=True) - bp.configuration_request(mode="HiZ", mode_configuration={'speed': 0}) - bp.close() - except Exception: - pass - - -# --------------------------------------------------------------------------- -# Command handlers -# --------------------------------------------------------------------------- - -def cmd_reset(bp): - """Toggle reset: low then release.""" - print("Resetting EC...") - gpio_reset(bp) - print("Reset complete.") - - -def cmd_reset_hold(bp): - """Hold EC in reset.""" - print("Holding EC in reset (RST low)...") - gpio_reset_hold(bp) - print("EC held in reset. Run --reset to release.") - - -def cmd_pty_bridge(bp, debug=False, reset_after_start=False): - """Run PTY bridge until Ctrl+C. Supports signal-based control. - - SIGUSR1 → toggle EC reset - SIGUSR2 → enter flash mode - """ - with PtyBridge(bp, debug=debug) as bridge: - pid = os.getpid() - print(f"PTY bridge active: {bridge.pty_path}") - print(f"PID: {pid}") - print("Connect with: tio %s" % bridge.pty_path) - print("Reset EC: kill -USR1 %d" % pid) - print("Flash mode: kill -USR2 %d" % pid) - print("Press Ctrl+C to stop.") - - if reset_after_start: - print("Resetting EC...") - gpio_reset(bp) - print("Reset complete. Boot log is being captured.") - - def on_usr1(signum, frame): - print("\n[SIGUSR1] Resetting EC...") - gpio_reset(bp) - print("[SIGUSR1] Reset complete.") - - def on_usr2(signum, frame): - print("\n[SIGUSR2] Entering flash mode...") - gpio_enter_flash_mode(bp, debug=debug) - print("[SIGUSR2] Flash mode entry complete.") - - signal.signal(signal.SIGUSR1, on_usr1) - signal.signal(signal.SIGUSR2, on_usr2) - - try: - while True: - signal.pause() - except KeyboardInterrupt: - pass - print("\nPTY bridge stopped.") - - -def cmd_log(bp, reset=False, debug=False): - """Print BPIO async UART data to stdout until Ctrl+C. - - If reset=True, starts collection first then resets so no boot - log bytes are dropped. - """ - bp.clear_async_queue() - - if reset: - print("Resetting EC...", file=sys.stderr) - gpio_reset(bp) - print("Reset complete. Logging EC output (Ctrl+C to stop)...", - file=sys.stderr) - else: - print("Logging EC output (Ctrl+C to stop)...", file=sys.stderr) - - try: - while True: - pkt = bp.check_async_data(timeout=0.1) - if pkt and pkt.get('data_read'): - data = bytes(pkt['data_read']) - sys.stdout.buffer.write(data) - sys.stdout.buffer.flush() - except KeyboardInterrupt: - pass - print("\nLog stopped.", file=sys.stderr) - - -def cmd_flash(bp, firmware_path, no_reset=False, log=False, debug=False): - """Full flash workflow: enter flash mode, PTY bridge, uartupdatetool, reset. - - firmware_path may be a build directory (containing ec.bin and - npcx_monitor.bin) or a single ec.bin file, in which case - npcx_monitor.bin is taken from this script's directory. - """ - fw_path = Path(firmware_path).expanduser() - if fw_path.is_dir(): - ec_bin = fw_path / "ec.bin" - monitor_bin = fw_path / "npcx_monitor.bin" - if not ec_bin.exists() or not monitor_bin.exists(): - sys.exit(f"Error: ec.bin and/or npcx_monitor.bin not found in {fw_path}") - else: - ec_bin = fw_path - monitor_bin = Path(__file__).resolve().parent / "npcx_monitor.bin" - if not ec_bin.exists(): - sys.exit(f"Error: {ec_bin} not found") - if not monitor_bin.exists(): - sys.exit(f"Error: npcx_monitor.bin not found in {monitor_bin.parent}") - - print(f"Firmware: {ec_bin}") - - # Enter flash mode - print("Entering EC flash mode...") - gpio_enter_flash_mode(bp, debug=debug) - time.sleep(0.5) - - # Start PTY bridge - with PtyBridge(bp, debug=debug) as bridge: - pty_name = bridge.pty_path - port_arg = pty_name.removeprefix("/dev/") - print(f"PTY bridge: {pty_name}") - - script_dir = os.path.dirname(os.path.abspath(__file__)) - tool = os.path.join(script_dir, "uartupdatetool") - - print("Flashing monitor...") - subprocess.run( - [tool, "--port", port_arg, "--opr", "wr", - "--addr", "0x200c3020", "--file", str(monitor_bin)], - check=True, - ) - - print("Flashing ec.bin...") - subprocess.run( - [tool, "--port", port_arg, "--opr", "wr", "--auto", - "--addr", "0x0000", "--file", str(ec_bin)], - check=True, - ) - - print("Flash complete.") - - if log: - # Start collecting before reset so no boot log is dropped - bp.clear_async_queue() - if not no_reset: - print("Rebooting EC...") - gpio_reset(bp) - print("Logging EC output (Ctrl+C to stop)...", file=sys.stderr) - try: - while True: - pkt = bp.check_async_data(timeout=0.1) - if pkt and pkt.get('data_read'): - data = bytes(pkt['data_read']) - sys.stdout.buffer.write(data) - sys.stdout.buffer.flush() - except KeyboardInterrupt: - pass - print("\nLog stopped.", file=sys.stderr) - else: - if not no_reset: - print("Rebooting EC...") - gpio_reset(bp) - print("Done.") - - -# --------------------------------------------------------------------------- -# Main -# --------------------------------------------------------------------------- - -def main(): - parser = argparse.ArgumentParser( - description="Bus Pirate 5 control tool (BPIO2 binmode)") - - parser.add_argument("--port", default=None, - help="BP5 binmode port (default: auto-detect)") - parser.add_argument("--debug", action="store_true", - help="Enable verbose debug output") - - # Primary action (mutually exclusive) - group = parser.add_mutually_exclusive_group() - group.add_argument("--reset-hold", action="store_true", - help="Hold EC in reset (RST low)") - group.add_argument("--pty-bridge", action="store_true", - help="PTY bridge (blocks until Ctrl+C)") - group.add_argument("--flash", metavar="PATH", - help="Full flash workflow with uartupdatetool. " - "PATH is a build dir with ec.bin + npcx_monitor.bin, " - "or a single ec.bin file (monitor taken from script dir)") - - # Combinable flags - parser.add_argument("--reset", action="store_true", - help="Toggle EC reset (combinable with --pty-bridge, --log)") - parser.add_argument("--log", action="store_true", - help="Print EC UART output to stdout (combinable with --reset, --flash)") - parser.add_argument("--enter-flash-mode", action="store_true", - help="Enter EC flash mode before primary action") - parser.add_argument("--no-reset", action="store_true", - help="Skip reset after --flash") - - args = parser.parse_args() - - if not (args.reset or args.reset_hold or args.pty_bridge or args.flash or args.log): - parser.error("One of --reset, --reset-hold, --pty-bridge, --flash, or --log is required") - - # Find port - binmode_port = args.port or find_bp5_binport() - if not binmode_port: - sys.exit("Error: BP5 binmode port not found. " - "Set BP5_BINPORT or use --port") - - print(f"BP5 binmode: {binmode_port}") - - # Setup - bp = setup_bp5(binmode_port, debug=args.debug) - - # Install signal handler for clean shutdown - original_sigint = signal.getsignal(signal.SIGINT) - - def sigint_handler(signum, frame): - signal.signal(signal.SIGINT, original_sigint) - raise KeyboardInterrupt - - signal.signal(signal.SIGINT, sigint_handler) - - try: - # Optional: enter flash mode before primary action - if args.enter_flash_mode: - print("Entering EC flash mode...") - gpio_enter_flash_mode(bp, debug=args.debug) - - # Primary action - if args.pty_bridge: - cmd_pty_bridge(bp, debug=args.debug, reset_after_start=args.reset) - elif args.reset_hold: - cmd_reset_hold(bp) - elif args.flash: - cmd_flash(bp, args.flash, no_reset=args.no_reset, - log=args.log, debug=args.debug) - elif args.log: - cmd_log(bp, reset=args.reset, debug=args.debug) - elif args.reset: - cmd_reset(bp) - except KeyboardInterrupt: - print("\nInterrupted.") - finally: - gpio_release_all(bp) - cleanup_bp5(bp) - - -if __name__ == "__main__": - main() diff --git a/scripts/flash_adl_ec.sh b/scripts/flash_adl_ec.sh deleted file mode 100755 index 642266a..0000000 --- a/scripts/flash_adl_ec.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -CTRLUART=/dev/ttyACM0 -FLASHUART=/dev/ttyACM2 -if [ $# -eq 0 ]; then - #no argument, try default location - FLASH_SRC=~/ec/build/hx30/ec.bin -else - #allow specifying a file as argument - FLASH_SRC=$1 -fi - -if [ -f "$FLASH_SRC" ]; then - cp $FLASH_SRC ec.bin.tmp -else - echo "No source file to flash was found at $FLASH_SRC" - exit 1 -fi - -#clear any invalid commands from uart buffer -echo -e "\n" > ${CTRLUART} -#put ec into reset -echo -e "\npin 21 0 opendrain\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 -#put teensy into serprog mode -echo -e "\nterm 2 8\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 -#flashrom --programmer ch341a_spi -w ec.bin - -truncate -s 1M ec.bin.tmp -flashrom -p serprog:dev=${FLASHUART}:115200,spispeed=2000000 -w ec.bin.tmp -rm ec.bin.tmp -#disable flashrom -echo -e "\nterm 2 2\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 -#take ec out of reset -echo -e "\npin 21 1\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 - diff --git a/scripts/flash_azalea_ec.sh b/scripts/flash_azalea_ec.sh deleted file mode 100755 index f03646b..0000000 --- a/scripts/flash_azalea_ec.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -DEVICE=${DEVICE:-"/dev/serial/by-id/usb-Framework_CMSIS-"} -CTRLUART=(${DEVICE}*-if00) -FLASHUART=$(basename $(readlink ${DEVICE}*-if02)) - -if [ $# -eq 0 ]; then - #no argument, try default locations - search_paths=("${HOME}/software/ec-lotus/src/platform/ec/build/zephyr/azalea/output"\ - "${HOME}/chromiumos/src/platform/ec/build/zephyr/azalea/output") - - for search in ${search_paths[@]} - do - if [ -d $search ] - then - echo "${search} exists" - FLASH_SRC="${search}/ec.bin" - MONITOR="${search}/npcx_monitor.bin" - fi - done -else - #allow specifying a file as argument - FLASH_SRC="$1/ec.bin" - MONITOR="$1/npcx_monitor.bin" -fi -echo "USING ${FLASH_SRC} to flash EC" - -#clear any invalid commands from uart buffer -echo -e "\n" > ${CTRLUART} -#put ec into reset -echo -e "\npin 21 0 opendrain\n" > ${CTRLUART} -#read INPUT < ${CTRLUART} -sleep 1 - -#enable 10k external pulldown on UART RX wired to pin 20 -echo -e "\npin 4 0 opendrain\n" > ${CTRLUART} -sleep 1 - -# take out of reset - echo -e "\npin 21 1\n" > ${CTRLUART} -sleep 1 -#### DO FLASH -echo "Using NUVOTON Tool ./uartupdatetool" -./uartupdatetool --port ${FLASHUART} --opr wr --addr 0x200c3020 --file ${MONITOR} -./uartupdatetool --port ${FLASHUART} --opr wr --auto --addr 0x0000 --file ${FLASH_SRC} - - -#### TAKE OUT OF RESET - -#put ec into reset -echo -e "\npin 21 0 opendrain\n" > ${CTRLUART} -#read INPUT < ${CTRLUART} -sleep 1 - -#disable 10k external pulldown on UART RX wired to pin 20 -echo -e "\npin 4 1 opendrain\n" > ${CTRLUART} -sleep 1 - - -# take out of reset -echo -e "\npin 21 1\n" > ${CTRLUART} diff --git a/scripts/flash_lotus_ec.sh b/scripts/flash_lotus_ec.sh deleted file mode 100755 index 877e056..0000000 --- a/scripts/flash_lotus_ec.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -CTRLUART=/dev/ttyACM0 -FLASHUART=ttyACM1 - -if [ $# -eq 0 ]; then - #no argument, try default locations - search_paths=("${HOME}/software/ec-lotus/src/platform/ec/build/zephyr/lotus/output"\ - "${HOME}/chromiumos/src/platform/ec/build/zephyr/lotus/output") - - for search in ${search_paths[@]} - do - if [ -d $search ] - then - echo "${search} exists" - FLASH_SRC="${search}/ec.bin" - MONITOR="${search}/npcx_monitor.bin" - fi - done -else - #allow specifying a file as argument - FLASH_SRC="$1/ec.bin" - MONITOR="$1/npcx_monitor.bin" -fi -echo "USING ${FLASH_SRC} to flash EC" - -#clear any invalid commands from uart buffer -echo -e "\n" > ${CTRLUART} -#put ec into reset -echo -e "\npin 21 0 opendrain\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 - -#enable 10k external pulldown on UART RX wired to pin 20 -echo -e "\npin 4 0 opendrain\n" > ${CTRLUART} -sleep 1 - -# take out of reset - echo -e "\npin 21 1\n" > ${CTRLUART} -sleep 1 -#### DO FLASH -echo "Using NUVOTON Tool ${software/ec/build/hx30/util/uartupdatetool}" -~/software/ec/build/hx30/util/uartupdatetool --port ${FLASHUART} --opr wr --addr 0x200c3020 --file ${MONITOR} -~/software/ec/build/hx30/util/uartupdatetool --port ${FLASHUART} --opr wr --auto --addr 0x0000 --file ${FLASH_SRC} - - -#### TAKE OUT OF RESET - -#put ec into reset -echo -e "\npin 21 0 opendrain\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 - -#disable 10k external pulldown on UART RX wired to pin 20 -echo -e "\npin 4 1 opendrain\n" > ${CTRLUART} -sleep 1 - - -# take out of reset -echo -e "\npin 21 1\n" > ${CTRLUART} diff --git a/scripts/flash_manual_ec.sh b/scripts/flash_manual_ec.sh deleted file mode 100755 index 3d39805..0000000 --- a/scripts/flash_manual_ec.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -# Only works on NPCX EC chips -# Every Framework system, except 11-13th Gen Intel -# -# Using bare UART adapter with manual reset/flashmode buttons -# Usage: -# 0. Connect USB-UART adapter to EC UART (TX, RX, GND) -# 1. Hold down flashmode button (4.7−10kΩ, e.g. 5.1k from EC UART TX to GND) -# 2. Press and release EC reset button (RST short to GND) -# 3. Run this script to flash -# ./flash_manual_ec.sh ~/Downloads/sunflower/ -# Where the folder contains ec.bin and npcx_monitor.bin -# If the adapter shows up at a different port, set it in an environment variable: -# env FLASHUART=ttyUSB1 ./flash_manual_ec.sh ~/Downloads/sunflower/ -# 4. Press and release EC reset button to boot EC again -# -# Useful to combine with the gh command -# > gh run download -R FrameworkComputer/ec -D temp -# > ./flash_manual_ec.sh temp/ -# Or with chromium chroot build -# > ./flash_manual_ec.sh ~/chromiumos/src/platform/ec/build/zephyr/marigold/output/ - -FLASHUART=${FLASHUART:-ttyUSB0} - -FLASH_SRC="$1/ec.bin" -MONITOR="$1/npcx_monitor.bin" -echo "USING ${FLASH_SRC} to flash EC" - -#### DO FLASH -echo "Using NUVOTON Tool ./uartupdatetool" -./uartupdatetool --port ${FLASHUART} --opr wr --addr 0x200c3020 --file ${MONITOR} -./uartupdatetool --port ${FLASHUART} --opr wr --auto --addr 0x0000 --file ${FLASH_SRC} diff --git a/scripts/flash_tgl_ec.sh b/scripts/flash_tgl_ec.sh deleted file mode 100755 index fc69730..0000000 --- a/scripts/flash_tgl_ec.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -CTRLUART=/dev/ttyACM0 -FLASHUART=/dev/ttyACM2 -if [ $# -eq 0 ]; then - #no argument, try default location - FLASH_SRC=~/ec/build/hx20/ec.bin -else - #allow specifying a file as argument - FLASH_SRC=$1 -fi - -if [ -f "$FLASH_SRC" ]; then - cp $FLASH_SRC ec.bin.tmp -else - echo "No source file to flash was found at $FLASH_SRC" - exit 1 -fi - -#clear any invalid commands from uart buffer -echo -e "\n" > ${CTRLUART} -#put ec into reset -echo -e "\npin 17 0 opendrain\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 -#put teensy into serprog mode -echo -e "\nterm 2 8\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 -#flashrom --programmer ch341a_spi -w ec.bin - -truncate -s 1M ec.bin.tmp -flashrom --noverify -p serprog:dev=${FLASHUART}:115200 -w ec.bin.tmp -rm ec.bin.tmp -#disable flashrom -echo -e "\nterm 2 2\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 -sleep 1 -#take ec out of reset -echo -e "\npin 17 1\n" > ${CTRLUART} -#read INPUT < /dev/ttyACM0 - diff --git a/scripts/npcx_monitor.bin b/scripts/npcx_monitor.bin deleted file mode 100755 index f3fae2b..0000000 Binary files a/scripts/npcx_monitor.bin and /dev/null differ diff --git a/scripts/shell.nix b/scripts/shell.nix deleted file mode 100644 index f62d60b..0000000 --- a/scripts/shell.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ pkgs ? import {} }: - -(pkgs.buildFHSEnv { - name = "framework-debugger-shell"; - targetPkgs = pkgs: with pkgs; [ - (python3.withPackages (ps: [ ps.pyserial ps.flatbuffers ps.cobs ps.numpy ])) - libftdi1 - libusb1 - ]; - runScript = "bash"; -}).env diff --git a/scripts/uartupdatetool b/scripts/uartupdatetool deleted file mode 100755 index 82aa20c..0000000 Binary files a/scripts/uartupdatetool and /dev/null differ diff --git a/teensy/.vscode/extensions.json b/teensy/.vscode/extensions.json deleted file mode 100644 index 080e70d..0000000 --- a/teensy/.vscode/extensions.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] -} diff --git a/teensy/README.md b/teensy/README.md deleted file mode 100644 index 8e64a66..0000000 --- a/teensy/README.md +++ /dev/null @@ -1,105 +0,0 @@ -# Multi purpose debugger - target controller - -Supports: - -- CMSIS-DAP -- Multiple serial terminals -- GPIO read/write/port register control. - -Right now the backend uses raw hid reports for debug communication, terminal.py will open an interactive terminal to the device. - -### Building - -Pre-requisites: - -- [Install PlatformIO](https://docs.platformio.org/en/latest/core/installation/index.html) - -###### Pre-build - -Build all of the platforms you need. It will fetch source and dependencies but -will fail! After this first attempt at building, the patches listed below need -to be applied. - -```sh -pio run -e teensy41 -pio run -e teensy31 -pio run -e teensy36 -``` - -###### Patching Arduino Source - -Required for all teensy versions. - -```sh -patch -d ~/.platformio/ -p0 < diff/arduino.py.diff -``` - -###### Patching Teensy3 Source - -```sh -patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.c.diff -patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.h.diff -patch -d ~/.platformio/ -p0 < diff/teensy3/usb_inst.cpp.diff -patch -d ~/.platformio/ -p0 < diff/teensy3/yield.cpp.diff -``` - -###### Patching Teensy4 Source - -```sh -patch -d ~/.platformio/ -p0 < diff/arduino.py.diff -patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.c.diff -patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.h.diff -patch -d ~/.platformio/ -p0 < diff/teensy4/usb_inst.cpp.diff -patch -d ~/.platformio/ -p0 < diff/teensy4/yield.cpp.diff -``` - -###### Build again - -Now all the builds should succeed. - -```sh -pio run -e teensy41 -pio run -e teensy31 -pio run -e teensy36 -``` - -### Flashing to Teensy - -Flash to whatever teensy hardware you have attached. - -```sh -pio run -e teensy41 --target upload -pio run -e teensy31 --target upload -pio run -e teensy36 --target upload -``` - -### EC Serial - -```sh -# For example with tio -tio /dev/serial/by-id/usb-Framework_CMSIS-DAP_13993040-if04 - -# Or picocom/minicom/screen -picocom /dev/ttyACM2 -b 115200 -``` - -### Flashing EC firmware - -Run the script for your target platform - -```sh -./scripts/flash_tgl_ec.sh -./scripts/flash_adl_ec.sh -``` - -### Teensy Control Serial - -Only for advanced usage, you can probably ignore this. - -```sh -# For example with tio -tio /dev/serial/by-id/usb-Framework_CMSIS-DAP_13993040-if00 - -# Or picocom/minicom/screen -picocom /dev/ttyACM0 -b 115200 -``` diff --git a/teensy/diff/arduino.py.diff b/teensy/diff/arduino.py.diff deleted file mode 100644 index 0e1367a..0000000 --- a/teensy/diff/arduino.py.diff +++ /dev/null @@ -1,10 +0,0 @@ ---- platforms/teensy/builder/frameworks/arduino.py 2023-12-11 17:06:57.115267304 +0800 -+++ platforms/teensy/builder/frameworks/arduino.py 2023-12-11 17:07:13.059123524 +0800 -@@ -41,6 +41,7 @@ - "USB_SERIAL", - "USB_DUAL_SERIAL", - "USB_TRIPLE_SERIAL", -+ "USB_RAWHID_TRIPLESERIAL", - "USB_KEYBOARDONLY", - "USB_TOUCHSCREEN", - "USB_HID_TOUCHSCREEN", diff --git a/teensy/diff/teensy3/usb_desc.c.diff b/teensy/diff/teensy3/usb_desc.c.diff deleted file mode 100644 index 6717a61..0000000 --- a/teensy/diff/teensy3/usb_desc.c.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy3/usb_desc.c 2023-12-11 17:01:29.574251846 +0800 -+++ packages/framework-arduinoteensy/cores/teensy3/usb_desc.c 2023-12-11 17:01:36.194190540 +0800 -@@ -1133,7 +1133,7 @@ - 0x03, // bInterfaceClass (0x03 = HID) - 0x00, // bInterfaceSubClass - 0x00, // bInterfaceProtocol -- 0, // iInterface -+ 2, // iInterface <-------------------Change this from 0 to 2! - // HID interface descriptor, HID 1.11 spec, section 6.2.1 - 9, // bLength - 0x21, // bDescriptorType diff --git a/teensy/diff/teensy3/usb_desc.h.diff b/teensy/diff/teensy3/usb_desc.h.diff deleted file mode 100644 index a0e782e..0000000 --- a/teensy/diff/teensy3/usb_desc.h.diff +++ /dev/null @@ -1,82 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy3/usb_desc.h 2023-12-11 17:01:49.298069192 +0800 -+++ packages/framework-arduinoteensy/cores/teensy3/usb_desc.h 2023-12-11 17:17:28.601424569 +0800 -@@ -116,7 +116,7 @@ - */ - - --#if defined(USB_SERIAL) -+#if defined(USB_SERIAL) && FALSE - #define VENDOR_ID 0x16C0 - #define PRODUCT_ID 0x0483 - #define DEVICE_CLASS 2 // 2 = Communication Class -@@ -986,6 +986,70 @@ - #define ENDPOINT13_CONFIG (ENDPOINT_RECEIVE_ISOCHRONOUS|ENDPOINT_TRANSMIT_ISOCHRONOUS) - #define ENDPOINT14_CONFIG ENDPOINT_TRANSMIT_ISOCHRONOUS - #define ENDPOINT15_CONFIG ENDPOINT_TRANSMIT_ONLY -+#elif defined(USB_RAWHID_TRIPLESERIAL) -+ #define VENDOR_ID 0x16C0 -+ #define PRODUCT_ID 0x048C -+ #define RAWHID_USAGE_PAGE 0xFFAB // recommended: 0xFF00 to 0xFFFF -+ #define RAWHID_USAGE 0x0200 // recommended: 0x0100 to 0xFFFF -+ #define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'} -+ #define MANUFACTURER_NAME_LEN 11 -+ #define PRODUCT_NAME {'C','M','S','I','S','-','D','A','P'} -+ #define PRODUCT_NAME_LEN 9 -+ #define EP0_SIZE 64 -+ #define NUM_ENDPOINTS 12 -+ #define NUM_USB_BUFFERS 32 -+ #define NUM_INTERFACE 7 -+ -+ #define CDC_IAD_DESCRIPTOR 1 // Serial -+ #define CDC_STATUS_INTERFACE 0 -+ #define CDC_DATA_INTERFACE 1 -+ #define CDC_ACM_ENDPOINT 2 -+ #define CDC_RX_ENDPOINT 3 -+ #define CDC_TX_ENDPOINT 4 -+ #define CDC_ACM_SIZE 16 -+ #define CDC_RX_SIZE 64 -+ #define CDC_TX_SIZE 64 -+ -+ #define CDC2_STATUS_INTERFACE 2 // SerialUSB1 -+ #define CDC2_DATA_INTERFACE 3 -+ #define CDC2_ACM_ENDPOINT 5 -+ #define CDC2_RX_ENDPOINT 6 -+ #define CDC2_TX_ENDPOINT 7 -+ #define CDC2_ACM_SIZE 16 -+ #define CDC2_RX_SIZE 64 -+ #define CDC2_TX_SIZE 64 -+ -+ #define CDC3_STATUS_INTERFACE 4 // SerialUSB2 -+ #define CDC3_DATA_INTERFACE 5 -+ #define CDC3_ACM_ENDPOINT 8 -+ #define CDC3_RX_ENDPOINT 9 -+ #define CDC3_TX_ENDPOINT 10 -+ #define CDC3_ACM_SIZE 16 -+ #define CDC3_RX_SIZE 64 -+ #define CDC3_TX_SIZE 64 -+ -+ #define RAWHID_INTERFACE 6 // RawHID -+ #define RAWHID_TX_ENDPOINT 11 -+ #define RAWHID_TX_SIZE 64 -+ #define RAWHID_TX_INTERVAL 1 -+ #define RAWHID_RX_ENDPOINT 12 -+ #define RAWHID_RX_SIZE 64 -+ #define RAWHID_RX_INTERVAL 1 -+ -+ #define ENDPOINT2_CONFIG ENDPOINT_TRANSMIT_ONLY -+ #define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_ONLY -+ #define ENDPOINT4_CONFIG ENDPOINT_TRANSMIT_ONLY -+ -+ #define ENDPOINT5_CONFIG ENDPOINT_TRANSMIT_ONLY -+ #define ENDPOINT6_CONFIG ENDPOINT_RECEIVE_ONLY -+ #define ENDPOINT7_CONFIG ENDPOINT_TRANSMIT_ONLY -+ -+ #define ENDPOINT8_CONFIG ENDPOINT_TRANSMIT_ONLY -+ #define ENDPOINT9_CONFIG ENDPOINT_RECEIVE_ONLY -+ #define ENDPOINT10_CONFIG ENDPOINT_TRANSMIT_ONLY -+ -+ #define ENDPOINT11_CONFIG ENDPOINT_TRANSMIT_ONLY -+ #define ENDPOINT12_CONFIG ENDPOINT_RECEIVE_ONLY - - #endif - diff --git a/teensy/diff/teensy3/usb_inst.cpp.diff b/teensy/diff/teensy3/usb_inst.cpp.diff deleted file mode 100644 index 74907a0..0000000 --- a/teensy/diff/teensy3/usb_inst.cpp.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy3/usb_inst.cpp 2023-12-11 17:03:27.049163985 +0800 -+++ packages/framework-arduinoteensy/cores/teensy3/usb_inst.cpp 2023-12-11 17:03:45.544995028 +0800 -@@ -88,7 +88,7 @@ - #else // F_CPU < 20 MHz - - #if defined(USB_SERIAL) || defined(USB_DUAL_SERIAL) || \ -- defined(USB_TRIPLE_SERIAL) || defined(USB_SERIAL_HID) -+ defined(USB_TRIPLE_SERIAL) || defined(USB_SERIAL_HID) || defined(USB_RAWHID_TRIPLESERIAL) - usb_serial_class Serial; - #elif (USB_DISABLED) - usb_serial_class Serial; diff --git a/teensy/diff/teensy3/yield.cpp.diff b/teensy/diff/teensy3/yield.cpp.diff deleted file mode 100644 index 2846523..0000000 --- a/teensy/diff/teensy3/yield.cpp.diff +++ /dev/null @@ -1,27 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy3/yield.cpp 2023-12-11 17:02:27.733713268 +0800 -+++ packages/framework-arduinoteensy/cores/teensy3/yield.cpp 2023-12-11 17:02:58.697426531 +0800 -@@ -31,7 +31,7 @@ - #include - #include "EventResponder.h" - --#ifdef USB_TRIPLE_SERIAL -+#if defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL) - uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1 | YIELD_CHECK_USB_SERIALUSB2; // default to check USB. - extern const uint8_t _serialEventUSB2_default; - extern const uint8_t _serialEventUSB1_default; -@@ -62,13 +62,13 @@ - } - // Current workaround until integrate with EventResponder. - --#if defined(USB_DUAL_SERIAL) || defined(USB_TRIPLE_SERIAL) -+#if defined(USB_DUAL_SERIAL) || defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL) - if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB1) { - if (SerialUSB1.available()) serialEventUSB1(); - if (_serialEventUSB1_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB1; - } - #endif --#ifdef USB_TRIPLE_SERIAL -+#if defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL) - if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB2) { - if (SerialUSB2.available()) serialEventUSB2(); - if (_serialEventUSB2_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB2; diff --git a/teensy/diff/teensy4/usb_desc.c.diff b/teensy/diff/teensy4/usb_desc.c.diff deleted file mode 100644 index eb5ad91..0000000 --- a/teensy/diff/teensy4/usb_desc.c.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy4/usb_desc.c 2023-12-11 17:38:41.575512487 +0800 -+++ packages/framework-arduinoteensy/cores/teensy4/usb_desc.c 2023-12-11 17:39:15.207185545 +0800 -@@ -1207,7 +1207,7 @@ - 0x03, // bInterfaceClass (0x03 = HID) - 0x00, // bInterfaceSubClass - 0x00, // bInterfaceProtocol -- 0, // iInterface -+ 2, // iInterface <-------------------Change this from 0 to 2! - // HID interface descriptor, HID 1.11 spec, section 6.2.1 - 9, // bLength - 0x21, // bDescriptorType diff --git a/teensy/diff/teensy4/usb_desc.h.diff b/teensy/diff/teensy4/usb_desc.h.diff deleted file mode 100644 index 559fc3d..0000000 --- a/teensy/diff/teensy4/usb_desc.h.diff +++ /dev/null @@ -1,75 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy4/usb_desc.h 2023-12-11 17:38:41.575512487 +0800 -+++ packages/framework-arduinoteensy/cores/teensy4/usb_desc.h 2023-12-11 17:51:01.544054165 +0800 -@@ -111,7 +111,8 @@ - */ - - --#if defined(USB_SERIAL) -+#if defined(USB_SERIAL) && FALSE -+OMG!!! - #define VENDOR_ID 0x16C0 - #define PRODUCT_ID 0x0483 - #define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'} -@@ -949,6 +950,62 @@ - #define ENDPOINT14_CONFIG ENDPOINT_TRANSMIT_ISOCHRONOUS - #define ENDPOINT15_CONFIG ENDPOINT_TRANSMIT_ONLY - -+#elif defined(USB_RAWHID_TRIPLESERIAL) -+ #define VENDOR_ID 0x16C0 -+ #define PRODUCT_ID 0x048C -+ #define RAWHID_USAGE_PAGE 0xFFAB // recommended: 0xFF00 to 0xFFFF -+ #define RAWHID_USAGE 0x0200 // recommended: 0x0100 to 0xFFFF -+ #define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'} -+ #define MANUFACTURER_NAME_LEN 11 -+ #define PRODUCT_NAME {'T','r','i','p','l','e',' ','S','e','r','i','a','l'} -+ #define PRODUCT_NAME_LEN 13 -+ #define EP0_SIZE 64 -+ #define NUM_ENDPOINTS 9 -+ #define NUM_INTERFACE 7 -+ -+ #define CDC_IAD_DESCRIPTOR 1 // Serial -+ #define CDC_STATUS_INTERFACE 0 -+ #define CDC_DATA_INTERFACE 1 -+ #define CDC_ACM_ENDPOINT 2 -+ #define CDC_RX_ENDPOINT 3 -+ #define CDC_TX_ENDPOINT 3 -+ #define CDC_ACM_SIZE 16 -+ #define CDC_RX_SIZE_480 512 -+ #define CDC_TX_SIZE_480 512 -+ #define CDC_RX_SIZE_12 64 -+ #define CDC_TX_SIZE_12 64 -+ #define SEREMU_TX_SIZE 64 -+ -+ #define CDC2_STATUS_INTERFACE 2 // SerialUSB1 -+ #define CDC2_DATA_INTERFACE 3 -+ #define CDC2_ACM_ENDPOINT 4 -+ #define CDC2_RX_ENDPOINT 5 -+ #define CDC2_TX_ENDPOINT 5 -+ -+ #define CDC3_STATUS_INTERFACE 4 // SerialUSB2 -+ #define CDC3_DATA_INTERFACE 5 -+ #define CDC3_ACM_ENDPOINT 6 -+ #define CDC3_RX_ENDPOINT 7 -+ #define CDC3_TX_ENDPOINT 7 -+ -+ #define RAWHID_INTERFACE 6 // RawHID -+ #define RAWHID_TX_ENDPOINT 8 -+ #define RAWHID_TX_SIZE 64 -+ #define RAWHID_TX_INTERVAL 1 // TODO: is this ok for 480 Mbit speed -+ #define RAWHID_RX_ENDPOINT 9 -+ #define RAWHID_RX_SIZE 64 -+ #define RAWHID_RX_INTERVAL 1 // TODO: is this ok for 480 Mbit speed -+ -+ #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT -+ #define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK -+ #define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT -+ #define ENDPOINT5_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK -+ #define ENDPOINT6_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT -+ #define ENDPOINT7_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK -+/* for raw hid */ -+ #define ENDPOINT8_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT -+ #define ENDPOINT9_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_UNUSED -+ - #endif - - #ifdef USB_DESC_LIST_DEFINE diff --git a/teensy/diff/teensy4/usb_inst.cpp.diff b/teensy/diff/teensy4/usb_inst.cpp.diff deleted file mode 100644 index 34d608a..0000000 --- a/teensy/diff/teensy4/usb_inst.cpp.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy4/usb_inst.cpp 2023-12-11 17:38:46.011469367 +0800 -+++ packages/framework-arduinoteensy/cores/teensy4/usb_inst.cpp 2023-12-11 17:40:34.002419647 +0800 -@@ -87,7 +87,7 @@ - - #else // F_CPU < 20 MHz - --#if defined(USB_SERIAL) || defined(USB_SERIAL_HID) -+#if defined(USB_SERIAL) || defined(USB_SERIAL_HID) || defined(USB_RAWHID_TRIPLESERIAL) - usb_serial_class Serial; - #elif (USB_DISABLED) - usb_serial_class Serial; diff --git a/teensy/diff/teensy4/yield.cpp.diff b/teensy/diff/teensy4/yield.cpp.diff deleted file mode 100644 index 869b7ca..0000000 --- a/teensy/diff/teensy4/yield.cpp.diff +++ /dev/null @@ -1,27 +0,0 @@ ---- packages/framework-arduinoteensy/cores/teensy4/yield.cpp 2023-12-11 17:38:48.495445219 +0800 -+++ packages/framework-arduinoteensy/cores/teensy4/yield.cpp 2023-12-11 17:41:10.658063282 +0800 -@@ -31,7 +31,7 @@ - #include - #include "EventResponder.h" - --#ifdef USB_TRIPLE_SERIAL -+#if defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL) - uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1 | YIELD_CHECK_USB_SERIALUSB2; // default to check USB. - extern const uint8_t _serialEventUSB2_default; - extern const uint8_t _serialEventUSB1_default; -@@ -61,13 +61,13 @@ - if (_serialEvent_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIAL; - } - --#if defined(USB_DUAL_SERIAL) || defined(USB_TRIPLE_SERIAL) -+#if defined(USB_DUAL_SERIAL) || defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL) - if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB1) { - if (SerialUSB1.available()) serialEventUSB1(); - if (_serialEventUSB1_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB1; - } - #endif --#ifdef USB_TRIPLE_SERIAL -+#if defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL) - if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB2) { - if (SerialUSB2.available()) serialEventUSB2(); - if (_serialEventUSB2_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB2; diff --git a/teensy/include/README b/teensy/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/teensy/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/teensy/lib/README b/teensy/lib/README deleted file mode 100644 index 6debab1..0000000 --- a/teensy/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/teensy/lib/libfrser/src/COPYING b/teensy/lib/libfrser/src/COPYING deleted file mode 100644 index d511905..0000000 --- a/teensy/lib/libfrser/src/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 of the License, 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; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/teensy/lib/libfrser/src/COPYING.GPLv3 b/teensy/lib/libfrser/src/COPYING.GPLv3 deleted file mode 100644 index 94a9ed0..0000000 --- a/teensy/lib/libfrser/src/COPYING.GPLv3 +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 3 of the License, 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. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/teensy/lib/libfrser/src/Makefile.frser b/teensy/lib/libfrser/src/Makefile.frser deleted file mode 100644 index 47443a3..0000000 --- a/teensy/lib/libfrser/src/Makefile.frser +++ /dev/null @@ -1,7 +0,0 @@ -#This is a fragment that you can include from the "hosting" makefile -#to include the right things... - -FRP := libfrser -CFLAGS += -I$(FRP) -std=gnu99 -DEPS += $(FRP)/frser.h $(FRP)/frser-int.h $(FRP)/frser-flashapi.h $(FRP)/typeu.h $(FRP)/udelay.h frser-cfg.h $(FRP)/Makefile.frser -SOURCES += $(FRP)/frser.c $(FRP)/udelay.c diff --git a/teensy/lib/libfrser/src/Makefile.lpcfwh b/teensy/lib/libfrser/src/Makefile.lpcfwh deleted file mode 100644 index 5f528a7..0000000 --- a/teensy/lib/libfrser/src/Makefile.lpcfwh +++ /dev/null @@ -1,6 +0,0 @@ -#This is a fragment that you can include from the "hosting" makefile -#to include the LPC and FWH device-independent codes from the library -#and your device-dependent nibble.c&h - -DEPS += $(FRP)/lpcfwh.h nibble.h -SOURCES += $(FRP)/lpcfwh.c nibble.c diff --git a/teensy/lib/libfrser/src/Makefile.spihw_avrspi b/teensy/lib/libfrser/src/Makefile.spihw_avrspi deleted file mode 100644 index a2d0447..0000000 --- a/teensy/lib/libfrser/src/Makefile.spihw_avrspi +++ /dev/null @@ -1,5 +0,0 @@ -#This is a fragment that you can include from the "hosting" makefile -#to include the AVR SPI code. - -DEPS += $(FRP)/spihw_avrspi.h -SOURCES += $(FRP)/spihw_avrspi.c diff --git a/teensy/lib/libfrser/src/Makefile.spilib b/teensy/lib/libfrser/src/Makefile.spilib deleted file mode 100644 index b37849f..0000000 --- a/teensy/lib/libfrser/src/Makefile.spilib +++ /dev/null @@ -1,5 +0,0 @@ -#This is a fragment that you can include from the "hosting" makefile -#to include the SPI library. - -DEPS += $(FRP)/spilib.h spihw.h -SOURCES += $(FRP)/spilib.c diff --git a/teensy/lib/libfrser/src/README b/teensy/lib/libfrser/src/README deleted file mode 100644 index b5ee75e..0000000 --- a/teensy/lib/libfrser/src/README +++ /dev/null @@ -1,23 +0,0 @@ -This is the hardware-independent parts of frser pulled out -so one can easily use them in different flashers. -Also included some hardware-specific bits (SPI) that can -be used by multiple flashers. - -The point is to include this stuff as a subfolder (eg. git submodule) -in your project and point your Makefile to the .c -files when you're compiling your project and -I the folder. ---- -Or alternatively, in your makefile: -include libfrser/Makefile.frser - -Also maybe other makefile fragments that are provided. - -Your project should contain real versions of the headers -named *.example and implement the stuff - also the stuff -in frser-flashapi.h. - -License -------- -the nibble and lpcfwh.c code are GPLv3+, -everything else is GPLv2+ - diff --git a/teensy/lib/libfrser/src/frser-cfg.h b/teensy/lib/libfrser/src/frser-cfg.h deleted file mode 100644 index 8d03181..0000000 --- a/teensy/lib/libfrser/src/frser-cfg.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _FRSER_CFG_H_ -#define _FRSER_CFG_H_ - -/* What kind of buses your flasher supports. I assume if it can LPC it can FWH too. */ -/* You can override that with FORCE_BUSTYPE if you cant (weirdo hardware duuude :P) */ -//#define FRSER_FEAT_PARALLEL -//#define FRSER_FEAT_LPCFWH -#define FRSER_FEAT_SPI - -/* Debug feature, if you want to use get_last_op to know the last frser operation. */ -#define FRSER_FEAT_LAST_OP -/* Safety feature, calls set_uart_timeout with a jmp_buf to longjmp to in case of timeout. */ -//#define FRSER_FEAT_UART_TIMEOUT -/* If your system is capable of autodetecting the actual attached chip bustype. */ -//#define FRSER_FEAT_DYNPROTO -/* If your system is capable of turning on/off chip drivers. */ -#define FRSER_FEAT_PIN_STATE -/* If you have a debug console you'd want frser to call upon space bar. */ -//#define FRSER_FEAT_DBG_CONSOLE - -/* Name provided to flashrom to identify what the thing is. Max 16 bytes */ -#define FRSER_NAME "Teensy Flasher" - -/* Attached address lines, only if FRSER_FEAT_PARALLEL */ -//#define FRSER_PARALLEL_BITS 19 - -/* Ability to set SPI frequency (only if SPI). */ -#define FRSER_FEAT_SPISPEED - -/* Optionally, if you want to make the auto-OPBUF-sizing code leave more/less RAM space for - * rest of the system, define this. Default is below. Not needed for SPI-only flashers. */ -//#define FRSER_SYS_BYTES 320 - -/* If you want to override the opbuf size completely, define this: */ -//#define FRSER_OPBUF_LEN 1024 - -/* If you want to override the read-n max len (default based on BAUD or 64k), define this: */ -//#define FRSER_READ_N_MAX (64*1024) - -/* Hooks that are run (and only run) before and after the RECEIVE() for the operation. * - * Do not access any local variables in the frser_main function. - * I'd say that if you need to access eg. op you could save it in RECEIVE() and access - * that (your private copy) from the hook. */ -/* These are only supported if you're using frser_main (or implement them in your own main()). */ -//#define FRSER_FEAT_PRE_OPRX_HOOK() do { stuff(); other_stuff(); } while(0) -//#define FRSER_FEAT_POST_OPRX_HOOK() do { stuff(); other_stuff(); } while(0) - -#endif diff --git a/teensy/lib/libfrser/src/frser-cfg.h.example b/teensy/lib/libfrser/src/frser-cfg.h.example deleted file mode 100644 index 1c5afc9..0000000 --- a/teensy/lib/libfrser/src/frser-cfg.h.example +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _FRSER_CFG_H_ -#define _FRSER_CFG_H_ - -/* What kind of buses your flasher supports. I assume if it can LPC it can FWH too. */ -/* You can override that with FORCE_BUSTYPE if you cant (weirdo hardware duuude :P) */ -#define FRSER_FEAT_PARALLEL -#define FRSER_FEAT_LPCFWH -#define FRSER_FEAT_SPI - -/* Debug feature, if you want to use get_last_op to know the last frser operation. */ -#define FRSER_FEAT_LAST_OP -/* Safety feature, calls set_uart_timeout with a jmp_buf to longjmp to in case of timeout. */ -#define FRSER_FEAT_UART_TIMEOUT -/* If your system is capable of autodetecting the actual attached chip bustype. */ -#define FRSER_FEAT_DYNPROTO -/* If your system is capable of turning on/off chip drivers. */ -#define FRSER_FEAT_PIN_STATE -/* If you have a debug console you'd want frser to call upon space bar. */ -#define FRSER_FEAT_DBG_CONSOLE - -/* Name provided to flashrom to identify what the thing is. Max 16 bytes */ -#define FRSER_NAME "Example flasher" - -/* Attached address lines, only if FRSER_FEAT_PARALLEL */ -#define FRSER_PARALLEL_BITS 19 - -/* Ability to set SPI frequency (only if SPI). */ -#define FRSER_FEAT_SPISPEED - -/* Optionally, if you want to make the auto-OPBUF-sizing code leave more/less RAM space for - * rest of the system, define this. Default is below. Not needed for SPI-only flashers. */ -//#define FRSER_SYS_BYTES 320 - -/* If you want to override the opbuf size completely, define this: */ -//#define FRSER_OPBUF_LEN 1024 - -/* If you want to override the read-n max len (default based on BAUD or 64k), define this: */ -//#define FRSER_READ_N_MAX (64*1024) - -/* Hooks that are run (and only run) before and after the RECEIVE() for the operation. * - * Do not access any local variables in the frser_main function. - * I'd say that if you need to access eg. op you could save it in RECEIVE() and access - * that (your private copy) from the hook. */ -/* These are only supported if you're using frser_main (or implement them in your own main()). */ -//#define FRSER_FEAT_PRE_OPRX_HOOK() do { stuff(); other_stuff(); } while(0) -//#define FRSER_FEAT_POST_OPRX_HOOK() do { stuff(); other_stuff(); } while(0) - - - -#endif diff --git a/teensy/lib/libfrser/src/frser-flashapi.h b/teensy/lib/libfrser/src/frser-flashapi.h deleted file mode 100644 index 375af26..0000000 --- a/teensy/lib/libfrser/src/frser-flashapi.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2009,2015 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* These are the functions (mostly flashing related) that frser will call. */ -/* Some of of them must be able to execute a part of the frser - operation over UART (flash_readn and flash_spiop). */ -/* flash_readn: send len bytes over uart. */ -/* flash_spiop: receive sbytes, send S_ACK, send rbytes */ - -#ifndef _FRSER_FLASHAPI_H_ -#define _FRSER_FLASHAPI_H_ - -/* The flashapi functions need to know S_ACK and the defines here come from there, - thus give frser-int.h */ -#include "frser-int.h" - -#ifdef FRSER_FEAT_PIN_STATE -/* This will be used to disable pin drivers. */ -void flash_set_safe(void); -#endif - -/* This can be always called to re-init the interface, or to enable pin drivers. */ -void flash_select_protocol(uint8_t allowed_protocols); - -#ifdef FRSER_FEAT_NONSPI -uint8_t flash_read(uint32_t addr); -void flash_readn(uint32_t addr, uint32_t len); -void flash_write(uint32_t addr, uint8_t data); -#endif - -#ifdef FRSER_FEAT_SPI -void flash_spiop(uint32_t sbytes, uint32_t rbytes); -#ifdef FRSER_FEAT_SPISPEED -uint32_t spi_set_speed(uint32_t hz); -#endif -#endif - -#ifdef FRSER_FEAT_DYNPROTO -uint8_t flash_plausible_protocols(void); -#endif - -#ifdef FRSER_FEAT_DBG_CONSOLE -/* The console must exit if it sees a S_CMD_NOP (0) */ -void ciface_main(void); -#endif - -#endif diff --git a/teensy/lib/libfrser/src/frser-int.h b/teensy/lib/libfrser/src/frser-int.h deleted file mode 100644 index 6cffe2e..0000000 --- a/teensy/lib/libfrser/src/frser-int.h +++ /dev/null @@ -1,115 +0,0 @@ -/* Flashrom serial interface AVR implementation */ -#ifndef _FRSER_INT_H_ -#define _FRSER_INT_H_ - -#define S_ACK 0x06 -#define S_NAK 0x15 - -#define S_CMD_NOP 0x00 /* No operation */ -#define S_CMD_Q_IFACE 0x01 /* Query interface version */ -#define S_CMD_Q_CMDMAP 0x02 /* Query supported commands bitmap */ -#define S_CMD_Q_PGMNAME 0x03 /* Query programmer name */ -#define S_CMD_Q_SERBUF 0x04 /* Query Serial Buffer Size */ -#define S_CMD_Q_BUSTYPE 0x05 /* Query supported bustypes */ -#define S_CMD_Q_CHIPSIZE 0x06 /* Query supported chipsize (2^n format) */ -#define S_CMD_Q_OPBUF 0x07 /* Query operation buffer size */ - -#define S_CMD_Q_WRNMAXLEN 0x08 /* Query Write to opbuf: Write-N maximum length */ -#define S_CMD_R_BYTE 0x09 /* Read a single byte */ -#define S_CMD_R_NBYTES 0x0A /* Read n bytes */ -#define S_CMD_O_INIT 0x0B /* Initialize operation buffer */ -#define S_CMD_O_WRITEB 0x0C /* Write opbuf: Write byte with address */ -#define S_CMD_O_WRITEN 0x0D /* Write to opbuf: Write-N */ -#define S_CMD_O_DELAY 0x0E /* Write opbuf: udelay */ -#define S_CMD_O_EXEC 0x0F /* Execute operation buffer */ - -#define S_CMD_SYNCNOP 0x10 /* Special no-operation that returns NAK+ACK */ -#define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */ -#define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s). */ -#define S_CMD_O_SPIOP 0x13 /* Perform SPI operation. */ -#define S_CMD_S_SPI_FREQ 0x14 /* Set SPI clock frequency */ -#define S_CMD_S_PIN_STATE 0x15 /* Enable/disable output drivers */ -// #define S_CMD_O_TOGGLERDY 0x16 /* Write to opbuf: wait JEDEC toggle ready */ -#define S_CMD_O_POLL 0x17 /* Write to opbuf: poll (details in code/soon doc) */ - -#define S_CMD_O_POLL_DLY 0x18 /* Write to opbuf: poll (details in code/soon doc) */ - -/* The biggest valid command value */ -#define S_MAXCMD 0x18 -/* The maximum static length of parameters (poll_dly)) */ -#define S_MAXLEN 0x08 - -/* "Library" Configuration Decisions - useful to have the command list above for reference with these */ -#include "frser-cfg.h" - -/* These are the commands that are always implemented */ -#define _FR_BM_B0_BASE 0xBF -#define _FR_BM_B1_BASE 0xC9 -#define _FR_BM_B2_BASE 0x03 - -#if (defined FRSER_FEAT_PARALLEL) || (defined FRSER_FEAT_LPCFWH) -#define FRSER_FEAT_NONSPI -#endif - -#ifdef FRSER_FEAT_PARALLEL -#define _FR_BM_B0_ADD0 0x40 -#else -#define _FR_BM_B0_ADD0 0 -#endif - -#ifdef FRSER_FEAT_NONSPI -#define _FR_BM_B1_ADD0 0x36 -#define _FR_BM_B2_ADD0 0x80 -#define _FR_BM_B3_BASE 0x01 -#else -#define _FR_BM_B1_ADD0 0 -#define _FR_BM_B2_ADD0 0 -#define _FR_BM_B3_BASE 0 -#endif - -#if (defined FRSER_FEAT_SPI) || (defined FRSER_FEAT_LPCFWH) -#define FRSER_FEAT_S_BUSTYPE -#endif - -#ifdef FRSER_FEAT_S_BUSTYPE -#define _FR_BM_B2_ADD1 0x04 -#else -#define _FR_BM_B2_ADD1 0 -#endif - - -#ifdef FRSER_FEAT_PIN_STATE -#define _FR_BM_B2_ADD2 0x20 -#else -#define _FR_BM_B2_ADD2 0 -#endif - -#ifdef FRSER_FEAT_SPI -#ifdef FRSER_FEAT_SPISPEED -#define _FR_BM_B2_ADD3 0x18 -#else -#define _FR_BM_B2_ADD3 0x08 -#endif -#else -#define _FR_BM_B2_ADD3 0 -#endif - -#define FRSER_BM_B0 (_FR_BM_B0_BASE | _FR_BM_B0_ADD0) -#define FRSER_BM_B1 (_FR_BM_B1_BASE | _FR_BM_B1_ADD0) -#define FRSER_BM_B2 (_FR_BM_B2_BASE | _FR_BM_B2_ADD0 | _FR_BM_B2_ADD1 | _FR_BM_B2_ADD2 | _FR_BM_B2_ADD3) -#define FRSER_BM_B3 (_FR_BM_B3_BASE) - -#include - -/* Teensy vs AVR compat. */ -#ifndef pgm_read_ptr - -#if INTPTR_MAX > 0x7FFFUL -#define pgm_read_ptr pgm_read_dword -#else -#define pgm_read_ptr pgm_read_word -#endif - -#endif - -#endif /* _FRSER_INT_H_ */ diff --git a/teensy/lib/libfrser/src/frser.cpp b/teensy/lib/libfrser/src/frser.cpp deleted file mode 100644 index b03bcbd..0000000 --- a/teensy/lib/libfrser/src/frser.cpp +++ /dev/null @@ -1,645 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2010,2011,2013,2015 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "main.h" -#include "uart.h" -#include "frser-cfg.h" -#include "frser-int.h" -#include "frser-flashapi.h" -#include "udelay.h" -#include "frser.h" -#include "typeu.h" - -/* Report -4 for safety (atleast -1 because our buffer cant be filled 100%) */ -#define UART_RBUFLEN (UART_BUFLEN-4) - -/* Maximum Write-N length..*/ -/* The 7 in SPI means cmd(1) + txamt(3) + rxamt(3) => 7 */ -#define WRNMAX_SPI (UART_RBUFLEN-7) -/* Here the 7 is the nominal opbuf usage of write-n. */ -#define WRNMAX_NONSPI (S_OPBUFLEN-7) - -#ifdef FRSER_FEAT_NONSPI - -#ifdef FRSER_OPBUF_LEN -#define S_OPBUFLEN FRSER_OPBUF_LEN -#else - -#if defined(RAMEND) && defined(RAMSTART) -// Sys_bytes = stack + bss vars. -#ifndef FRSER_SYS_BYTES -#define FRSER_SYS_BYTES 320 -#endif -#define RAM_BYTES (RAMEND-RAMSTART+1) -/* The length of the operation buffer */ -#define S_OPBUFLEN (RAM_BYTES-FRSER_SYS_BYTES-UART_BUFLEN-UARTTX_BUFLEN) -#else /* No RAM size info, default to 1k. */ -#define S_OPBUFLEN 1024 -#endif /* RAMEND && RAMSTART */ - -#endif /* FRSER_OPBUF_LEN */ - -#ifdef FRSER_FEAT_SPI -/* We need to handle the opcode manually if both SPI and not SPI... */ -#define DYN_WRNMAX -#else -/* If no SPI then based on opbuf. */ -#define WRNMAX WRNMAX_NONSPI -#endif - -#else -/* Fake. */ -#define S_OPBUFLEN 12 -/* Write-N never goes to opbuf, thus report based on UART buf. */ -#define WRNMAX WRNMAX_SPI -#endif - -struct constanswer { - uint8_t len; - PGM_P data; -} __attribute__ ((__packed__)); - -#ifdef FRSER_FEAT_LAST_OP -static uint8_t last_op; -uint8_t get_last_op(void) { - return last_op; -} -#define LAST_OP(x) do { last_op = (x); } while(0) -#else -#define LAST_OP(x) -#endif - -#ifndef FRSER_FEAT_PRE_OPRX_HOOK -#define FRSER_FEAT_PRE_OPRX_HOOK() -#endif - -#ifndef FRSER_FEAT_POST_OPRX_HOOK -#define FRSER_FEAT_POST_OPRX_HOOK() -#endif - - -/* Allow read-n-max override by frser-cfg.h and apply a default if not that or baud given... */ -#ifdef FRSER_READ_N_MAX -#define RDNMAX FRSER_READ_N_MAX -#else - -#ifndef BAUD -#define RDNMAX (64*1024) -#else -/* Calculate a nice read-n max value so that it doesnt hurt performance, but - doesnt allow the device to be accidentally left in an "infini-tx" mode. - This is the amount of data it can send based on baud rate in 2 seconds rounded to kB. */ -#define BYTERATE (BAUD/5) -#define KBPSEC ((BYTERATE+512)/1024) -#define RDNMAX (KBPSEC*1024) -#endif /* BAUD */ - -#endif /* FRSER_READ_N_MAX */ - -const char PROGMEM ca_iface[3] = { S_ACK, 0x01, 0x00 }; -const char PROGMEM ca_bitmap[33] = { S_ACK, FRSER_BM_B0, FRSER_BM_B1, FRSER_BM_B2, FRSER_BM_B3, 0 }; -const char PROGMEM ca_pgmname[17] = "\x06" FRSER_NAME; /* Small hack to include S_ACK in the name. */ -const char PROGMEM ca_serbuf[3] = { S_ACK, (UART_RBUFLEN)&0xFF, (UART_RBUFLEN>>8)&0xFF }; -const char PROGMEM ca_syncnop[2] = { S_NAK, S_ACK }; - -const char PROGMEM ca_opbufsz[3] = { S_ACK, S_OPBUFLEN&0xFF, (S_OPBUFLEN>>8)&0xFF }; -#ifndef DYN_WRNMAX -const char PROGMEM ca_wrnlen[4] = { S_ACK, WRNMAX&0xFF, (WRNMAX>>8)&0xFF, 0 }; -#endif -const char PROGMEM ca_rdnmaxlen[4] = { S_ACK, RDNMAX&0xFF, (RDNMAX>>8)&0xFF, (RDNMAX>>16)&0xFF }; - -#ifndef FRSER_FEAT_DYNPROTO -const char PROGMEM ca_bustypes[2] = { S_ACK, SUPPORTED_BUSTYPES }; -#endif - -#ifdef FRSER_FEAT_PARALLEL -const char PROGMEM ca_chipsize[2] = { S_ACK, FRSER_PARALLEL_BITS }; -#endif - -/* Commands with a const answer cannot have parameters */ -const struct constanswer PROGMEM const_table[S_MAXCMD+1] = { - { 1, ca_iface }, // NOP - { 3, ca_iface }, // IFACE V - { 33, ca_bitmap }, // op bitmap - { 17, ca_pgmname }, // programmer name - { 3, ca_serbuf }, // serial buffer size -#ifdef FRSER_FEAT_DYNPROTO - { 0, NULL }, // bustypes -#else - { 2, ca_bustypes }, -#endif - -#ifdef FRSER_FEAT_PARALLEL - { 2, ca_chipsize }, // chip size -#else - { 0, NULL }, -#endif - - { 3, ca_opbufsz }, // operation buffer size -#ifdef DYN_WRNMAX - { 0, NULL }, -#else - { 4, ca_wrnlen }, // write-n max len -#endif - { 0, NULL }, // read byte - { 0, NULL }, // read n - { 0, NULL }, // init opbuf - { 0, NULL }, // opbuf, write-1 - { 0, NULL }, // opbuf, write-n - { 0, NULL }, // opbuf, delay - { 0, NULL }, // exec opbuf - { 2, ca_syncnop }, // sync nop - { 4, ca_rdnmaxlen }, // Read-n maximum len - { 0, NULL }, // Set bustype - { 0, NULL }, // SPI operation - { 0, NULL }, // SPI speed - { 0, NULL }, // set output drivers - { 1, ca_syncnop }, // JEDEC toggle rdy => NAK (discard that thing) - { 0, NULL }, // Poll - { 0, NULL } // Poll w delay -}; - -const uint8_t PROGMEM op2len[S_MAXCMD+1] = { - /* A table to get parameter length from opcode if possible (if not 0) */ - 0x00, 0x00, 0x00, /* NOP, iface, bitmap */ - 0x00, 0x00, 0x00, /* progname, serbufsize, bustypes */ - 0x00, 0x00, 0x00, /* chipsize, opbufsz, query-n maxlen */ - 0x03, 0x06, 0x00, /* read byte, read n, init opbuf */ - 0x04, 0x00, 0x04, /* write byte, write n, write delay */ - 0x00, 0x00, 0x00, /* Exec opbuf, syncnop, max read-n */ - 0x01, 0x06, 0x04, /* Set used bustype, SPI op, spi-speed */ - 0x01, 0x00, 0x04, /* output drivers, togglerdy(nakd), poll */ - 0x08 /* poll+delay */ -}; - -#ifdef FRSER_FEAT_S_BUSTYPE -static uint8_t last_set_bus_types; -#else -/* Read-only */ -#define last_set_bus_types SUPPORTED_BUSTYPES -#endif - -#ifdef FRSER_FEAT_PIN_STATE -static uint8_t last_set_pin_state; -#endif - - -static uint32_t buf2u24(uint8_t *buf) { - u32_u u24; - u24.b[0] = buf[0]; - u24.b[1] = buf[1]; - u24.b[2] = buf[2]; - u24.b[3] = 0; - return u24.l; -} - -#ifdef FRSER_FEAT_NONSPI - -#define OPBUF_WRITENOP 0x00 -#define OPBUF_WRITE1OP 0x01 -#define OPBUF_DELAYOP 0x02 -#define OPBUF_POLL 0x03 -#define OPBUF_POLL_DLY 0x04 - -static uint8_t opbuf[S_OPBUFLEN]; -static uint16_t opbuf_bytes = 0; - -static uint8_t opbuf_check(uint16_t addsz) { - if ((opbuf_bytes + addsz) > S_OPBUFLEN) { - return 1; - } - return 0; -} - -static void do_cmd_opbuf(uint8_t *parbuf, uint8_t op, uint8_t l) { - if (opbuf_check(l+1)) { - SEND(S_NAK); - return; - } - opbuf[opbuf_bytes++] = op; - for (uint8_t i=0;i= opbuf_bytes) goto nakret; - if ((op == OPBUF_WRITE1OP)||(op==OPBUF_WRITENOP)) { - uint32_t addr; - u16_u len; - uint16_t i; - len.l = 1; - if (op==OPBUF_WRITENOP) { - len.b[0] = opbuf[readptr++]; - len.b[1] = opbuf[readptr++]; - } - addr = buf2u24(opbuf+readptr); - readptr += 3; - if ((readptr+len.l) > opbuf_bytes) goto nakret; - for(i=0;;) { - uint8_t c; - c = opbuf[readptr++]; - flash_write(addr,c); - addr++; - i++; - if (i==len.l) break; - } - continue; - } - if (op == OPBUF_DELAYOP) { - u32_u usecs; - usecs.b[0] = opbuf[readptr++]; - usecs.b[1] = opbuf[readptr++]; - usecs.b[2] = opbuf[readptr++]; - usecs.b[3] = opbuf[readptr++]; - if (readptr > opbuf_bytes) goto nakret; - udelay(usecs.l); - continue; - } - if ((op == OPBUF_POLL)||(op == OPBUF_POLL_DLY)) { - uint8_t tmp1, tmp2; - uint32_t i = 0; - u32_u usecs; - usecs.l = 0; - uint8_t details = opbuf[readptr++]; - uint32_t addr = buf2u24(opbuf+readptr); - readptr += 3; - if (op == OPBUF_POLL_DLY) { - usecs.b[0] = opbuf[readptr++]; - usecs.b[1] = opbuf[readptr++]; - usecs.b[2] = opbuf[readptr++]; - usecs.b[3] = opbuf[readptr++]; - } - if (readptr > opbuf_bytes) goto nakret; - /* For random inputs i might not have bothered with the LUT, - * but because it is mostly 6 or 7 shifts i think the LUT is a win. */ - uint8_t mask = pgm_read_byte( &(bit_mask_lut[details&7]) ); - if (details&0x10) { - /* toggle mode */ - tmp1 = flash_read(addr) & mask; - } else { - /* data wait mode */ - tmp1 = details&0x20 ? mask : 0; - } - while (i++ < 0xFFFFFFF) { - if (usecs.l) udelay(usecs.l); - tmp2 = flash_read(addr) & mask; - if (tmp1 == tmp2) { - break; - } - /* Only move in toggle mode */ - if (details&0x10) tmp1 = tmp2; - } - continue; - } - - goto nakret; - } - opbuf_bytes = 0; - SEND(S_ACK); - return; -nakret: - opbuf_bytes = 0; - SEND(S_NAK); - return; -} - - -static void do_cmd_opbuf_init(void) { - opbuf_bytes = 0; -} - - -static void do_cmd_readbyte(uint8_t *parbuf) { - uint8_t c; - uint32_t addr; - SEND(S_ACK); - addr = buf2u24(parbuf); - c = flash_read(addr); - SEND(c); -} - -static void do_cmd_readnbytes(uint8_t *parbuf) { - uint32_t addr; - uint32_t n; - SEND(S_ACK); - addr = buf2u24(parbuf); - n = buf2u24(parbuf+3); - if (n==0) n = ((uint32_t)1 << 24); /* Protocol detail, dont show it to flash_readn */ - flash_readn(addr,n); -} -#else /* FRSER_FEAT_NONSPI ^^ */ -static uint32_t opbuf_delay_acc = 0; - -static void do_cmd_opbuf_delay(uint8_t *parbuf) { - u32_u usecs; - usecs.l = 0; - usecs.b[0] = parbuf[0]; - usecs.b[1] = parbuf[1]; - usecs.b[2] = parbuf[2]; - usecs.b[3] = parbuf[3]; - opbuf_delay_acc += usecs.l; - SEND(S_ACK); - return; -} - -static void do_cmd_opbuf_init(void) { - opbuf_delay_acc = 0; -} - -static void do_cmd_opbuf_exec(void) { - if (opbuf_delay_acc) udelay(opbuf_delay_acc); - opbuf_delay_acc = 0; - SEND(S_ACK); -} -#endif - -#ifdef FRSER_FEAT_SPI -static void do_cmd_spiop(uint8_t *parbuf) { - uint32_t sbytes; - uint32_t rbytes; - sbytes = buf2u24(parbuf); - rbytes = buf2u24(parbuf+3); - flash_spiop(sbytes,rbytes); -} - -#ifdef FRSER_FEAT_SPISPEED -static void do_cmd_spispeed(uint8_t* parbuf) { - u32_u hz; - hz.b[0] = parbuf[0]; - hz.b[1] = parbuf[1]; - hz.b[2] = parbuf[2]; - hz.b[3] = parbuf[3]; - if (hz.l==0) { /* I think this spec is stupid. /UR */ - SEND(S_NAK); - return; - } - u32_u new_hz; - new_hz.l = spi_set_speed(hz.l); - SEND(S_ACK); - SEND(new_hz.b[0]); - SEND(new_hz.b[1]); - SEND(new_hz.b[2]); - SEND(new_hz.b[3]); -} -#endif -#endif - -static void do_cmd_set_proto(uint8_t v) { -#ifdef FRSER_FEAT_PIN_STATE - if (last_set_pin_state) { - flash_select_protocol(v); - } -#else - flash_select_protocol(v); -#endif -#ifdef FRSER_FEAT_S_BUSTYPE - last_set_bus_types = v; -#endif -} - -#ifdef FRSER_FEAT_PIN_STATE -static void do_cmd_pin_state(uint8_t v) { - if (v) { - flash_select_protocol(last_set_bus_types); - } else { - flash_set_safe(); - } - last_set_pin_state = v; -} -#endif - -void frser_init(void) { -#ifdef FRSER_FEAT_PIN_STATE - last_set_pin_state = 1; -#endif - LAST_OP(0xFE); - do_cmd_set_proto(SUPPORTED_BUSTYPES); // select any protocol you like, just select one. -} - -void frser_operation(uint8_t op) { -#ifdef FRSER_FEAT_UART_TIMEOUT - jmp_buf uart_timeout; -#endif - uint8_t parbuf[S_MAXLEN]; /* Parameter buffer */ - uint8_t a_len,p_len; - uint8_t i; - -#ifdef FRSER_FEAT_DBG_CONSOLE - if (op == 0x20) { /* Space bar gives you your debug console. */ - ciface_main(); - return; - } -#endif - - if (op > S_MAXCMD) { - /* Protect against out-of-bounds array read. */ - SEND(S_NAK); - return; - } - -#ifdef FRSER_FEAT_UART_TIMEOUT - if (setjmp(uart_timeout)) { - /* We might be in the middle of an SPI operation or otherwise - in a weird state. Re-init and hope for best. */ - do_cmd_set_proto(last_set_bus_types); - SEND(S_NAK); /* Tell of a problem. */ - uart_set_timeout(NULL); - return; - } -#endif - LAST_OP(op); - - a_len = pgm_read_byte(&(const_table[op].len)); - /* These are the simple query-like operations, we just reply from ProgMem: */ - /* NOTE: Operations that have a const answer cannot have parameters !!! */ - if (a_len) { - PGM_P data = (PGM_P)pgm_read_ptr(&(const_table[op].data)); - for(i=0;i>8); - } else { - SEND(WRNMAX_NONSPI & 0xFF); - SEND(WRNMAX_NONSPI>>8); - } - SEND(0); - break; -#endif -#ifdef FRSER_FEAT_NONSPI - case S_CMD_R_BYTE: - do_cmd_readbyte(parbuf); - break; - case S_CMD_R_NBYTES: - do_cmd_readnbytes(parbuf); - break; - case S_CMD_O_WRITEB: - do_cmd_opbuf_writeb(parbuf); - break; - case S_CMD_O_WRITEN: - do_cmd_opbuf_writen(); - break; - case S_CMD_O_POLL: - do_cmd_opbuf_poll(parbuf); - break; - case S_CMD_O_POLL_DLY: - do_cmd_opbuf_poll_dly(parbuf); - break; -#endif - -#ifdef FRSER_FEAT_DYNPROTO - case S_CMD_Q_BUSTYPE: /* Dynamic bus types. */ - SEND(S_ACK); - SEND(flash_plausible_protocols()); - break; -#endif - - case S_CMD_O_INIT: - SEND(S_ACK); - do_cmd_opbuf_init(); - /* Select protocol atleast once per flashrom invocation in - order to detect change of chip between flashrom runs */ - do_cmd_set_proto(last_set_bus_types); - break; - - case S_CMD_O_DELAY: - do_cmd_opbuf_delay(parbuf); - break; - case S_CMD_O_EXEC: - do_cmd_opbuf_exec(); - break; - -#ifdef FRSER_FEAT_S_BUSTYPE - case S_CMD_S_BUSTYPE: - SEND(S_ACK); - do_cmd_set_proto(parbuf[0]); - break; -#endif -#ifdef FRSER_FEAT_SPI - case S_CMD_O_SPIOP: - do_cmd_spiop(parbuf); - break; -#ifdef FRSER_FEAT_SPISPEED - case S_CMD_S_SPI_FREQ: - do_cmd_spispeed(parbuf); - break; -#endif -#endif /* SPI */ - -#ifdef FRSER_FEAT_PIN_STATE - case S_CMD_S_PIN_STATE: - SEND(S_ACK); - do_cmd_pin_state(parbuf[0]); - break; -#endif - } -#ifdef FRSER_FEAT_UART_TIMEOUT - uart_set_timeout(NULL); -#endif - -} - -void frser_main(void) { - frser_init(); - for(;;) { - uint8_t op; - FRSER_FEAT_PRE_OPRX_HOOK(); - op = RECEIVE(); - FRSER_FEAT_POST_OPRX_HOOK(); - frser_operation(op); - } -} - diff --git a/teensy/lib/libfrser/src/frser.h b/teensy/lib/libfrser/src/frser.h deleted file mode 100644 index 1597761..0000000 --- a/teensy/lib/libfrser/src/frser.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2009,2015 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef _FRSER_H_ -#define _FRSER_H_ - -#include "frser-cfg.h" - -/* Call this and frser owns your thingy. */ -void frser_main(void) __attribute__((noreturn)); - -/* Alternatively, you can use this API: */ -void frser_init(void); -void frser_operation(uint8_t op); - -#ifdef FRSER_FEAT_LAST_OP -uint8_t get_last_op(void); -#endif - -/* These allow you to override to a single bustype (eg. FWH-only). */ -/* I suppose you could put one of them into frser-cfg.h too.. */ -/* Do still also pick the FRSER_FEAT_* that includes your bustype. */ - -//#define FORCE_BUSTYPE CHIP_BUSTYPE_PARALLEL -//#define FORCE_BUSTYPE CHIP_BUSTYPE_LPC -//#define FORCE_BUSTYPE CHIP_BUSTYPE_FWH -//#define FORCE_BUSTYPE CHIP_BUSTYPE_SPI - -#define CHIP_BUSTYPE_PARALLEL (1 << 0) -#define CHIP_BUSTYPE_LPC (1 << 1) -#define CHIP_BUSTYPE_FWH (1 << 2) -#define CHIP_BUSTYPE_SPI (1 << 3) - -#ifdef FRSER_FEAT_PARALLEL -#define _FR_SUPP0 CHIP_BUSTYPE_PARALLEL -#else -#define _FR_SUPP0 0 -#endif - -#ifdef FRSER_FEAT_LPCFWH -#define _FR_SUPP1 CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH -#else -#define _FR_SUPP1 0 -#endif - -#ifdef FRSER_FEAT_SPI -#define _FR_SUPP2 CHIP_BUSTYPE_SPI -#else -#define _FR_SUPP2 0 -#endif - -#ifdef FORCE_BUSTYPE -#define SUPPORTED_BUSTYPES FORCE_BUSTYPE -#else -#define SUPPORTED_BUSTYPES (_FR_SUPP0 | _FR_SUPP1 | _FR_SUPP2) -#endif - -#endif /* _FRSER_H_ */ diff --git a/teensy/lib/libfrser/src/l.cppfwh.c.example b/teensy/lib/libfrser/src/l.cppfwh.c.example deleted file mode 100644 index 273ca8e..0000000 --- a/teensy/lib/libfrser/src/l.cppfwh.c.example +++ /dev/null @@ -1,243 +0,0 @@ -/* - This file was part of bbflash, now frser-m328lpcspi. - Copyright (C) 2013, Hao Liu and Robert L. Thompson - Copyright (C) 2013,2015 Urja Rannikko - - 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 3 of the License, 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. If not, see . -*/ -#include "main.h" -#include "nibble.h" -#include "lpcfwh.h" -#include "typeu.h" -#include "uart.h" - -/* Generic */ - -static uint8_t nib_byte_read(void) { - return clocked_nibble_read() - | (clocked_nibble_read() << 4); -} - -static void nib_byte_write(uint8_t byte) { - clocked_nibble_write(byte); - clocked_nibble_write_hi(byte); -} - -static bool nibble_ready_sync(void) { - uint8_t nib; - uint8_t x=32; - do { - nib = clocked_nibble_read(); - if (!(x--)) { - /* Do a proper-ish abort, just to be nice. */ - nibble_abort(); - return false; - } - } while (nib != 0); - return true; -} - -static void nibble_send_addr_24b(uint32_t addr) { - u32_u a; - a.l = addr; - clocked_nibble_write_hi(a.b[2]); - clocked_nibble_write(a.b[2]); - clocked_nibble_write_hi(a.b[1]); - clocked_nibble_write(a.b[1]); - clocked_nibble_write_hi(a.b[0]); - clocked_nibble_write(a.b[0]); -} - -/* LPC start */ - -#define LPC_START 0b0000 -#define LPC_CYCTYPE_READ 0b0100 -#define LPC_CYCTYPE_WRITE 0b0110 - -bool lpc_init(void) { - return nibble_init(); -} - -void lpc_cleanup(void) { - nibble_cleanup(); -} - - -static void lpc_start(void) { - nibble_start(LPC_START); -} - -#define lpc_nibble_write(v) clocked_nibble_write(v) - - -static void lpc_send_addr(uint32_t addr) { - /* NOTE: Hard-coded uppest 8b. */ - lpc_nibble_write(0xF); - clock_cycle(); - nibble_send_addr_24b(addr); -} - -int lpc_read_address(uint32_t addr) { - lpc_start(); - lpc_nibble_write(LPC_CYCTYPE_READ); - lpc_send_addr(addr); - nibble_set_dir(INPUT); - clock_cycle(); - if (!nibble_ready_sync()) - return -1; - uint8_t byte = nib_byte_read(); - clock_cycle(); - clock_cycle(); - clock_cycle(); - return byte; -} - -bool lpc_write_address(uint32_t addr, uint8_t byte) { - lpc_start(); - lpc_nibble_write(LPC_CYCTYPE_WRITE); - lpc_send_addr(addr); - nib_byte_write(byte); - nibble_set_dir(INPUT); - clock_cycle(); - clock_cycle(); - if (!nibble_ready_sync()) - return false; - clock_cycle(); - return true; -} - - - -uint8_t lpc_test(void) { - nibble_hw_init(); - lpc_init(); - if (lpc_read_address(0xFFFFFFFF)==-1) return 0; - return 1; -} - -/* LPC end, FWH start */ - -#define FWH_START_READ 0b1101 -#define FWH_START_WRITE 0b1110 -#define FWH_ABORT 0b1111 - -static uint8_t fwh_read_128 = 0; - -bool fwh_init(void) { - return nibble_init(); -} - -void fwh_cleanup(void) { - nibble_cleanup(); -} - -#define fwh_nibble_write(v) clocked_nibble_write(v) -#define fwh_start(v) nibble_start(v) - -static void fwh_send_imaddr(uint32_t addr) { - /* NOTE: hard-coded uppest 4b. */ - fwh_nibble_write(0xF); - nibble_send_addr_24b(addr); -} - -int fwh_read_address(uint32_t addr) { - fwh_start(FWH_START_READ); - fwh_nibble_write(0); /* IDSEL hardwired */ - fwh_send_imaddr(addr); - fwh_nibble_write(0); /* IMSIZE single byte */ - nibble_set_dir(INPUT); - clock_cycle(); - if (!nibble_ready_sync()) - return -1; - uint8_t byte = nib_byte_read(); - clock_cycle(); - nibble_set_dir(OUTPUT); - fwh_nibble_write(0xf); - clock_cycle(); - return byte; -} - -static int fwh_test_128b(void) { - fwh_start(FWH_START_READ); - fwh_nibble_write(0); /* IDSEL hardwired */ - fwh_send_imaddr(0xFFFFFF80); - fwh_nibble_write(7); /* IMSIZE 128b */ - nibble_set_dir(INPUT); - clock_cycle(); - if (!nibble_ready_sync()) - return 0; - for (int i=0;i<256;i++) clock_cycle(); - clock_cycle(); - nibble_set_dir(OUTPUT); - fwh_nibble_write(0xf); - clock_cycle(); - return 1; -} - -void fwh_read_n(uint32_t addr, uint32_t len) { - if (!fwh_read_128) { - while (len--) SEND(fwh_read_address(addr++)); - return; - } - /* Align read ... */ - while (addr & 0x7F) { - SEND(fwh_read_address(addr++)); - len--; - if (!len) return; - } - while (len >= 128) { - fwh_start(FWH_START_READ); - fwh_nibble_write(0); /* IDSEL hardwired */ - fwh_send_imaddr(addr); - fwh_nibble_write(7); /* IMSIZE 128b */ - nibble_set_dir(INPUT); - clock_cycle(); - if (!nibble_ready_sync()) - break; // Try with the single-byte version then... - for (int i=0;i<128;i++) SEND(nib_byte_read()); - clock_cycle(); - nibble_set_dir(OUTPUT); - fwh_nibble_write(0xf); - clock_cycle(); - len -= 128; - addr += 128; - } - /* Do the remainder if any. */ - while (len--) SEND(fwh_read_address(addr++)); - -} - -bool fwh_write_address(uint32_t addr, uint8_t byte) { - fwh_start(FWH_START_WRITE); - fwh_nibble_write(0); /* IDSEL hardwired */ - fwh_send_imaddr(addr); - fwh_nibble_write(0); /* IMSIZE single byte */ - nib_byte_write(byte); - nibble_write(0xf); - nibble_set_dir(INPUT); - clock_cycle(); - clock_cycle(); - if (!nibble_ready_sync()) - return false; - clock_cycle(); - return true; -} - -uint8_t fwh_test(void) { - nibble_hw_init(); - fwh_init(); - if (fwh_read_address(0xFFFFFFFF)==-1) return 0; - fwh_read_128 = fwh_test_128b(); - return 1 + fwh_read_128; -} diff --git a/teensy/lib/libfrser/src/lpcfwh.h.example b/teensy/lib/libfrser/src/lpcfwh.h.example deleted file mode 100644 index 9db4eee..0000000 --- a/teensy/lib/libfrser/src/lpcfwh.h.example +++ /dev/null @@ -1,37 +0,0 @@ -/* - This file was part of bbflash, is part of frser-m328lpcspi. - Copyright (C) 2013, Hao Liu and Robert L. Thompson - - 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 3 of the License, 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. If not, see . -*/ -#ifndef LPCFWH_H_ -#define LPCFWH_H_ -#include "mybool.h" - -/* LPC */ -bool lpc_init(void); -uint8_t lpc_test(void); -void lpc_cleanup(void); -int lpc_read_address(uint32_t addr); -bool lpc_write_address(uint32_t addr, uint8_t byte); - -/* FWH */ -bool fwh_init(void); -uint8_t fwh_test(void); -void fwh_cleanup(void); -int fwh_read_address(uint32_t addr); -bool fwh_write_address(uint32_t addr, uint8_t byte); -void fwh_read_n(uint32_t addr, uint32_t len); - -#endif /* LPCFWH_H_ */ diff --git a/teensy/lib/libfrser/src/main.h b/teensy/lib/libfrser/src/main.h deleted file mode 100644 index 295ea04..0000000 --- a/teensy/lib/libfrser/src/main.h +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -#if defined(ARDUINO_TEENSY31) || defined(ARDUINO_TEENSY36) -#include -#endif - diff --git a/teensy/lib/libfrser/src/main.h.example b/teensy/lib/libfrser/src/main.h.example deleted file mode 100644 index 3d36695..0000000 --- a/teensy/lib/libfrser/src/main.h.example +++ /dev/null @@ -1,9 +0,0 @@ -/* This is a hypothetical example of what libfrser expects main.h to contain. */ - -#include -#include "pgmspace-compat.h" -#include -#include -#include -#include -#include diff --git a/teensy/lib/libfrser/src/mybool.h.example b/teensy/lib/libfrser/src/mybool.h.example deleted file mode 100644 index 668f695..0000000 --- a/teensy/lib/libfrser/src/mybool.h.example +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef MYBOOL_H -#define MYBOOL_H -#include - -typedef uint8_t bool; -#define true 1 -#define false 0 - -#endif diff --git a/teensy/lib/libfrser/src/nibble.c.example b/teensy/lib/libfrser/src/nibble.c.example deleted file mode 100644 index 5d06f7e..0000000 --- a/teensy/lib/libfrser/src/nibble.c.example +++ /dev/null @@ -1,149 +0,0 @@ -/* - This file was part of bbflash, now frser-m328lpcspi. - Copyright (C) 2013, Hao Liu and Robert L. Thompson - Copyright (C) 2013 Urja Rannikko - - 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 3 of the License, 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. If not, see . -*/ -#include "main.h" -#include "nibble.h" - -#define delay() asm("nop") -#define swap(x) do { asm volatile("swap %0" : "=r" (x) : "0" (x)); } while(0) - - - -#define FRAME_DDR DDRD -#define FRAME_PORT PORTD -#define FRAME PD3 - - -#define INIT_DDR DDRD -#define INIT_PORT PORTD -#define INIT PD4 - -void nibble_set_dir(uint8_t dir) { - if (!dir) { - DDRC = 0; - } -} - -uint8_t nibble_read(void) { - uint8_t rv; - rv = PINC & 0xF; - return rv; -} - -static void nibble_write_hi(uint8_t data) { - swap(data); - DDRC = (~data) & 0xF; -// data &= 0xF; -// while ((PINC & 0xF) != data); -} - -void nibble_write(uint8_t data) { - DDRC = (~data) & 0xF; -// data &= 0xF; -// while ((PINC & 0xF) != data); -} - -#define clock_low() do { CLK_PORT &= ~_BV(CLK); } while(0) -#define clock_high() do { CLK_PORT |= _BV(CLK); } while(0) - - - -bool nibble_init(void) { - uint8_t i; - - INIT_PORT &= ~_BV(INIT); - INIT_DDR |= _BV(INIT); - - CLK_DDR |= _BV(CLK); - CLK_PORT |= _BV(CLK); - - FRAME_DDR |= _BV(FRAME); - FRAME_PORT |= _BV(FRAME); - - nibble_set_dir(OUTPUT); - nibble_write(0); - - for (i = 0; i < 24; i++) - clock_cycle(); - INIT_DDR &= ~_BV(INIT); - _delay_us(1); // Let pullup work - for (i = 0; i < 42; i++) - clock_cycle(); - - return true; -} - -void nibble_cleanup(void) { - CLK_DDR &= ~_BV(CLK); - FRAME_DDR &= ~_BV(FRAME); - nibble_set_dir(INPUT); -} - -void clocked_nibble_write(uint8_t value) { - clock_low(); - nibble_write(value); - clock_high(); -} - -void clocked_nibble_write_hi(uint8_t value) { - clock_low(); - nibble_write_hi(value); - clock_high(); -} - -uint8_t clocked_nibble_read(void) { - clock_cycle(); - delay(); - delay(); - return nibble_read(); -} - -void nibble_abort(void) { - gpio_set(FRAME_PORT, FRAME); - nibble_set_dir(OUTPUT); - clock_high(); - gpio_clear(FRAME_PORT, FRAME); - nibble_write(0xF); - clock_cycle(); - clock_cycle(); - clock_cycle(); - clock_cycle(); - gpio_set(FRAME_PORT, FRAME); - clock_cycle(); - clock_cycle(); -} - -void nibble_start(uint8_t start) { - FRAME_PORT |= _BV(FRAME); - nibble_set_dir(OUTPUT); - clock_high(); - FRAME_PORT &= ~_BV(FRAME); - nibble_write(start); - clock_cycle(); - FRAME_PORT |= _BV(FRAME); -} - -void nibble_hw_init(void) { - /* Do your port init if needed etc... */ - - /* Kick reset here so lpc/fwh.c doesnt need to know about how it is controlled. */ - DDRD |= _BV(2); //!RST - _delay_us(1); - DDRD &= ~_BV(2); - _delay_us(1); // slow pullup -} diff --git a/teensy/lib/libfrser/src/nibble.h b/teensy/lib/libfrser/src/nibble.h deleted file mode 100644 index 76f0242..0000000 --- a/teensy/lib/libfrser/src/nibble.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - This file was part of bbflash, now frser-m328lpcspi. - Copyright (C) 2013, Hao Liu and Robert L. Thompson - - 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 3 of the License, 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. If not, see . -*/ -#ifndef NIBBLE_H_ -#define NIBBLE_H_ - -bool nibble_init(void) {return true;} -void nibble_cleanup(void) {} -void clocked_nibble_write(uint8_t value) {} -void clocked_nibble_write_hi(uint8_t value) {} -uint8_t clocked_nibble_read(void) {return 0;} -void nibble_start(uint8_t start) {} -void nibble_hw_init(void) {} -void nibble_set_dir(uint8_t dir) {} -uint8_t nibble_read(void) {return 0;} -void nibble_write(uint8_t data) {}; -void nibble_abort(void) {}; - - -#define clock_cycle() do { } while(0) - -#endif /* NIBBLE_H_ */ diff --git a/teensy/lib/libfrser/src/nibble.h.example b/teensy/lib/libfrser/src/nibble.h.example deleted file mode 100644 index 215263d..0000000 --- a/teensy/lib/libfrser/src/nibble.h.example +++ /dev/null @@ -1,47 +0,0 @@ -/* - This file was part of bbflash, now frser-m328lpcspi. - Copyright (C) 2013, Hao Liu and Robert L. Thompson - - 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 3 of the License, 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. If not, see . -*/ -#ifndef NIBBLE_H_ -#define NIBBLE_H_ -#include "mybool.h" - -#define OUTPUT 1 -#define INPUT 0 - -/* This is just a part of the header because clock_cycle() macro needs it, - not a part of the official interface. */ -#define CLK_DDR DDRD -#define CLK_PORT PORTD -#define CLK PD7 - - -bool nibble_init(void); -void nibble_cleanup(void); -void clocked_nibble_write(uint8_t value); -void clocked_nibble_write_hi(uint8_t value); -uint8_t clocked_nibble_read(void); -void nibble_start(uint8_t start); -void nibble_hw_init(void); -void nibble_set_dir(uint8_t dir); -uint8_t nibble_read(void); -void nibble_write(uint8_t data); -void nibble_abort(void); - - -#define clock_cycle() do { CLK_PORT &= ~_BV(CLK); CLK_PORT |= _BV(CLK); } while(0) - -#endif /* NIBBLE_H_ */ diff --git a/teensy/lib/libfrser/src/pgmspace-compat.h b/teensy/lib/libfrser/src/pgmspace-compat.h deleted file mode 100644 index 9355d96..0000000 --- a/teensy/lib/libfrser/src/pgmspace-compat.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef __PGMSPACE_H_ -#define __PGMSPACE_H_ 1 - -#define PROGMEM -#define PGM_P const char * -#define PSTR(str) (str) - -#define _SFR_BYTE(n) (n) - -typedef void prog_void; -typedef char prog_char; -typedef unsigned char prog_uchar; -typedef int8_t prog_int8_t; -typedef uint8_t prog_uint8_t; -typedef int16_t prog_int16_t; -typedef uint16_t prog_uint16_t; -typedef int32_t prog_int32_t; -typedef uint32_t prog_uint32_t; - -#define memchr_P(str, c, len) memchr((str), (c), (len)) -#define memcmp_P(a, b, n) memcmp((a), (b), (n)) -#define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) -#define memmem_P(a, alen, b, blen) memmem((a), (alen), (b), (blen)) -#define memrchr_P(str, val, len) memrchr((str), (val), (len)) -#define strcat_P(dest, src) strcat((dest), (src)) -#define strchr_P(str, c) strchr((str), (c)) -#define strchrnul_P(str, c) strchrnul((str), (c)) -#define strcmp_P(a, b) strcmp((a), (b)) -#define strcpy_P(dest, src) strcpy((dest), (src)) -#define strcasecmp_P(a, b) strcasecmp((a), (b)) -#define strcasestr_P(a, b) strcasestr((a), (b)) -#define strlcat_P(dest, src, len) strlcat((dest), (src), (len)) -#define strlcpy_P(dest, src, len) strlcpy((dest), (src), (len)) -#define strlen_P(s) strlen((const char *)(s)) -#define strnlen_P(str, len) strnlen((str), (len)) -#define strncmp_P(a, b, n) strncmp((a), (b), (n)) -#define strncasecmp_P(a, b, n) strncasecmp((a), (b), (n)) -#define strncat_P(a, b, n) strncat((a), (b), (n)) -#define strncpy_P(a, b, n) strncpy((a), (b), (n)) -#define strpbrk_P(str, chrs) strpbrk((str), (chrs)) -#define strrchr_P(str, c) strrchr((str), (c)) -#define strsep_P(strp, delim) strsep((strp), (delim)) -#define strspn_P(str, chrs) strspn((str), (chrs)) -#define strstr_P(a, b) strstr((a), (b)) -#define sprintf_P(s, ...) sprintf((s), __VA_ARGS__) -#define vfprintf_P(s, ...) vfprintf((s), __VA_ARGS__) -#define printf_P(...) printf(__VA_ARGS__) -#define snprintf_P(s, n, ...) ((s), (n), __VA_ARGS__) -#define vsprintf_P(s, ...) ((s),__VA_ARGS__) -#define vsnprintf_P(s, n, ...) ((s), (n),__VA_ARGS__) -#define fprintf_P(s, ...) ((s), __VA_ARGS__) - -#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) -#define pgm_read_word(addr) (*(const unsigned short *)(addr)) -#define pgm_read_dword(addr) (*(const unsigned long *)(addr)) -#define pgm_read_float(addr) (*(const float *)(addr)) -#define pgm_read_ptr(addr) (*(const void**)(addr)) - -#define pgm_read_byte_near(addr) pgm_read_byte(addr) -#define pgm_read_word_near(addr) pgm_read_word(addr) -#define pgm_read_dword_near(addr) pgm_read_dword(addr) -#define pgm_read_float_near(addr) pgm_read_float(addr) -#define pgm_read_byte_far(addr) pgm_read_byte(addr) -#define pgm_read_word_far(addr) pgm_read_word(addr) -#define pgm_read_dword_far(addr) pgm_read_dword(addr) -#define pgm_read_float_far(addr) pgm_read_float(addr) - -#endif diff --git a/teensy/lib/libfrser/src/spi_cs.h b/teensy/lib/libfrser/src/spi_cs.h deleted file mode 100644 index 16479d5..0000000 --- a/teensy/lib/libfrser/src/spi_cs.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef _SPI_CS_H_ -#define _SPI_CS_H_ -#include -#include -/* These can be functions if it makes sense, but these compile to so few instructions. */ -//#define spi_select() do { digitalWrite(15, LOW); } while(0) -/* delay because slow pullup. */ -//#define spi_deselect() do { digitalWrite(15, HIGH); delayMicroseconds(1); } while(0); - -#endif diff --git a/teensy/lib/libfrser/src/spi_cs.h.example b/teensy/lib/libfrser/src/spi_cs.h.example deleted file mode 100644 index c878291..0000000 --- a/teensy/lib/libfrser/src/spi_cs.h.example +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef _SPI_CS_H_ -#define _SPI_CS_H_ - -/* These can be functions if it makes sense, but these compile to so few instructions. */ - -#define spi_select() do { DDRB |=_BV(0); } while(0) -/* delay because slow pullup. */ -#define spi_deselect() do { DDRB &= ~_BV(0); _delay_us(1); } while(0); - -#endif diff --git a/teensy/lib/libfrser/src/spihw.h b/teensy/lib/libfrser/src/spihw.h deleted file mode 100644 index 91c4c9b..0000000 --- a/teensy/lib/libfrser/src/spihw.h +++ /dev/null @@ -1,3 +0,0 @@ -/* Define what our hardware is. */ -#include "spihw_teensyspi.h" -#include "spi_cs.h" diff --git a/teensy/lib/libfrser/src/spihw.h.example b/teensy/lib/libfrser/src/spihw.h.example deleted file mode 100644 index 6b6dd8c..0000000 --- a/teensy/lib/libfrser/src/spihw.h.example +++ /dev/null @@ -1,3 +0,0 @@ -/* Define what our hardware is. */ -#include "spihw_avrspi.h" -#include "spi_cs.h" diff --git a/teensy/lib/libfrser/src/spihw_avrspi.c.example b/teensy/lib/libfrser/src/spihw_avrspi.c.example deleted file mode 100644 index eb3561c..0000000 --- a/teensy/lib/libfrser/src/spihw_avrspi.c.example +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2015 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "main.h" -#include "spihw_avrspi.h" -#include "frser-cfg.h" - -/* This is for the usage of the SPI module of the ATmega88/168/328, maybe others. */ -/* Doesnt deal with CS. */ - -static uint8_t spi_initialized = 0; - -#ifdef FRSER_FEAT_SPISPEED -static uint8_t spi_set_spd = 0; /* Max speed - F_CPU/2 */ - -const uint8_t PROGMEM spd_table[7] = { - 0x80, // SPI2X is 0x80 in this table because i say so. - div 2 - 0, // div 4 - 0x80 | _BV(SPR0), // div 8 - _BV(SPR0), // div 16 - 0x80 | _BV(SPR1), // div 32 - _BV(SPR1), // div64 - _BV(SPR1) | _BV(SPR0), //div128 -}; - -const uint32_t PROGMEM spd_hz_table[7] = { - F_CPU/2, F_CPU/4, F_CPU/8, F_CPU/16, F_CPU/32, F_CPU/64, F_CPU/128 -}; - -uint32_t spi_set_speed(uint32_t hz) { - /* We can set F_CPU / : 2,4,8,16,32,64,128 */ - - uint8_t spd; - uint32_t hz_spd; - - /* Range check. */ - if (hz<=(F_CPU/128)) { - spd = 6; - hz_spd = F_CPU/128; - } else { - for (spd=0;spd<7;spd++) { - hz_spd = pgm_read_dword(&(spd_hz_table[spd])); - if (hz >= hz_spd) break; - } - } - spi_set_spd = spd; - if (spi_initialized) { // change speed - spi_init(); // re-init - } - return hz_spd; -} - - -void spi_init(void) { - /* DDR and PORT settings come from elsewhere (maybe flash.c) */ - uint8_t spdv = pgm_read_byte(&(spd_table[spi_set_spd])); - SPCR = _BV(SPE) | _BV(MSTR) | (spdv & 0x03); - if (spdv&0x80) SPSR |= _BV(SPI2X); - else SPSR &= ~_BV(SPI2X); - spi_initialized = 1; -} -#else -void spi_init(void) { - /* No speed setting code wanted? Max speed. */ - SPCR = _BV(SPE) | _BV(MSTR); - SPSR |= _BV(SPI2X); - spi_initialized = 1; -} -#endif - -uint8_t spi_uninit(void) { - if (spi_initialized) { - SPCR = 0; - spi_initialized = 0; - return 1; - } - return 0; -} - -void spi_awrite_fast(uint8_t d) { - SPDR = d; -} - -void spi_awrite(uint8_t d) { - uint8_t dummy = SPSR; /* Flush previous SPIF */ - SPDR = d; - if (SPSR & _BV(WCOL)) { - loop_until_bit_is_set(SPSR,SPIF); - SPDR = d; - } - (void)dummy; /* Silence compiler */ -} - -uint8_t spi_aread(void) { - loop_until_bit_is_set(SPSR,SPIF); - return SPDR; -} - -uint8_t spi_txrx(const uint8_t c) { - spi_awrite_fast(c); - return spi_aread(); -} - - - -/* This is here only to keep spi_initialized a static variable, - * hidden from other bits of code. */ - -void spi_init_cond(void) { - if (!spi_initialized) spi_init(); -} - -/* Select and deselect are not part of the "domain" of this .c / target-specific */ diff --git a/teensy/lib/libfrser/src/spihw_avrspi.h.example b/teensy/lib/libfrser/src/spihw_avrspi.h.example deleted file mode 100644 index e7a82db..0000000 --- a/teensy/lib/libfrser/src/spihw_avrspi.h.example +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _SPIHW_AVRSPI_H_ -#define _SPIHW_AVRSPI_H_ -/* This will give spi_set_speed if needed. A bit illogically maybe, but anyways... */ -#include "frser-flashapi.h" - -void spi_init(void); -uint8_t spi_uninit(void); -uint8_t spi_txrx(const uint8_t c); - -#define FRSER_ASYNC_SPI_API -void spi_awrite_fast(uint8_t d); -void spi_awrite(uint8_t d); -uint8_t spi_aread(void); - -/* Async SPI API: - * write_fast: assumes SPI idle*, starts a transfer - * write: will wait for space (or use a FIFO if available) - * read: returns the byte associated with the last write_fast / write (=will wait for transfer complete). - * - * *SPI is idle after spi_read / spi_txrx / spi_init. - * Do NOT: - * write* + write_fast - * (no write)/read + read - * - those undefined actions can lead to anything, including infinite loop/reset/undefined TX value/things appearing to work. - * Note: spi_txrx is allowed to be write_fast + read. thus do not write* + spi_txrx. - */ - -void spi_init_cond(void); - -#endif diff --git a/teensy/lib/libfrser/src/spihw_teensyspi.cpp b/teensy/lib/libfrser/src/spihw_teensyspi.cpp deleted file mode 100644 index f98ed8a..0000000 --- a/teensy/lib/libfrser/src/spihw_teensyspi.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2015 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "main.h" -#include "spihw_teensyspi.h" -#include "frser-cfg.h" -#include -#include -#include -#include "spilib.h" - -/* This is for the usage of the SPI module of the ATmega88/168/328, maybe others. */ -/* Doesnt deal with CS. */ - -static uint8_t spi_initialized = 0; - -#ifdef FRSER_FEAT_SPISPEED -static uint32_t spi_set_spd = 4000000; /* Max speed - F_CPU/2 */ - -static uint8_t flexspi_ctrl = 0; - -uint32_t spi_set_speed(uint32_t hz) { - /* We can set F_CPU / : 2,4,8,16,32,64,128 */ - - spi_set_spd = hz; - if (spi_initialized) { // change speed - spi_init(); // re-init - } - return hz; -} -void spi_set_port(int spi_port) { - spi_uninit(); - flexspi_ctrl = spi_port; - spi_init(); - -} - -void spi_init(void) { - /* DDR and PORT settings come from elsewhere (maybe flash.c) */ - if (flexspi_ctrl == 0) { - pinMode(SPI_CS_PIN, OUTPUT); - pinMode(SPI_SCK_PIN, OUTPUT); - SPI.setSCK(SPI_SCK_PIN); - SPI.begin(); - SPI.setSCK(SPI_SCK_PIN); - - SPI.beginTransaction(SPISettings(spi_set_spd, MSBFIRST, SPI_MODE0)); - }else if (flexspi_ctrl == 1){ -#ifdef ARDUINO_TEENSY41 - SPI2.setMISO(SPI2_DI_PIN); - SPI2.setMOSI(SPI2_DO_PIN); - SPI2.setSCK(SPI2_SCK_PIN); - SPI2.begin(); - SPI2.setMISO(SPI2_DI_PIN); - SPI2.setMOSI(SPI2_DO_PIN); - SPI2.setSCK(SPI2_SCK_PIN); - SPI2.beginTransaction(SPISettings(spi_set_spd, MSBFIRST, SPI_MODE0)); -#elif defined(ARDUINO_TEENSY40) - SPI1.setMISO(SPI1_DI_PIN); - SPI1.setMOSI(SPI1_DO_PIN); - SPI1.setSCK(SPI1_SCK_PIN); - SPI1.begin(); - SPI1.setMISO(SPI1_DI_PIN); - SPI1.setMOSI(SPI1_DO_PIN); - SPI1.setSCK(SPI1_SCK_PIN); - SPI1.beginTransaction(SPISettings(spi_set_spd, MSBFIRST, SPI_MODE0)); -#endif - } - spi_initialized = 1; -} -#else - -#endif - -uint8_t spi_uninit(void) { - if (spi_initialized) { - if (flexspi_ctrl == 0) { - SPI.endTransaction(); - } else if (flexspi_ctrl ==1) { -#if defined(ARDUINO_TEENSY41) - SPI2.endTransaction(); -#elif defined(ARDUINO_TEENSY40) - SPI1.endTransaction(); -#endif - } - spi_initialized = 0; - return 1; - } - return 0; -} - - -uint8_t spi_txrx(const uint8_t c) { - if (flexspi_ctrl == 0) { - return SPI.transfer(c); - }else if (flexspi_ctrl ==1){ -#if defined(ARDUINO_TEENSY41) - return SPI2.transfer(c); -#elif defined(ARDUINO_TEENSY40) - return SPI1.transfer(c); -#endif - } - return 0; -} - - - -/* This is here only to keep spi_initialized a static variable, - * hidden from other bits of code. */ - -void spi_init_cond(void) { - if (!spi_initialized) spi_init(); -} - - -void flash_set_safe(void) { - spi_uninit(); - if (flexspi_ctrl == 0) { - pinMode(SPI_CS_PIN, INPUT); //SS - pinMode(SPI_DO_PIN, INPUT); - pinMode(SPI_DI_PIN, INPUT); - pinMode(SPI_SCK_PIN, INPUT); - }else if (flexspi_ctrl ==1){ -#if defined(ARDUINO_TEENSY41) - pinMode(SPI2_CS_PIN, INPUT); //SS - pinMode(SPI2_DO_PIN, INPUT); - pinMode(SPI2_DI_PIN, INPUT); - pinMode(SPI2_SCK_PIN, INPUT); -#elif defined(ARDUINO_TEENSY40) - pinMode(SPI1_CS_PIN, INPUT); //SS - pinMode(SPI1_DO_PIN, INPUT); - pinMode(SPI1_DI_PIN, INPUT); - pinMode(SPI1_SCK_PIN, INPUT); -#endif - } -} - -void flash_select_protocol(uint8_t allowed_protocols) { - (void)allowed_protocols; -} - -void flash_spiop(uint32_t s, uint32_t r) { - spi_spiop(s,r); -} - - -/* These can be functions if it makes sense, but these compile to so few instructions. */ -void spi_select(void) { - if (flexspi_ctrl == 0) { - digitalWrite(SPI_CS_PIN, LOW); - -#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) - }else if (flexspi_ctrl ==1){ -#if defined(ARDUINO_TEENSY41) - digitalWrite(SPI2_CS_PIN, LOW); -#elif defined(ARDUINO_TEENSY40) - digitalWrite(SPI1_CS_PIN, LOW); -#endif -#endif - - } -} -/* delay because slow pullup. */ -void spi_deselect(void) { - if (flexspi_ctrl == 0) { - digitalWrite(SPI_CS_PIN, HIGH); -#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) - }else if (flexspi_ctrl ==1){ -#if defined(ARDUINO_TEENSY41) - digitalWrite(SPI2_CS_PIN, HIGH); -#elif defined(ARDUINO_TEENSY40) - digitalWrite(SPI1_CS_PIN, HIGH); -#endif -#endif - } - - -} - -/* Select and deselect are not part of the "domain" of this .c / target-specific */ diff --git a/teensy/lib/libfrser/src/spihw_teensyspi.h b/teensy/lib/libfrser/src/spihw_teensyspi.h deleted file mode 100644 index d366719..0000000 --- a/teensy/lib/libfrser/src/spihw_teensyspi.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _SPIHW_TEENSYSPI_H_ -#define _SPIHW_TEENSYSPI_H_ -/* This will give spi_set_speed if needed. A bit illogically maybe, but anyways... */ -#include "frser-flashapi.h" -#include -#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) -#define SPI_CS_PIN 10 -#define SPI_DO_PIN 11 -#define SPI_DI_PIN 12 -#define SPI_SCK_PIN 13 -#else -#define SPI_CS_PIN 15 -#define SPI_DO_PIN 11 -#define SPI_DI_PIN 12 -#define SPI_SCK_PIN 14 - -#endif - -#if defined(ARDUINO_TEENSY40) -#define SPI1_CS_PIN 28 -#define SPI1_DO_PIN 26 -#define SPI1_DI_PIN 1 -#define SPI1_SCK_PIN 27 -#elif defined(ARDUINO_TEENSY41) -#define SPI2_CS_PIN 51 -#define SPI2_DO_PIN 50 -#define SPI2_DI_PIN 54 -#define SPI2_SCK_PIN 49 -#endif - - -void spi_init(void); -uint8_t spi_uninit(void); -uint8_t spi_txrx(const uint8_t c); - -void spi_set_port(int spi_port); -//#define FRSER_ASYNC_SPI_API -//void spi_awrite_fast(uint8_t d); -//void spi_awrite(uint8_t d); -//uint8_t spi_aread(void); - -/* Async SPI API: - * write_fast: assumes SPI idle*, starts a transfer - * write: will wait for space (or use a FIFO if available) - * read: returns the byte associated with the last write_fast / write (=will wait for transfer complete). - * - * *SPI is idle after spi_read / spi_txrx / spi_init. - * Do NOT: - * write* + write_fast - * (no write)/read + read - * - those undefined actions can lead to anything, including infinite loop/reset/undefined TX value/things appearing to work. - * Note: spi_txrx is allowed to be write_fast + read. thus do not write* + spi_txrx. - */ - -void spi_init_cond(void); - - -/* These can be functions if it makes sense, but these compile to so few instructions. */ -void spi_select(void); -/* delay because slow pullup. */ -void spi_deselect(void); - - -#endif diff --git a/teensy/lib/libfrser/src/spilib.cpp b/teensy/lib/libfrser/src/spilib.cpp deleted file mode 100644 index a3be42c..0000000 --- a/teensy/lib/libfrser/src/spilib.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2015 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "main.h" -#include "spilib.h" -#include "uart.h" - -/* This is just hardware-independent generic code to help with spi. */ - -static void spi_localop_start(uint8_t sbytes, const uint8_t* sarr) { - uint8_t i; - spi_select(); - for(i=0;i> 4)) & 0xf; - val = (val ^ (val >> 2)) & 0x3; - return (val ^ (val >> 1)) & 0x1; -} - -uint8_t spi_probe_rdid(uint8_t *id) { - const uint8_t out[1] = { 0x9F }; - uint8_t in[3]; - spi_localop(1,out,3,in); - if (!oddparity(in[0])) return 0; - if ((in[0] == 0xFF)&&(in[1] == 0xFF)&&(in[2] == 0xFF)) return 0; - if ((in[0] == 0)&&(in[1] == 0)&&(in[2] == 0)) return 0; - if (id) memcpy(id,in,3); - return 1; -} - -uint8_t spi_probe_rems(uint8_t *id) { - const uint8_t out[4] = { 0x90, 0, 0, 0 }; - uint8_t in[2]; - spi_localop(4,out,2,in); - if ((in[0] == 0xFF)&&(in[1] == 0xFF)) return 0; - if ((in[0] == 0)&&(in[1] == 0)) return 0; - if (id) memcpy(id,in,2); - return 1; -} - -uint8_t spi_probe_res(uint8_t *id) { - const uint8_t out[4] = { 0xAB, 0, 0, 0 }; - uint8_t in[1]; - spi_localop(4,out,1,in); - if (in[0] == 0xFF) return 0; - if (in[0] == 0) return 0; - if (id) *id = in[0]; - return 1; -} - -uint8_t spi_test(void) { - spi_init(); - if (spi_probe_rdid(NULL)) return 1; - if (spi_probe_rems(NULL)) return 1; - if (spi_probe_res(NULL)) return 1; - spi_uninit(); - return 0; -} - -uint8_t spi_read(uint32_t addr) { - uint8_t sarr[4]; - uint8_t rarrv; - sarr[0] = 0x03; /* Read */ - sarr[1] = (addr>>16)&0xFF; - sarr[2] = (addr>> 8)&0xFF; - sarr[3] = (addr )&0xFF; - spi_localop(4,sarr,1,&rarrv); - return rarrv; -} - -void spi_readn(uint32_t addr, uint32_t len) { - uint8_t sarr[4]; - sarr[0] = 0x03; - sarr[1] = (addr>>16)&0xFF; - sarr[2] = (addr>> 8)&0xFF; - sarr[3] = (addr )&0xFF; - spi_localop_start(4,sarr); - spi_spiop_end(len); -} diff --git a/teensy/lib/libfrser/src/spilib.h b/teensy/lib/libfrser/src/spilib.h deleted file mode 100644 index 5b4fdc5..0000000 --- a/teensy/lib/libfrser/src/spilib.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2009,2015 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _SPILIB_H_ -#define _SPILIB_H_ - -/* These are the things in spilib.c (generic helpers) */ -uint8_t spi_test(void); -uint8_t spi_read(uint32_t addr); -void spi_readn(uint32_t addr, uint32_t len); -void spi_spiop(uint32_t sbytes, uint32_t rbytes); -uint8_t spi_probe_rdid(uint8_t *id); -uint8_t spi_probe_rems(uint8_t *id); -uint8_t spi_probe_res(uint8_t *id); - -/* This includes all the hardware-specific functions, - * to be provided by target. */ -#include "spihw.h" - -/* The name is spilib.h instead of spi.h - * in order not to clash with "host" spi.h if this - * code is not used in the app. */ - -#endif diff --git a/teensy/lib/libfrser/src/typeu.h b/teensy/lib/libfrser/src/typeu.h deleted file mode 100644 index 229c791..0000000 --- a/teensy/lib/libfrser/src/typeu.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _TYPEU_H_ -#define _TYPEU_H_ - -typedef union u32u { - uint32_t l; - uint8_t b[4]; -} u32_u; - -typedef union u16u { - uint16_t l; - uint8_t b[2]; -} u16_u; - -#endif diff --git a/teensy/lib/libfrser/src/uart.h b/teensy/lib/libfrser/src/uart.h deleted file mode 100644 index 017f05e..0000000 --- a/teensy/lib/libfrser/src/uart.h +++ /dev/null @@ -1,27 +0,0 @@ -/* This is an example for what frser.c requires from an uart.h */ - -#ifndef _UART_H_ -#define _UART_H_ -#include -#if defined(ARDUINO_TEENSY31) || defined(ARDUINO_TEENSY36) -#include -#endif -/* These function names can be any, but to show the types. */ -//uint8_t uart_recv(void); -//void uart_send(uint8_t val); -/* ------- */ - -/* ifdef FRSER_FEAT_UART_TIMEOUT */ -//void uart_set_timeout(jmp_buf *buf); -/* endif */ - -/* These defines are what is really used: */ -#define BAUD 115200 - -#define RECEIVE() SerialUSB2.read() -#define SEND(n) SerialUSB2.write(n) -#define ISDATA() SerialUSB2.available() -#define UART_BUFLEN 1280 -#define UARTTX_BUFLEN 0 - -#endif diff --git a/teensy/lib/libfrser/src/uart.h.example b/teensy/lib/libfrser/src/uart.h.example deleted file mode 100644 index b40f94b..0000000 --- a/teensy/lib/libfrser/src/uart.h.example +++ /dev/null @@ -1,23 +0,0 @@ -/* This is an example for what frser.c requires from an uart.h */ - -#ifndef _UART_H_ -#define _UART_H_ - -/* These function names can be any, but to show the types. */ -uint8_t uart_recv(void); -void uart_send(uint8_t val); -/* ------- */ - -/* ifdef FRSER_FEAT_UART_TIMEOUT */ -void uart_set_timeout(jmp_buf *buf); -/* endif */ - -/* These defines are what is really used: */ -#define BAUD 115200 - -#define RECEIVE() uart_recv() -#define SEND(n) uart_send(n) -#define UART_BUFLEN 1280 -#define UARTTX_BUFLEN 0 - -#endif diff --git a/teensy/lib/libfrser/src/udelay.cpp b/teensy/lib/libfrser/src/udelay.cpp deleted file mode 100644 index 01b91c4..0000000 --- a/teensy/lib/libfrser/src/udelay.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2009 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "main.h" - -void udelay(uint32_t usecs) __attribute__((weak)); -void udelay(uint32_t usecs) { - if (usecs < 16) { - uint8_t i=usecs; - do { delayMicroseconds(1); } while(--i); - return; - } - usecs >>= 4; // div 16; - do { delayMicroseconds(16); } while(--usecs); - return; -} diff --git a/teensy/lib/libfrser/src/udelay.h b/teensy/lib/libfrser/src/udelay.h deleted file mode 100644 index 82bee58..0000000 --- a/teensy/lib/libfrser/src/udelay.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is part of the libfrser project. - * - * Copyright (C) 2009 Urja Rannikko - * - * 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 of the License, 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; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -void udelay(uint32_t usecs); diff --git a/teensy/platformio.ini b/teensy/platformio.ini deleted file mode 100644 index abb26c1..0000000 --- a/teensy/platformio.ini +++ /dev/null @@ -1,45 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:teensy31] -platform = teensy -board = teensy31 -framework = arduino -build_flags = -D USB_RAWHID_TRIPLESERIAL -upload_protocol = teensy-cli -lib_deps = majenkolibraries/CLI@^1.2.3 -lib_ignore = libflexiot4, FlexIO_t4 - -[env:teensy36] -platform = teensy -board = teensy36 -framework = arduino -build_flags = -D USB_RAWHID_TRIPLESERIAL -upload_protocol = teensy-cli -lib_deps = majenkolibraries/CLI@^1.2.3 -lib_ignore = libflexiot4, FlexIO_t4 - - -[env:teensy40] -platform = teensy -board = teensy40 -framework = arduino -build_flags = -D USB_RAWHID_TRIPLESERIAL -upload_protocol = teensy-cli -lib_deps = majenkolibraries/CLI@^1.2.3 - -[env:teensy41] -platform = teensy -board = teensy41 -framework = arduino -build_flags = -D USB_RAWHID_TRIPLESERIAL -upload_protocol = teensy-cli -lib_deps = majenkolibraries/CLI@^1.2.3 - diff --git a/teensy/src/DAP.c b/teensy/src/DAP.c deleted file mode 100644 index 72db2f9..0000000 --- a/teensy/src/DAP.c +++ /dev/null @@ -1,1795 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * Copyright 2019, Cypress Semiconductor Corporation - * or a subsidiary of Cypress Semiconductor Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - * - * 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. - * - * ---------------------------------------------------------------------- - * - * $Date: 1. December 2017 - * $Revision: V2.0.0 - * - * Project: CMSIS-DAP Source - * Title: DAP.c CMSIS-DAP Commands - * - *---------------------------------------------------------------------------*/ - -#include -#ifdef RTE_CMSIS_RTOS -#include "cmsis_os.h" -#endif -#include "DAP_config.h" -#include "DAP.h" -//#include "info.h" -#include "dap_strings.h" - - -#if (DAP_PACKET_SIZE < 64U) -#error "Minimum Packet Size is 64!" -#endif -#if (DAP_PACKET_SIZE > 32768U) -#error "Maximum Packet Size is 32768!" -#endif -#if (DAP_PACKET_COUNT < 1U) -#error "Minimum Packet Count is 1!" -#endif -#if (DAP_PACKET_COUNT > 255U) -#error "Maximum Packet Count is 255!" -#endif - - -// Clock Macros - -#define MAX_SWJ_CLOCK(delay_cycles) \ - ((CPU_CLOCK/2U) / (IO_PORT_WRITE_CYCLES + delay_cycles)) - -#define CLOCK_DELAY(swj_clock) \ - (((CPU_CLOCK/2U) / swj_clock) - IO_PORT_WRITE_CYCLES) - - - DAP_Data_t DAP_Data; // DAP Data -volatile uint8_t DAP_TransferAbort; // Transfer Abort Flag - - -// static const char DAP_FW_Ver [] = DAP_FW_VER; - -#if TARGET_DEVICE_FIXED -static const char TargetDeviceVendor [] = TARGET_DEVICE_VENDOR; -static const char TargetDeviceName [] = TARGET_DEVICE_NAME; -#endif - - -// Get DAP Information -// id: info identifier -// info: pointer to info data -// return: number of bytes in info data -static uint8_t DAP_Info(uint8_t id, uint8_t *info) { - uint8_t length = 0U; - - switch (id) { - case DAP_ID_VENDOR: - length = DAP_GetVendorString((char *)info); - break; - case DAP_ID_PRODUCT: - length = DAP_GetProductString((char *)info); - break; - case DAP_ID_SER_NUM: - length = DAP_GetSerNumString((char *)info); - break; - case DAP_ID_FW_VER: { -// --- begin DAPLink change --- - length = DAP_GetFirmwareVersionString((char *)info); -// Original: -// memcpy(info, DAP_FW_Ver, sizeof(DAP_FW_Ver)); -// length = (uint8_t)sizeof(DAP_FW_Ver); -// --- end DAPLink change --- - break; - } - case DAP_ID_DEVICE_VENDOR: -#if TARGET_DEVICE_FIXED - length = (uint8_t)sizeof(TargetDeviceVendor); - memcpy(info, TargetDeviceVendor, length); -#endif - break; - case DAP_ID_DEVICE_NAME: -#if TARGET_DEVICE_FIXED - length = (uint8_t)sizeof(TargetDeviceName); - memcpy(info, TargetDeviceName, length); -#endif - break; - case DAP_ID_CAPABILITIES: - info[0] = ((DAP_SWD != 0) ? (1U << 0) : 0U) | - ((DAP_JTAG != 0) ? (1U << 1) : 0U) | - ((SWO_UART != 0) ? (1U << 2) : 0U) | - ((SWO_MANCHESTER != 0) ? (1U << 3) : 0U) | - /* Atomic Commands */ (1U << 4) | - ((TIMESTAMP_CLOCK != 0U) ? (1U << 5) : 0U) | - ((SWO_STREAM != 0U) ? (1U << 6) : 0U); - length = 1U; - break; - case DAP_ID_TIMESTAMP_CLOCK: -#if (TIMESTAMP_CLOCK != 0U) - info[0] = (uint8_t)(TIMESTAMP_CLOCK >> 0); - info[1] = (uint8_t)(TIMESTAMP_CLOCK >> 8); - info[2] = (uint8_t)(TIMESTAMP_CLOCK >> 16); - info[3] = (uint8_t)(TIMESTAMP_CLOCK >> 24); - length = 4U; -#endif - break; - case DAP_ID_SWO_BUFFER_SIZE: -#if ((SWO_UART != 0) || (SWO_MANCHESTER != 0)) - info[0] = (uint8_t)(SWO_BUFFER_SIZE >> 0); - info[1] = (uint8_t)(SWO_BUFFER_SIZE >> 8); - info[2] = (uint8_t)(SWO_BUFFER_SIZE >> 16); - info[3] = (uint8_t)(SWO_BUFFER_SIZE >> 24); - length = 4U; -#endif - break; - case DAP_ID_PACKET_SIZE: - info[0] = (uint8_t)(DAP_PACKET_SIZE >> 0); - info[1] = (uint8_t)(DAP_PACKET_SIZE >> 8); - length = 2U; - break; - case DAP_ID_PACKET_COUNT: - info[0] = DAP_PACKET_COUNT; - length = 1U; - break; - default: - break; - } - - return (length); -} - - -// Delay for specified time -// delay: delay time in ms -void Delayms(uint32_t delay) { - delay *= ((CPU_CLOCK/1000U) + (DELAY_SLOW_CYCLES-1U)) / DELAY_SLOW_CYCLES; - PIN_DELAY_SLOW(delay); -} - - -// Process Delay command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_Delay(const uint8_t *request, uint8_t *response) { - uint32_t delay; - - delay = (uint32_t)(*(request+0)) | - (uint32_t)(*(request+1) << 8); - delay *= ((CPU_CLOCK/1000000U) + (DELAY_SLOW_CYCLES-1U)) / DELAY_SLOW_CYCLES; - - PIN_DELAY_SLOW(delay); - - *response = DAP_OK; - return ((2U << 16) | 1U); -} - - -// Process Host Status command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_HostStatus(const uint8_t *request, uint8_t *response) { - - switch (*request) { - case DAP_DEBUGGER_CONNECTED: - LED_CONNECTED_OUT((*(request+1) & 1U)); - break; - case DAP_TARGET_RUNNING: - LED_RUNNING_OUT((*(request+1) & 1U)); - break; - default: - *response = DAP_ERROR; - return ((2U << 16) | 1U); - } - - *response = DAP_OK; - return ((2U << 16) | 1U); -} - - -// Process Connect command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_Connect(const uint8_t *request, uint8_t *response) { - uint32_t port; - - if (*request == DAP_PORT_AUTODETECT) { - port = DAP_DEFAULT_PORT; - } else { - port = *request; - } - - switch (port) { -#if (DAP_SWD != 0) - case DAP_PORT_SWD: - DAP_Data.debug_port = DAP_PORT_SWD; - PORT_SWD_SETUP(); - break; -#endif -#if (DAP_JTAG != 0) - case DAP_PORT_JTAG: - DAP_Data.debug_port = DAP_PORT_JTAG; - PORT_JTAG_SETUP(); - break; -#endif - default: - port = DAP_PORT_DISABLED; - break; - } - - *response = (uint8_t)port; - return ((1U << 16) | 1U); -} - - -// Process Disconnect command and prepare response -// response: pointer to response data -// return: number of bytes in response -static uint32_t DAP_Disconnect(uint8_t *response) { - - DAP_Data.debug_port = DAP_PORT_DISABLED; - PORT_OFF(); - - *response = DAP_OK; - return (1U); -} - - -// Process Reset Target command and prepare response -// response: pointer to response data -// return: number of bytes in response -static uint32_t DAP_ResetTarget(uint8_t *response) { - - *(response+1) = RESET_TARGET(); - *(response+0) = DAP_OK; - return (2U); -} - - -// Process SWJ Pins command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_SWJ_Pins(const uint8_t *request, uint8_t *response) { -#if ((DAP_SWD != 0) || (DAP_JTAG != 0)) - uint32_t value; - uint32_t select; - uint32_t wait; - uint32_t timestamp; - - value = (uint32_t) *(request+0); - select = (uint32_t) *(request+1); - wait = (uint32_t)(*(request+2) << 0) | - (uint32_t)(*(request+3) << 8) | - (uint32_t)(*(request+4) << 16) | - (uint32_t)(*(request+5) << 24); - - if ((select & (1U << DAP_SWJ_SWCLK_TCK)) != 0U) { - if ((value & (1U << DAP_SWJ_SWCLK_TCK)) != 0U) { - PIN_SWCLK_TCK_SET(); - } else { - PIN_SWCLK_TCK_CLR(); - } - } - if ((select & (1U << DAP_SWJ_SWDIO_TMS)) != 0U) { - if ((value & (1U << DAP_SWJ_SWDIO_TMS)) != 0U) { - PIN_SWDIO_TMS_SET(); - } else { - PIN_SWDIO_TMS_CLR(); - } - } - if ((select & (1U << DAP_SWJ_TDI)) != 0U) { - PIN_TDI_OUT(value >> DAP_SWJ_TDI); - } - if ((select & (1U << DAP_SWJ_nTRST)) != 0U) { - PIN_nTRST_OUT(value >> DAP_SWJ_nTRST); - } - if ((select & (1U << DAP_SWJ_nRESET)) != 0U){ - PIN_nRESET_OUT(value >> DAP_SWJ_nRESET); - } - - if (wait != 0U) { -#if (TIMESTAMP_CLOCK != 0U) - if (wait > 3000000U) { - wait = 3000000U; - } -#if (TIMESTAMP_CLOCK >= 1000000U) - wait *= TIMESTAMP_CLOCK / 1000000U; -#else - wait /= 1000000U / TIMESTAMP_CLOCK; -#endif -#else - wait = 1U; -#endif - timestamp = TIMESTAMP_GET(); - do { - if ((select & (1U << DAP_SWJ_SWCLK_TCK)) != 0U) { - if ((value >> DAP_SWJ_SWCLK_TCK) ^ PIN_SWCLK_TCK_IN()) { - continue; - } - } - if ((select & (1U << DAP_SWJ_SWDIO_TMS)) != 0U) { - if ((value >> DAP_SWJ_SWDIO_TMS) ^ PIN_SWDIO_TMS_IN()) { - continue; - } - } - if ((select & (1U << DAP_SWJ_TDI)) != 0U) { - if ((value >> DAP_SWJ_TDI) ^ PIN_TDI_IN()) { - continue; - } - } - if ((select & (1U << DAP_SWJ_nTRST)) != 0U) { - if ((value >> DAP_SWJ_nTRST) ^ PIN_nTRST_IN()) { - continue; - } - } - if ((select & (1U << DAP_SWJ_nRESET)) != 0U) { - if ((value >> DAP_SWJ_nRESET) ^ PIN_nRESET_IN()) { - continue; - } - } - break; - } while ((TIMESTAMP_GET() - timestamp) < wait); - } - - value = (PIN_SWCLK_TCK_IN() << DAP_SWJ_SWCLK_TCK) | - (PIN_SWDIO_TMS_IN() << DAP_SWJ_SWDIO_TMS) | - (PIN_TDI_IN() << DAP_SWJ_TDI) | - (PIN_TDO_IN() << DAP_SWJ_TDO) | - (PIN_nTRST_IN() << DAP_SWJ_nTRST) | - (PIN_nRESET_IN() << DAP_SWJ_nRESET); - - *response = (uint8_t)value; -#else - *response = 0U; -#endif - - return ((6U << 16) | 1U); -} - - -// Process SWJ Clock command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_SWJ_Clock(const uint8_t *request, uint8_t *response) { -#if ((DAP_SWD != 0) || (DAP_JTAG != 0)) - uint32_t clock; - uint32_t delay; - - clock = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8) | - (uint32_t)(*(request+2) << 16) | - (uint32_t)(*(request+3) << 24); - - if (clock == 0U) { - *response = DAP_ERROR; - return ((4U << 16) | 1U); - } - - if (clock >= MAX_SWJ_CLOCK(DELAY_FAST_CYCLES)) { - DAP_Data.fast_clock = 1U; - DAP_Data.clock_delay = 1U; - } else { - DAP_Data.fast_clock = 0U; - - delay = ((CPU_CLOCK/2U) + (clock - 1U)) / clock; - if (delay > IO_PORT_WRITE_CYCLES) { - delay -= IO_PORT_WRITE_CYCLES; - delay = (delay + (DELAY_SLOW_CYCLES - 1U)) / DELAY_SLOW_CYCLES; - } else { - delay = 1U; - } - - DAP_Data.clock_delay = delay; - } - - *response = DAP_OK; -#else - *response = DAP_ERROR; -#endif - - return ((4U << 16) | 1U); -} - - -// Process SWJ Sequence command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_SWJ_Sequence(const uint8_t *request, uint8_t *response) { - uint32_t count; - - count = *request++; - if (count == 0U) { - count = 256U; - } - -#if ((DAP_SWD != 0) || (DAP_JTAG != 0)) - SWJ_Sequence(count, request); - *response = DAP_OK; -#else - *response = DAP_ERROR; -#endif - - count = (count + 7U) >> 3; - - return (((count + 1U) << 16) | 1U); -} - - -// Process SWD Configure command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_SWD_Configure(const uint8_t *request, uint8_t *response) { -#if (DAP_SWD != 0) - uint8_t value; - - value = *request; - DAP_Data.swd_conf.turnaround = (value & 0x03U) + 1U; - DAP_Data.swd_conf.data_phase = (value & 0x04U) ? 1U : 0U; - - *response = DAP_OK; -#else - *response = DAP_ERROR; -#endif - - return ((1U << 16) | 1U); -} - - -// Process SWD Sequence command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_SWD_Sequence(const uint8_t *request, uint8_t *response) { - uint32_t sequence_info; - uint32_t sequence_count; - uint32_t request_count; - uint32_t response_count; - uint32_t count; - -#if (DAP_SWD != 0) - *response++ = DAP_OK; -#else - *response++ = DAP_ERROR; -#endif - request_count = 1U; - response_count = 1U; - - sequence_count = *request++; - while (sequence_count--) { - sequence_info = *request++; - count = sequence_info & SWD_SEQUENCE_CLK; - if (count == 0U) { - count = 64U; - } - count = (count + 7U) / 8U; -#if (DAP_SWD != 0) - if ((sequence_info & SWD_SEQUENCE_DIN) != 0U) { - PIN_SWDIO_OUT_DISABLE(); - } else { - PIN_SWDIO_OUT_ENABLE(); - } - SWD_Sequence(sequence_info, request, response); - if (sequence_count == 0U) { - PIN_SWDIO_OUT_ENABLE(); - } -#endif - if ((sequence_info & SWD_SEQUENCE_DIN) != 0U) { - request_count++; -#if (DAP_SWD != 0) - response += count; - response_count += count; -#endif - } else { - request += count; - request_count += count + 1U; - } - } - - return ((request_count << 16) | response_count); -} - - -// Process JTAG Sequence command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_JTAG_Sequence(const uint8_t *request, uint8_t *response) { - uint32_t sequence_info; - uint32_t sequence_count; - uint32_t request_count; - uint32_t response_count; - uint32_t count; - -#if (DAP_JTAG != 0) - *response++ = DAP_OK; -#else - *response++ = DAP_ERROR; -#endif - request_count = 1U; - response_count = 1U; - - sequence_count = *request++; - while (sequence_count--) { - sequence_info = *request++; - count = sequence_info & JTAG_SEQUENCE_TCK; - if (count == 0U) { - count = 64U; - } - count = (count + 7U) / 8U; -#if (DAP_JTAG != 0) - JTAG_Sequence(sequence_info, request, response); -#endif - request += count; - request_count += count + 1U; -#if (DAP_JTAG != 0) - if ((sequence_info & JTAG_SEQUENCE_TDO) != 0U) { - response += count; - response_count += count; - } -#endif - } - - return ((request_count << 16) | response_count); -} - - -// Process JTAG Configure command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_JTAG_Configure(const uint8_t *request, uint8_t *response) { - uint32_t count; -#if (DAP_JTAG != 0) - uint32_t length; - uint32_t bits; - uint32_t n; - - count = *request++; - DAP_Data.jtag_dev.count = (uint8_t)count; - - bits = 0U; - for (n = 0U; n < count; n++) { - length = *request++; - DAP_Data.jtag_dev.ir_length[n] = (uint8_t)length; - DAP_Data.jtag_dev.ir_before[n] = (uint16_t)bits; - bits += length; - } - for (n = 0U; n < count; n++) { - bits -= DAP_Data.jtag_dev.ir_length[n]; - DAP_Data.jtag_dev.ir_after[n] = (uint16_t)bits; - } - - *response = DAP_OK; -#else - count = *request; - *response = DAP_ERROR; -#endif - - return (((count + 1U) << 16) | 1U); -} - - -// Process JTAG IDCODE command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_JTAG_IDCode(const uint8_t *request, uint8_t *response) { -#if (DAP_JTAG != 0) - uint32_t data; - - if (DAP_Data.debug_port != DAP_PORT_JTAG) { - goto id_error; - } - - // Device index (JTAP TAP) - DAP_Data.jtag_dev.index = *request; - if (DAP_Data.jtag_dev.index >= DAP_Data.jtag_dev.count) { - goto id_error; - } - - // Select JTAG chain - JTAG_IR(JTAG_IDCODE); - - // Read IDCODE register - data = JTAG_ReadIDCode(); - - // Store Data - *(response+0) = DAP_OK; - *(response+1) = (uint8_t)(data >> 0); - *(response+2) = (uint8_t)(data >> 8); - *(response+3) = (uint8_t)(data >> 16); - *(response+4) = (uint8_t)(data >> 24); - - return ((1U << 16) | 5U); - -id_error: -#endif - *response = DAP_ERROR; - return ((1U << 16) | 1U); -} - - -// Process Transfer Configure command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_TransferConfigure(const uint8_t *request, uint8_t *response) { - - DAP_Data.transfer.idle_cycles = *(request+0); - DAP_Data.transfer.retry_count = (uint16_t) *(request+1) | - (uint16_t)(*(request+2) << 8); - DAP_Data.transfer.match_retry = (uint16_t) *(request+3) | - (uint16_t)(*(request+4) << 8); - - *response = DAP_OK; - return ((5U << 16) | 1U); -} - - -// Process SWD Transfer command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -#if (DAP_SWD != 0) -static uint32_t DAP_SWD_Transfer(const uint8_t *request, uint8_t *response) { - const - uint8_t *request_head; - uint32_t request_count; - uint32_t request_value; - uint8_t *response_head; - uint32_t response_count; - uint32_t response_value; - uint32_t post_read; - uint32_t check_write; - uint32_t match_value; - uint32_t match_retry; - uint32_t retry; - uint32_t data; -#if (TIMESTAMP_CLOCK != 0U) - uint32_t timestamp; -#endif - - request_head = request; - - response_count = 0U; - response_value = 0U; - response_head = response; - response += 2; - - DAP_TransferAbort = 0U; - - post_read = 0U; - check_write = 0U; - - request++; // Ignore DAP index - - request_count = *request++; - - for (; request_count != 0U; request_count--) { - request_value = *request++; - if ((request_value & DAP_TRANSFER_RnW) != 0U) { - // Read register - if (post_read) { - // Read was posted before - retry = DAP_Data.transfer.retry_count; - if ((request_value & (DAP_TRANSFER_APnDP | DAP_TRANSFER_MATCH_VALUE)) == DAP_TRANSFER_APnDP) { - // Read previous AP data and post next AP read - do { - response_value = SWD_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - } else { - // Read previous AP data - do { - response_value = SWD_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - post_read = 0U; - } - if (response_value != DAP_TRANSFER_OK) { - break; - } - // Store previous AP data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); -#if (TIMESTAMP_CLOCK != 0U) - if (post_read) { - // Store Timestamp of next AP read - if ((request_value & DAP_TRANSFER_TIMESTAMP) != 0U) { - timestamp = DAP_Data.timestamp; - *response++ = (uint8_t) timestamp; - *response++ = (uint8_t)(timestamp >> 8); - *response++ = (uint8_t)(timestamp >> 16); - *response++ = (uint8_t)(timestamp >> 24); - } - } -#endif - } - if ((request_value & DAP_TRANSFER_MATCH_VALUE) != 0U) { - // Read with value match - match_value = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8) | - (uint32_t)(*(request+2) << 16) | - (uint32_t)(*(request+3) << 24); - request += 4; - match_retry = DAP_Data.transfer.match_retry; - if ((request_value & DAP_TRANSFER_APnDP) != 0U) { - // Post AP read - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(request_value, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } - } - do { - // Read register until its value matches or retry counter expires - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } - } while (((data & DAP_Data.transfer.match_mask) != match_value) && match_retry-- && !DAP_TransferAbort); - if ((data & DAP_Data.transfer.match_mask) != match_value) { - response_value |= DAP_TRANSFER_MISMATCH; - } - if (response_value != DAP_TRANSFER_OK) { - break; - } - } else { - // Normal read - retry = DAP_Data.transfer.retry_count; - if ((request_value & DAP_TRANSFER_APnDP) != 0U) { - // Read AP register - if (post_read == 0U) { - // Post AP read - do { - response_value = SWD_Transfer(request_value, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } -#if (TIMESTAMP_CLOCK != 0U) - // Store Timestamp - if ((request_value & DAP_TRANSFER_TIMESTAMP) != 0U) { - timestamp = DAP_Data.timestamp; - *response++ = (uint8_t) timestamp; - *response++ = (uint8_t)(timestamp >> 8); - *response++ = (uint8_t)(timestamp >> 16); - *response++ = (uint8_t)(timestamp >> 24); - } -#endif - post_read = 1U; - } - } else { - // Read DP register - do { - response_value = SWD_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } -#if (TIMESTAMP_CLOCK != 0U) - // Store Timestamp - if ((request_value & DAP_TRANSFER_TIMESTAMP) != 0U) { - timestamp = DAP_Data.timestamp; - *response++ = (uint8_t) timestamp; - *response++ = (uint8_t)(timestamp >> 8); - *response++ = (uint8_t)(timestamp >> 16); - *response++ = (uint8_t)(timestamp >> 24); - } -#endif - // Store data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); - } - } - check_write = 0U; - } else { - // Write register - if (post_read) { - // Read previous data - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } - // Store previous data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); - post_read = 0U; - } - // Load data - data = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8) | - (uint32_t)(*(request+2) << 16) | - (uint32_t)(*(request+3) << 24); - request += 4; - if ((request_value & DAP_TRANSFER_MATCH_MASK) != 0U) { - // Write match mask - DAP_Data.transfer.match_mask = data; - response_value = DAP_TRANSFER_OK; - } else { - // Write DP/AP register - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } -#if (TIMESTAMP_CLOCK != 0U) - // Store Timestamp - if ((request_value & DAP_TRANSFER_TIMESTAMP) != 0U) { - timestamp = DAP_Data.timestamp; - *response++ = (uint8_t) timestamp; - *response++ = (uint8_t)(timestamp >> 8); - *response++ = (uint8_t)(timestamp >> 16); - *response++ = (uint8_t)(timestamp >> 24); - } -#endif - check_write = 1U; - } - } - response_count++; - if (DAP_TransferAbort) { - break; - } - } - - for (; request_count != 0U; request_count--) { - // Process canceled requests - request_value = *request++; - if ((request_value & DAP_TRANSFER_RnW) != 0U) { - // Read register - if ((request_value & DAP_TRANSFER_MATCH_VALUE) != 0U) { - // Read with value match - request += 4; - } - } else { - // Write register - request += 4; - } - } - - if (response_value == DAP_TRANSFER_OK) { - if (post_read) { - // Read previous data - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - // Store previous data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); - } else if (check_write) { - // Check last write - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - } - } - -end: - *(response_head+0) = (uint8_t)response_count; - *(response_head+1) = (uint8_t)response_value; - - return (((uint32_t)(request - request_head) << 16) | (uint32_t)(response - response_head)); -} -#endif - - -// Process JTAG Transfer command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -#if (DAP_JTAG != 0) -static uint32_t DAP_JTAG_Transfer(const uint8_t *request, uint8_t *response) { - const - uint8_t *request_head; - uint32_t request_count; - uint32_t request_value; - uint32_t request_ir; - uint8_t *response_head; - uint32_t response_count; - uint32_t response_value; - uint32_t post_read; - uint32_t match_value; - uint32_t match_retry; - uint32_t retry; - uint32_t data; - uint32_t ir; -#if (TIMESTAMP_CLOCK != 0U) - uint32_t timestamp; -#endif - - request_head = request; - - response_count = 0U; - response_value = 0U; - response_head = response; - response += 2; - - DAP_TransferAbort = 0U; - - ir = 0U; - post_read = 0U; - - // Device index (JTAP TAP) - DAP_Data.jtag_dev.index = *request++; - if (DAP_Data.jtag_dev.index >= DAP_Data.jtag_dev.count) { - goto end; - } - - request_count = *request++; - - for (; request_count != 0U; request_count--) { - request_value = *request++; - request_ir = (request_value & DAP_TRANSFER_APnDP) ? JTAG_APACC : JTAG_DPACC; - if ((request_value & DAP_TRANSFER_RnW) != 0U) { - // Read register - if (post_read) { - // Read was posted before - retry = DAP_Data.transfer.retry_count; - if ((ir == request_ir) && ((request_value & DAP_TRANSFER_MATCH_VALUE) == 0U)) { - // Read previous data and post next read - do { - response_value = JTAG_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - } else { - // Select JTAG chain - if (ir != JTAG_DPACC) { - ir = JTAG_DPACC; - JTAG_IR(ir); - } - // Read previous data - do { - response_value = JTAG_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - post_read = 0U; - } - if (response_value != DAP_TRANSFER_OK) { - break; - } - // Store previous data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); -#if (TIMESTAMP_CLOCK != 0U) - if (post_read) { - // Store Timestamp of next AP read - if ((request_value & DAP_TRANSFER_TIMESTAMP) != 0U) { - timestamp = DAP_Data.timestamp; - *response++ = (uint8_t) timestamp; - *response++ = (uint8_t)(timestamp >> 8); - *response++ = (uint8_t)(timestamp >> 16); - *response++ = (uint8_t)(timestamp >> 24); - } - } -#endif - } - if ((request_value & DAP_TRANSFER_MATCH_VALUE) != 0U) { - // Read with value match - match_value = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8) | - (uint32_t)(*(request+2) << 16) | - (uint32_t)(*(request+3) << 24); - request += 4; - match_retry = DAP_Data.transfer.match_retry; - // Select JTAG chain - if (ir != request_ir) { - ir = request_ir; - JTAG_IR(ir); - } - // Post DP/AP read - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(request_value, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } - do { - // Read register until its value matches or retry counter expires - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } - } while (((data & DAP_Data.transfer.match_mask) != match_value) && match_retry-- && !DAP_TransferAbort); - if ((data & DAP_Data.transfer.match_mask) != match_value) { - response_value |= DAP_TRANSFER_MISMATCH; - } - if (response_value != DAP_TRANSFER_OK) { - break; - } - } else { - // Normal read - if (post_read == 0U) { - // Select JTAG chain - if (ir != request_ir) { - ir = request_ir; - JTAG_IR(ir); - } - // Post DP/AP read - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(request_value, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } -#if (TIMESTAMP_CLOCK != 0U) - // Store Timestamp - if ((request_value & DAP_TRANSFER_TIMESTAMP) != 0U) { - timestamp = DAP_Data.timestamp; - *response++ = (uint8_t) timestamp; - *response++ = (uint8_t)(timestamp >> 8); - *response++ = (uint8_t)(timestamp >> 16); - *response++ = (uint8_t)(timestamp >> 24); - } -#endif - post_read = 1U; - } - } - } else { - // Write register - if (post_read) { - // Select JTAG chain - if (ir != JTAG_DPACC) { - ir = JTAG_DPACC; - JTAG_IR(ir); - } - // Read previous data - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } - // Store previous data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); - post_read = 0U; - } - // Load data - data = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8) | - (uint32_t)(*(request+2) << 16) | - (uint32_t)(*(request+3) << 24); - request += 4; - if ((request_value & DAP_TRANSFER_MATCH_MASK) != 0U) { - // Write match mask - DAP_Data.transfer.match_mask = data; - response_value = DAP_TRANSFER_OK; - } else { - // Select JTAG chain - if (ir != request_ir) { - ir = request_ir; - JTAG_IR(ir); - } - // Write DP/AP register - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - break; - } -#if (TIMESTAMP_CLOCK != 0U) - // Store Timestamp - if ((request_value & DAP_TRANSFER_TIMESTAMP) != 0U) { - timestamp = DAP_Data.timestamp; - *response++ = (uint8_t) timestamp; - *response++ = (uint8_t)(timestamp >> 8); - *response++ = (uint8_t)(timestamp >> 16); - *response++ = (uint8_t)(timestamp >> 24); - } -#endif - } - } - response_count++; - if (DAP_TransferAbort) { - break; - } - } - - for (; request_count != 0U; request_count--) { - // Process canceled requests - request_value = *request++; - if ((request_value & DAP_TRANSFER_RnW) != 0U) { - // Read register - if ((request_value & DAP_TRANSFER_MATCH_VALUE) != 0U) { - // Read with value match - request += 4; - } - } else { - // Write register - request += 4; - } - } - - if (response_value == DAP_TRANSFER_OK) { - // Select JTAG chain - if (ir != JTAG_DPACC) { - ir = JTAG_DPACC; - JTAG_IR(ir); - } - if (post_read) { - // Read previous data - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - // Store previous data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); - } else { - // Check last write - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - } - } - -end: - *(response_head+0) = (uint8_t)response_count; - *(response_head+1) = (uint8_t)response_value; - - return (((uint32_t)(request - request_head) << 16) | (uint32_t)(response - response_head)); -} -#endif - - -// Process Dummy Transfer command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_Dummy_Transfer(const uint8_t *request, uint8_t *response) { - const - uint8_t *request_head; - uint32_t request_count; - uint32_t request_value; - - request_head = request; - - request++; // Ignore DAP index - - request_count = *request++; - - for (; request_count != 0U; request_count--) { - // Process dummy requests - request_value = *request++; - if ((request_value & DAP_TRANSFER_RnW) != 0U) { - // Read register - if ((request_value & DAP_TRANSFER_MATCH_VALUE) != 0U) { - // Read with value match - request += 4; - } - } else { - // Write register - request += 4; - } - } - - *(response+0) = 0U; // Response count - *(response+1) = 0U; // Response value - - return (((uint32_t)(request - request_head) << 16) | 2U); -} - - -// Process Transfer command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_Transfer(const uint8_t *request, uint8_t *response) { - uint32_t num; - - switch (DAP_Data.debug_port) { -#if (DAP_SWD != 0) - case DAP_PORT_SWD: - num = DAP_SWD_Transfer(request, response); - break; -#endif -#if (DAP_JTAG != 0) - case DAP_PORT_JTAG: - num = DAP_JTAG_Transfer(request, response); - break; -#endif - default: - num = DAP_Dummy_Transfer(request, response); - break; - } - - return (num); -} - - -// Process SWD Transfer Block command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response -#if (DAP_SWD != 0) -static uint32_t DAP_SWD_TransferBlock(const uint8_t *request, uint8_t *response) { - uint32_t request_count; - uint32_t request_value; - uint32_t response_count; - uint32_t response_value; - uint8_t *response_head; - uint32_t retry; - uint32_t data; - - response_count = 0U; - response_value = 0U; - response_head = response; - response += 3; - - DAP_TransferAbort = 0U; - - request++; // Ignore DAP index - - request_count = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8); - request += 2; - if (request_count == 0U) { - goto end; - } - - request_value = *request++; - if ((request_value & DAP_TRANSFER_RnW) != 0U) { - // Read register block - if ((request_value & DAP_TRANSFER_APnDP) != 0U) { - // Post AP read - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(request_value, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - } - while (request_count--) { - // Read DP/AP register - if ((request_count == 0U) && ((request_value & DAP_TRANSFER_APnDP) != 0U)) { - // Last AP read - request_value = DP_RDBUFF | DAP_TRANSFER_RnW; - } - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - // Store data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); - response_count++; - } - } else { - // Write register block - while (request_count--) { - // Load data - data = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8) | - (uint32_t)(*(request+2) << 16) | - (uint32_t)(*(request+3) << 24); - request += 4; - // Write DP/AP register - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - response_count++; - } - // Check last write - retry = DAP_Data.transfer.retry_count; - do { - response_value = SWD_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - } - -end: - *(response_head+0) = (uint8_t)(response_count >> 0); - *(response_head+1) = (uint8_t)(response_count >> 8); - *(response_head+2) = (uint8_t) response_value; - - return ((uint32_t)(response - response_head)); -} -#endif - - -// Process JTAG Transfer Block command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response -#if (DAP_JTAG != 0) -static uint32_t DAP_JTAG_TransferBlock(const uint8_t *request, uint8_t *response) { - uint32_t request_count; - uint32_t request_value; - uint32_t response_count; - uint32_t response_value; - uint8_t *response_head; - uint32_t retry; - uint32_t data; - uint32_t ir; - - response_count = 0U; - response_value = 0U; - response_head = response; - response += 3; - - DAP_TransferAbort = 0U; - - // Device index (JTAP TAP) - DAP_Data.jtag_dev.index = *request++; - if (DAP_Data.jtag_dev.index >= DAP_Data.jtag_dev.count) { - goto end; - } - - request_count = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8); - request += 2; - if (request_count == 0U) { - goto end; - } - - request_value = *request++; - - // Select JTAG chain - ir = (request_value & DAP_TRANSFER_APnDP) ? JTAG_APACC : JTAG_DPACC; - JTAG_IR(ir); - - if ((request_value & DAP_TRANSFER_RnW) != 0U) { - // Post read - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(request_value, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - // Read register block - while (request_count--) { - // Read DP/AP register - if (request_count == 0U) { - // Last read - if (ir != JTAG_DPACC) { - JTAG_IR(JTAG_DPACC); - } - request_value = DP_RDBUFF | DAP_TRANSFER_RnW; - } - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - // Store data - *response++ = (uint8_t) data; - *response++ = (uint8_t)(data >> 8); - *response++ = (uint8_t)(data >> 16); - *response++ = (uint8_t)(data >> 24); - response_count++; - } - } else { - // Write register block - while (request_count--) { - // Load data - data = (uint32_t)(*(request+0) << 0) | - (uint32_t)(*(request+1) << 8) | - (uint32_t)(*(request+2) << 16) | - (uint32_t)(*(request+3) << 24); - request += 4; - // Write DP/AP register - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(request_value, &data); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - if (response_value != DAP_TRANSFER_OK) { - goto end; - } - response_count++; - } - // Check last write - if (ir != JTAG_DPACC) { - JTAG_IR(JTAG_DPACC); - } - retry = DAP_Data.transfer.retry_count; - do { - response_value = JTAG_Transfer(DP_RDBUFF | DAP_TRANSFER_RnW, NULL); - } while ((response_value == DAP_TRANSFER_WAIT) && retry-- && !DAP_TransferAbort); - } - -end: - *(response_head+0) = (uint8_t)(response_count >> 0); - *(response_head+1) = (uint8_t)(response_count >> 8); - *(response_head+2) = (uint8_t) response_value; - - return ((uint32_t)(response - response_head)); -} -#endif - - -// Process Transfer Block command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_TransferBlock(const uint8_t *request, uint8_t *response) { - uint32_t num; - - switch (DAP_Data.debug_port) { -#if (DAP_SWD != 0) - case DAP_PORT_SWD: - num = DAP_SWD_TransferBlock (request, response); - break; -#endif -#if (DAP_JTAG != 0) - case DAP_PORT_JTAG: - num = DAP_JTAG_TransferBlock(request, response); - break; -#endif - default: - *(response+0) = 0U; // Response count [7:0] - *(response+1) = 0U; // Response count[15:8] - *(response+2) = 0U; // Response value - num = 3U; - break; - } - - if ((*(request+3) & DAP_TRANSFER_RnW) != 0U) { - // Read register block - num |= 4U << 16; - } else { - // Write register block - num |= (4U + (((uint32_t)(*(request+1)) | (uint32_t)(*(request+2) << 8)) * 4)) << 16; - } - - return (num); -} - - -// Process SWD Write ABORT command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response -#if (DAP_SWD != 0) -static uint32_t DAP_SWD_WriteAbort(const uint8_t *request, uint8_t *response) { - uint32_t data; - - // Load data (Ignore DAP index) - data = (uint32_t)(*(request+1) << 0) | - (uint32_t)(*(request+2) << 8) | - (uint32_t)(*(request+3) << 16) | - (uint32_t)(*(request+4) << 24); - - // Write Abort register - SWD_Transfer(DP_ABORT, &data); - - *response = DAP_OK; - return (1U); -} -#endif - - -// Process JTAG Write ABORT command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response -#if (DAP_JTAG != 0) -static uint32_t DAP_JTAG_WriteAbort(const uint8_t *request, uint8_t *response) { - uint32_t data; - - // Device index (JTAP TAP) - DAP_Data.jtag_dev.index = *request; - if (DAP_Data.jtag_dev.index >= DAP_Data.jtag_dev.count) { - *response = DAP_ERROR; - return (1U); - } - - // Select JTAG chain - JTAG_IR(JTAG_ABORT); - - // Load data - data = (uint32_t)(*(request+1) << 0) | - (uint32_t)(*(request+2) << 8) | - (uint32_t)(*(request+3) << 16) | - (uint32_t)(*(request+4) << 24); - - // Write Abort register - JTAG_WriteAbort(data); - - *response = DAP_OK; - return (1U); -} -#endif - - -// Process Write ABORT command and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -static uint32_t DAP_WriteAbort(const uint8_t *request, uint8_t *response) { - uint32_t num; - - switch (DAP_Data.debug_port) { -#if (DAP_SWD != 0) - case DAP_PORT_SWD: - num = DAP_SWD_WriteAbort (request, response); - break; -#endif -#if (DAP_JTAG != 0) - case DAP_PORT_JTAG: - num = DAP_JTAG_WriteAbort(request, response); - break; -#endif - default: - *response = DAP_ERROR; - num = 1U; - break; - } - return ((5U << 16) | num); -} - - -// Process DAP Vendor command request and prepare response -// Default function (can be overridden) -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -__weak uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { - (void)request; - *response = ID_DAP_Invalid; - return ((1U << 16) | 1U); -} - -// Process DAP Vendor extended command request and prepare response -// Default function (can be overridden) -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -__weak uint32_t DAP_ProcessVendorCommandEx(const uint8_t *request, uint8_t *response) { - *response = ID_DAP_Invalid; - return ((1U << 16) | 1U); -} - -// Process DAP command request and prepare response -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -uint32_t DAP_ProcessCommand(const uint8_t *request, uint8_t *response) { - uint32_t num; - - if ((*request >= ID_DAP_Vendor0) && (*request <= ID_DAP_Vendor31)) { - return DAP_ProcessVendorCommand(request, response); - } - - if ((*request >= ID_DAP_VendorExFirst) && (*request <= ID_DAP_VendorExLast)) { - return DAP_ProcessVendorCommandEx(request, response); - } - - *response++ = *request; - - switch (*request++) { - case ID_DAP_Info: - num = DAP_Info(*request, response+1); - *response = (uint8_t)num; - return ((2U << 16) + 2U + num); - - case ID_DAP_HostStatus: - num = DAP_HostStatus(request, response); - break; - - case ID_DAP_Connect: - num = DAP_Connect(request, response); - break; - case ID_DAP_Disconnect: - num = DAP_Disconnect(response); - break; - - case ID_DAP_Delay: - num = DAP_Delay(request, response); - break; - - case ID_DAP_ResetTarget: - num = DAP_ResetTarget(response); - break; - - case ID_DAP_SWJ_Pins: - num = DAP_SWJ_Pins(request, response); - break; - case ID_DAP_SWJ_Clock: - num = DAP_SWJ_Clock(request, response); - break; - case ID_DAP_SWJ_Sequence: - num = DAP_SWJ_Sequence(request, response); - break; - - case ID_DAP_SWD_Configure: - num = DAP_SWD_Configure(request, response); - break; - case ID_DAP_SWD_Sequence: - num = DAP_SWD_Sequence(request, response); - break; - - case ID_DAP_JTAG_Sequence: - num = DAP_JTAG_Sequence(request, response); - break; - case ID_DAP_JTAG_Configure: - num = DAP_JTAG_Configure(request, response); - break; - case ID_DAP_JTAG_IDCODE: - num = DAP_JTAG_IDCode(request, response); - break; - - case ID_DAP_TransferConfigure: - num = DAP_TransferConfigure(request, response); - break; - case ID_DAP_Transfer: - num = DAP_Transfer(request, response); - break; - case ID_DAP_TransferBlock: - num = DAP_TransferBlock(request, response); - break; - - case ID_DAP_WriteABORT: - num = DAP_WriteAbort(request, response); - break; - -#if ((SWO_UART != 0) || (SWO_MANCHESTER != 0)) - case ID_DAP_SWO_Transport: - num = SWO_Transport(request, response); - break; - case ID_DAP_SWO_Mode: - num = SWO_Mode(request, response); - break; - case ID_DAP_SWO_Baudrate: - num = SWO_Baudrate(request, response); - break; - case ID_DAP_SWO_Control: - num = SWO_Control(request, response); - break; - case ID_DAP_SWO_Status: - num = SWO_Status(response); - break; - case ID_DAP_SWO_ExtendedStatus: - num = SWO_ExtendedStatus(request, response); - break; - case ID_DAP_SWO_Data: - num = SWO_Data(request, response); - break; -#endif - - default: - *(response-1) = ID_DAP_Invalid; - return ((1U << 16) | 1U); - } - - return ((1U << 16) + 1U + num); -} - - -// Execute DAP command (process request and prepare response) -// request: pointer to request data -// response: pointer to response data -// return: number of bytes in response (lower 16 bits) -// number of bytes in request (upper 16 bits) -uint32_t DAP_ExecuteCommand(const uint8_t *request, uint8_t *response) { - uint32_t cnt, num, n; - - if (*request == ID_DAP_ExecuteCommands) { - *response++ = *request++; - cnt = *request++; - *response++ = (uint8_t)cnt; - num = (2U << 16) | 2U; - while (cnt--) { - n = DAP_ProcessCommand(request, response); - num += n; - request += (uint16_t)(n >> 16); - response += (uint16_t) n; - } - return (num); - } - - return DAP_ProcessCommand(request, response); -} - - -// Setup DAP -void DAP_Setup(void) { - - // Default settings - DAP_Data.debug_port = 0U; - DAP_Data.fast_clock = 0U; - DAP_Data.clock_delay = CLOCK_DELAY(DAP_DEFAULT_SWJ_CLOCK); - DAP_Data.transfer.idle_cycles = 0U; - DAP_Data.transfer.retry_count = 100U; - DAP_Data.transfer.match_retry = 0U; - DAP_Data.transfer.match_mask = 0x00000000U; -#if (DAP_SWD != 0) - DAP_Data.swd_conf.turnaround = 1U; - DAP_Data.swd_conf.data_phase = 0U; -#endif -#if (DAP_JTAG != 0) - DAP_Data.jtag_dev.count = 0U; -#endif - - DAP_SETUP(); // Device specific setup -} diff --git a/teensy/src/DAP.h b/teensy/src/DAP.h deleted file mode 100644 index 0615c1e..0000000 --- a/teensy/src/DAP.h +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Copyright (c) 2013-2019 ARM Limited. All rights reserved. - * Copyright 2019, Cypress Semiconductor Corporation - * or a subsidiary of Cypress Semiconductor Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - * - * 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. - * - * ---------------------------------------------------------------------- - * - * $Date: 26. November 2019 - * $Revision: V2.0.0 - * - * Project: CMSIS-DAP Include - * Title: DAP.h Definitions - * - *---------------------------------------------------------------------------*/ - -#ifndef __DAP_H__ -#define __DAP_H__ - - -// DAP Firmware Version -#ifdef DAP_FW_V1 -#define DAP_FW_VER "1.2.0" -#else -#define DAP_FW_VER "2.0.0" -#endif - -// DAP Command IDs -#define ID_DAP_Info 0x00U -#define ID_DAP_HostStatus 0x01U -#define ID_DAP_Connect 0x02U -#define ID_DAP_Disconnect 0x03U -#define ID_DAP_TransferConfigure 0x04U -#define ID_DAP_Transfer 0x05U -#define ID_DAP_TransferBlock 0x06U -#define ID_DAP_TransferAbort 0x07U -#define ID_DAP_WriteABORT 0x08U -#define ID_DAP_Delay 0x09U -#define ID_DAP_ResetTarget 0x0AU -#define ID_DAP_SWJ_Pins 0x10U -#define ID_DAP_SWJ_Clock 0x11U -#define ID_DAP_SWJ_Sequence 0x12U -#define ID_DAP_SWD_Configure 0x13U -#define ID_DAP_SWD_Sequence 0x1DU -#define ID_DAP_JTAG_Sequence 0x14U -#define ID_DAP_JTAG_Configure 0x15U -#define ID_DAP_JTAG_IDCODE 0x16U -#define ID_DAP_SWO_Transport 0x17U -#define ID_DAP_SWO_Mode 0x18U -#define ID_DAP_SWO_Baudrate 0x19U -#define ID_DAP_SWO_Control 0x1AU -#define ID_DAP_SWO_Status 0x1BU -#define ID_DAP_SWO_ExtendedStatus 0x1EU -#define ID_DAP_SWO_Data 0x1CU - -#define ID_DAP_QueueCommands 0x7EU -#define ID_DAP_ExecuteCommands 0x7FU - -// DAP Vendor Command IDs -#define ID_DAP_Vendor0 0x80U -#define ID_DAP_Vendor1 0x81U -#define ID_DAP_Vendor2 0x82U -#define ID_DAP_Vendor3 0x83U -#define ID_DAP_Vendor4 0x84U -#define ID_DAP_Vendor5 0x85U -#define ID_DAP_Vendor6 0x86U -#define ID_DAP_Vendor7 0x87U -#define ID_DAP_Vendor8 0x88U -#define ID_DAP_Vendor9 0x89U -#define ID_DAP_Vendor10 0x8AU -#define ID_DAP_Vendor11 0x8BU -#define ID_DAP_Vendor12 0x8CU -#define ID_DAP_Vendor13 0x8DU -#define ID_DAP_Vendor14 0x8EU -#define ID_DAP_Vendor15 0x8FU -#define ID_DAP_Vendor16 0x90U -#define ID_DAP_Vendor17 0x91U -#define ID_DAP_Vendor18 0x92U -#define ID_DAP_Vendor19 0x93U -#define ID_DAP_Vendor20 0x94U -#define ID_DAP_Vendor21 0x95U -#define ID_DAP_Vendor22 0x96U -#define ID_DAP_Vendor23 0x97U -#define ID_DAP_Vendor24 0x98U -#define ID_DAP_Vendor25 0x99U -#define ID_DAP_Vendor26 0x9AU -#define ID_DAP_Vendor27 0x9BU -#define ID_DAP_Vendor28 0x9CU -#define ID_DAP_Vendor29 0x9DU -#define ID_DAP_Vendor30 0x9EU -#define ID_DAP_Vendor31 0x9FU - -// DAP Extended range of Vendor Command IDs - -#define ID_DAP_VendorExFirst 0xA0U -#define ID_DAP_VendorExLast 0xFEU - -#define ID_DAP_Invalid 0xFFU - -// DAP Status Code -#define DAP_OK 0U -#define DAP_ERROR 0xFFU - -// DAP ID -#define DAP_ID_VENDOR 1U -#define DAP_ID_PRODUCT 2U -#define DAP_ID_SER_NUM 3U -#define DAP_ID_FW_VER 4U -#define DAP_ID_DEVICE_VENDOR 5U -#define DAP_ID_DEVICE_NAME 6U -#define DAP_ID_CAPABILITIES 0xF0U -#define DAP_ID_TIMESTAMP_CLOCK 0xF1U -#define DAP_ID_SWO_BUFFER_SIZE 0xFDU -#define DAP_ID_PACKET_COUNT 0xFEU -#define DAP_ID_PACKET_SIZE 0xFFU - -// DAP Host Status -#define DAP_DEBUGGER_CONNECTED 0U -#define DAP_TARGET_RUNNING 1U - -// DAP Port -#define DAP_PORT_AUTODETECT 0U // Autodetect Port -#define DAP_PORT_DISABLED 0U // Port Disabled (I/O pins in High-Z) -#define DAP_PORT_SWD 1U // SWD Port (SWCLK, SWDIO) + nRESET -#define DAP_PORT_JTAG 2U // JTAG Port (TCK, TMS, TDI, TDO, nTRST) + nRESET - -// DAP SWJ Pins -#define DAP_SWJ_SWCLK_TCK 0 // SWCLK/TCK -#define DAP_SWJ_SWDIO_TMS 1 // SWDIO/TMS -#define DAP_SWJ_TDI 2 // TDI -#define DAP_SWJ_TDO 3 // TDO -#define DAP_SWJ_nTRST 5 // nTRST -#define DAP_SWJ_nRESET 7 // nRESET - -// DAP Transfer Request -#define DAP_TRANSFER_APnDP (1U<<0) -#define DAP_TRANSFER_RnW (1U<<1) -#define DAP_TRANSFER_A2 (1U<<2) -#define DAP_TRANSFER_A3 (1U<<3) -#define DAP_TRANSFER_MATCH_VALUE (1U<<4) -#define DAP_TRANSFER_MATCH_MASK (1U<<5) -#define DAP_TRANSFER_TIMESTAMP (1U<<7) - -// DAP Transfer Response -#define DAP_TRANSFER_OK (1U<<0) -#define DAP_TRANSFER_WAIT (1U<<1) -#define DAP_TRANSFER_FAULT (1U<<2) -#define DAP_TRANSFER_ERROR (1U<<3) -#define DAP_TRANSFER_MISMATCH (1U<<4) - -// DAP SWO Trace Mode -#define DAP_SWO_OFF 0U -#define DAP_SWO_UART 1U -#define DAP_SWO_MANCHESTER 2U - -// DAP SWO Trace Status -#define DAP_SWO_CAPTURE_ACTIVE (1U<<0) -#define DAP_SWO_CAPTURE_PAUSED (1U<<1) -#define DAP_SWO_STREAM_ERROR (1U<<6) -#define DAP_SWO_BUFFER_OVERRUN (1U<<7) - - -// Debug Port Register Addresses -#define DP_IDCODE 0x00U // IDCODE Register (SW Read only) -#define DP_ABORT 0x00U // Abort Register (SW Write only) -#define DP_CTRL_STAT 0x04U // Control & Status -#define DP_WCR 0x04U // Wire Control Register (SW Only) -#define DP_SELECT 0x08U // Select Register (JTAG R/W & SW W) -#define DP_RESEND 0x08U // Resend (SW Read Only) -#define DP_RDBUFF 0x0CU // Read Buffer (Read Only) - -// JTAG IR Codes -#define JTAG_ABORT 0x08U -#define JTAG_DPACC 0x0AU -#define JTAG_APACC 0x0BU -#define JTAG_IDCODE 0x0EU -#define JTAG_BYPASS 0x0FU - -// JTAG Sequence Info -#define JTAG_SEQUENCE_TCK 0x3FU // TCK count -#define JTAG_SEQUENCE_TMS 0x40U // TMS value -#define JTAG_SEQUENCE_TDO 0x80U // TDO capture - -// SWD Sequence Info -#define SWD_SEQUENCE_CLK 0x3FU // SWCLK count -#define SWD_SEQUENCE_DIN 0x80U // SWDIO capture - - -#include -#include - -// DAP Data structure -typedef struct { - uint8_t debug_port; // Debug Port - uint8_t fast_clock; // Fast Clock Flag - uint8_t padding[2]; - uint32_t clock_delay; // Clock Delay - uint32_t timestamp; // Last captured Timestamp - struct { // Transfer Configuration - uint8_t idle_cycles; // Idle cycles after transfer - uint8_t padding[3]; - uint16_t retry_count; // Number of retries after WAIT response - uint16_t match_retry; // Number of retries if read value does not match - uint32_t match_mask; // Match Mask - } transfer; -#if (DAP_SWD != 0) - struct { // SWD Configuration - uint8_t turnaround; // Turnaround period - uint8_t data_phase; // Always generate Data Phase - } swd_conf; -#endif -#if (DAP_JTAG != 0) - struct { // JTAG Device Chain - uint8_t count; // Number of devices - uint8_t index; // Device index (device at TDO has index 0) -#if (DAP_JTAG_DEV_CNT != 0) - uint8_t ir_length[DAP_JTAG_DEV_CNT]; // IR Length in bits - uint16_t ir_before[DAP_JTAG_DEV_CNT]; // Bits before IR - uint16_t ir_after [DAP_JTAG_DEV_CNT]; // Bits after IR -#endif - } jtag_dev; -#endif -} DAP_Data_t; - -extern DAP_Data_t DAP_Data; // DAP Data -extern volatile uint8_t DAP_TransferAbort; // Transfer Abort Flag - - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Functions -extern void SWJ_Sequence (uint32_t count, const uint8_t *data); -extern void SWD_Sequence (uint32_t info, const uint8_t *swdo, uint8_t *swdi); -extern void JTAG_Sequence (uint32_t info, const uint8_t *tdi, uint8_t *tdo); -extern void JTAG_IR (uint32_t ir); -extern uint32_t JTAG_ReadIDCode (void); -extern void JTAG_WriteAbort (uint32_t data); -extern uint8_t JTAG_Transfer (uint32_t request, uint32_t *data); -extern uint8_t SWD_Transfer (uint32_t request, uint32_t *data); - -extern void Delayms (uint32_t delay); - -extern uint32_t SWO_Transport (const uint8_t *request, uint8_t *response); -extern uint32_t SWO_Mode (const uint8_t *request, uint8_t *response); -extern uint32_t SWO_Baudrate (const uint8_t *request, uint8_t *response); -extern uint32_t SWO_Control (const uint8_t *request, uint8_t *response); -extern uint32_t SWO_Status (uint8_t *response); -extern uint32_t SWO_ExtendedStatus (const uint8_t *request, uint8_t *response); -extern uint32_t SWO_Data (const uint8_t *request, uint8_t *response); - -extern void SWO_QueueTransfer (uint8_t *buf, uint32_t num); -extern void SWO_AbortTransfer (void); -extern void SWO_TransferComplete (void); - -extern uint32_t UART_SWO_Mode (uint32_t enable); -extern uint32_t UART_SWO_Baudrate (uint32_t baudrate); -extern uint32_t UART_SWO_Control (uint32_t active); -extern void UART_SWO_Capture (uint8_t *buf, uint32_t num); -extern uint32_t UART_SWO_GetCount (void); - -extern uint32_t Manchester_SWO_Mode (uint32_t enable); -extern uint32_t Manchester_SWO_Baudrate (uint32_t baudrate); -extern uint32_t Manchester_SWO_Control (uint32_t active); -extern void Manchester_SWO_Capture (uint8_t *buf, uint32_t num); -extern uint32_t Manchester_SWO_GetCount (void); - -extern uint32_t DAP_ProcessVendorCommand (const uint8_t *request, uint8_t *response); -extern uint32_t DAP_ProcessCommand (const uint8_t *request, uint8_t *response); -extern uint32_t DAP_ExecuteCommand (const uint8_t *request, uint8_t *response); - -extern void DAP_Setup (void); - -// Configurable delay for clock generation -#ifndef DELAY_SLOW_CYCLES -#define DELAY_SLOW_CYCLES 3U // Number of cycles for one iteration -#endif -#if defined(__CC_ARM) -static __inline void PIN_DELAY_SLOW (uint32_t delay) { - uint32_t count = delay; - while (--count); -} -#else -static __inline void PIN_DELAY_SLOW (uint32_t delay) { - __asm__ volatile ( - ".syntax unified\n" - "0:\n\t" - "subs %0,%0,#1\n\t" - "bne 0b\n" - : "+l" (delay) : : "cc" - ); -} -#endif - -// Fixed delay for fast clock generation -#ifndef DELAY_FAST_CYCLES -#define DELAY_FAST_CYCLES 0U // Number of cycles: 0..3 -#endif -static __inline void PIN_DELAY_FAST (void) { -#if (DELAY_FAST_CYCLES >= 1U) - __NOP(); -#endif -#if (DELAY_FAST_CYCLES >= 2U) - __NOP(); -#endif -#if (DELAY_FAST_CYCLES >= 3U) - __NOP(); -#endif -} - -#ifdef __cplusplus -} -#endif - - -#endif /* __DAP_H__ */ diff --git a/teensy/src/DAP_config.h b/teensy/src/DAP_config.h deleted file mode 100644 index 0acf0de..0000000 --- a/teensy/src/DAP_config.h +++ /dev/null @@ -1,465 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - * - * 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. - * - * ---------------------------------------------------------------------- - * - * $Date: 1. December 2017 - * $Revision: V2.0.0 - * - * Project: CMSIS-DAP Configuration - * Title: DAP_config.h CMSIS-DAP Configuration File (Template) - * - *---------------------------------------------------------------------------*/ - -#ifndef __DAP_CONFIG_H__ -#define __DAP_CONFIG_H__ -#include // Debug Unit Cortex-M Processor Header File - -#include "IO_Config.h" - -#define __weak __attribute__ ((weak)) - -//************************************************************************************************** -/** -\defgroup DAP_Config_Debug_gr CMSIS-DAP Debug Unit Information -\ingroup DAP_ConfigIO_gr -@{ -Provides definitions about the hardware and configuration of the Debug Unit. - -This information includes: - - Definition of Cortex-M processor parameters used in CMSIS-DAP Debug Unit. - - Debug Unit Identification strings (Vendor, Product, Serial Number). - - Debug Unit communication packet size. - - Debug Access Port supported modes and settings (JTAG/SWD and SWO). - - Optional information about a connected Target Device (for Evaluation Boards). -*/ - -/// Processor Clock of the Cortex-M MCU used in the Debug Unit. -/// This value is used to calculate the SWD/JTAG clock speed. -#define CPU_CLOCK F_CPU ///< Specifies the CPU Clock in Hz. - -/// Number of processor cycles for I/O Port write operations. -/// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O -/// Port write operations in the Debug Unit by a Cortex-M MCU. Most Cortex-M processors -/// require 2 processor cycles for a I/O Port Write operation. If the Debug Unit uses -/// a Cortex-M0+ processor with high-speed peripheral I/O only 1 processor cycle might be -/// required. -#define IO_PORT_WRITE_CYCLES 2U ///< I/O Cycles: 2=default, 1=Cortex-M0+ fast I/0. - -/// Indicate that Serial Wire Debug (SWD) communication mode is available at the Debug Access Port. -/// This information is returned by the command \ref DAP_Info as part of Capabilities. -#define DAP_SWD 1 ///< SWD Mode: 1 = available, 0 = not available. - -/// Indicate that JTAG communication mode is available at the Debug Port. -/// This information is returned by the command \ref DAP_Info as part of Capabilities. -#define DAP_JTAG 0 ///< JTAG Mode: 1 = available, 0 = not available. - -/// Configure maximum number of JTAG devices on the scan chain connected to the Debug Access Port. -/// This setting impacts the RAM requirements of the Debug Unit. Valid range is 1 .. 255. -#define DAP_JTAG_DEV_CNT 0 ///< Maximum number of JTAG devices on scan chain. - -/// Default communication mode on the Debug Access Port. -/// Used for the command \ref DAP_Connect when Port Default mode is selected. -#define DAP_DEFAULT_PORT 1U ///< Default JTAG/SWJ Port Mode: 1 = SWD, 2 = JTAG. - -/// Default communication speed on the Debug Access Port for SWD and JTAG mode. -/// Used to initialize the default SWD/JTAG clock frequency. -/// The command \ref DAP_SWJ_Clock can be used to overwrite this default setting. -#define DAP_DEFAULT_SWJ_CLOCK 1000000U ///< Default SWD/JTAG clock frequency in Hz. - -/// Maximum Package Size for Command and Response data. -/// This configuration settings is used to optimize the communication performance with the -/// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB, -/// 1024 for High-speed USB HID and 512 for High-speed USB WinUSB. -#define DAP_PACKET_SIZE 64U ///< Specifies Packet Size in bytes. - -/// Maximum Package Buffers for Command and Response data. -/// This configuration settings is used to optimize the communication performance with the -/// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the -/// setting can be reduced (valid range is 1 .. 255). -#define DAP_PACKET_COUNT 5U ///< Specifies number of packets buffered. - -/// Indicate that UART Serial Wire Output (SWO) trace is available. -/// This information is returned by the command \ref DAP_Info as part of Capabilities. -#define SWO_UART 0 ///< SWO UART: 1 = available, 0 = not available. - -/// Maximum SWO UART Baudrate. -#define SWO_UART_MAX_BAUDRATE 10000000U ///< SWO UART Maximum Baudrate in Hz. - -/// Indicate that Manchester Serial Wire Output (SWO) trace is available. -/// This information is returned by the command \ref DAP_Info as part of Capabilities. -#define SWO_MANCHESTER 0 ///< SWO Manchester: 1 = available, 0 = not available. - -/// SWO Trace Buffer Size. -#define SWO_BUFFER_SIZE 4096U ///< SWO Trace Buffer Size in bytes (must be 2^n). - -/// SWO Streaming Trace. -#define SWO_STREAM 0 ///< SWO Streaming Trace: 1 = available, 0 = not available. - -/// Clock frequency of the Test Domain Timer. Timer value is returned with \ref TIMESTAMP_GET. -#define TIMESTAMP_CLOCK 1000000U ///< Timestamp clock in Hz (0 = timestamps not supported). - -/// Debug Unit is connected to fixed Target Device. -/// The Debug Unit may be part of an evaluation board and always connected to a fixed -/// known device. In this case a Device Vendor and Device Name string is stored which -/// may be used by the debugger or IDE to configure device parameters. -#define TARGET_DEVICE_FIXED 0 ///< Target Device: 1 = known, 0 = unknown; - -#if TARGET_DEVICE_FIXED -#define TARGET_DEVICE_VENDOR "" ///< String indicating the Silicon Vendor -#define TARGET_DEVICE_NAME "" ///< String indicating the Target Device -#endif - -///@} - - -//************************************************************************************************** -/** -\defgroup DAP_Config_PortIO_gr CMSIS-DAP Hardware I/O Pin Access -\ingroup DAP_ConfigIO_gr -@{ - -Standard I/O Pins of the CMSIS-DAP Hardware Debug Port support standard JTAG mode -and Serial Wire Debug (SWD) mode. In SWD mode only 2 pins are required to implement the debug -interface of a device. The following I/O Pins are provided: - -JTAG I/O Pin | SWD I/O Pin | CMSIS-DAP Hardware pin mode ----------------------------- | -------------------- | --------------------------------------------- -TCK: Test Clock | SWCLK: Clock | Output Push/Pull -TMS: Test Mode Select | SWDIO: Data I/O | Output Push/Pull; Input (for receiving data) -TDI: Test Data Input | | Output Push/Pull -TDO: Test Data Output | | Input -nTRST: Test Reset (optional) | | Output Open Drain with pull-up resistor -nRESET: Device Reset | nRESET: Device Reset | Output Open Drain with pull-up resistor - - -DAP Hardware I/O Pin Access Functions -------------------------------------- -The various I/O Pins are accessed by functions that implement the Read, Write, Set, or Clear to -these I/O Pins. - -For the SWDIO I/O Pin there are additional functions that are called in SWD I/O mode only. -This functions are provided to achieve faster I/O that is possible with some advanced GPIO -peripherals that can independently write/read a single I/O pin without affecting any other pins -of the same I/O port. The following SWDIO I/O Pin functions are provided: - - \ref PIN_SWDIO_OUT_ENABLE to enable the output mode from the DAP hardware. - - \ref PIN_SWDIO_OUT_DISABLE to enable the input mode to the DAP hardware. - - \ref PIN_SWDIO_IN to read from the SWDIO I/O pin with utmost possible speed. - - \ref PIN_SWDIO_OUT to write to the SWDIO I/O pin with utmost possible speed. -*/ - - -// Configure DAP I/O pins ------------------------------ - -/** Setup JTAG I/O pins: TCK, TMS, TDI, TDO, nTRST, and nRESET. -Configures the DAP Hardware I/O pins for JTAG mode: - - TCK, TMS, TDI, nTRST, nRESET to output mode and set to high level. - - TDO to input mode. -*/ -static __inline void PORT_JTAG_SETUP (void) { - pinMode(pin_swclk, OUTPUT); - pinMode(pin_swdio, OUTPUT); - pinMode(pin_nreset, OUTPUT_OPENDRAIN); - pinMode(pin_tdi, OUTPUT); - pinMode(pin_tdo, INPUT); -} - -/** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET. -Configures the DAP Hardware I/O pins for Serial Wire Debug (SWD) mode: - - SWCLK, SWDIO, nRESET to output mode and set to default high level. - - TDI, TMS, nTRST to HighZ mode (pins are unused in SWD mode). -*/ -static __inline void PORT_SWD_SETUP(void) -{ - pinMode(pin_swclk, OUTPUT); - pinMode(pin_swdio, OUTPUT); - pinMode(pin_nreset, OUTPUT_OPENDRAIN); - pinMode(pin_tdi, INPUT); - pinMode(pin_tdo, INPUT); -} - -/** Disable JTAG/SWD I/O Pins. -Disables the DAP Hardware I/O pins which configures: - - TCK/SWCLK, TMS/SWDIO, TDI, TDO, nTRST, nRESET to High-Z mode. -*/ -static __inline void PORT_OFF(void) -{ - pinMode(pin_swclk, INPUT); - pinMode(pin_swdio, INPUT); - pinMode(pin_nreset, INPUT); - pinMode(pin_tdo, INPUT); - pinMode(pin_nreset, INPUT); -} - - -// SWCLK/TCK I/O pin ------------------------------------- - -/** SWCLK/TCK I/O pin: Get Input. -\return Current status of the SWCLK/TCK DAP hardware I/O pin. -*/ -static __inline uint32_t PIN_SWCLK_TCK_IN (void) { - return (digitalRead(pin_swclk) == HIGH) ? 1 : 0; -} - -/** SWCLK/TCK I/O pin: Set Output to High. -Set the SWCLK/TCK DAP hardware I/O pin to high level. -*/ -static __inline void PIN_SWCLK_TCK_SET(void) -{ - digitalWrite(pin_swclk, HIGH); -} - -/** SWCLK/TCK I/O pin: Set Output to Low. -Set the SWCLK/TCK DAP hardware I/O pin to low level. -*/ -static __inline void PIN_SWCLK_TCK_CLR(void) -{ - digitalWrite(pin_swclk, LOW); -} - - -// SWDIO/TMS Pin I/O -------------------------------------- - -/** SWDIO/TMS I/O pin: Get Input. -\return Current status of the SWDIO/TMS DAP hardware I/O pin. -*/ -static __inline uint32_t PIN_SWDIO_TMS_IN(void) -{ - return (digitalRead(pin_swdio) == HIGH) ? 1 : 0; -} - -/** SWDIO/TMS I/O pin: Set Output to High. -Set the SWDIO/TMS DAP hardware I/O pin to high level. -*/ -static __inline void PIN_SWDIO_TMS_SET(void) -{ - digitalWrite(pin_swdio, HIGH); -} - -/** SWDIO/TMS I/O pin: Set Output to Low. -Set the SWDIO/TMS DAP hardware I/O pin to low level. -*/ -static __inline void PIN_SWDIO_TMS_CLR(void) -{ - digitalWrite(pin_swdio, LOW); -} - -/** SWDIO I/O pin: Get Input (used in SWD mode only). -\return Current status of the SWDIO DAP hardware I/O pin. -*/ -static __inline uint32_t PIN_SWDIO_IN(void) -{ - return (digitalRead(pin_swdio) == HIGH) ? 1 : 0; -} - -/** SWDIO I/O pin: Set Output (used in SWD mode only). -\param bit Output value for the SWDIO DAP hardware I/O pin. -*/ -static __inline void PIN_SWDIO_OUT(uint32_t bit) -{ - digitalWrite(pin_swdio, (bit & 1) ? HIGH : LOW); -} - -/** SWDIO I/O pin: Switch to Output mode (used in SWD mode only). -Configure the SWDIO DAP hardware I/O pin to output mode. This function is -called prior \ref PIN_SWDIO_OUT function calls. -*/ -static __inline void PIN_SWDIO_OUT_ENABLE(void) -{ - pinMode(pin_swdio, OUTPUT); -} - -/** SWDIO I/O pin: Switch to Input mode (used in SWD mode only). -Configure the SWDIO DAP hardware I/O pin to input mode. This function is -called prior \ref PIN_SWDIO_IN function calls. -*/ -static __inline void PIN_SWDIO_OUT_DISABLE(void) -{ - pinMode(pin_swdio, INPUT_PULLUP); -} - - -// TDI Pin I/O --------------------------------------------- - -/** TDI I/O pin: Get Input. -\return Current status of the TDI DAP hardware I/O pin. -*/ -static __inline uint32_t PIN_TDI_IN (void) { - return (digitalRead(pin_tdi) == HIGH) ? 1 : 0; -} - -/** TDI I/O pin: Set Output. -\param bit Output value for the TDI DAP hardware I/O pin. -*/ -static __inline void PIN_TDI_OUT (uint32_t bit) { - digitalWrite(pin_tdi, (bit & 1) ? HIGH : LOW); -} - - -// TDO Pin I/O --------------------------------------------- - -/** TDO I/O pin: Get Input. -\return Current status of the TDO DAP hardware I/O pin. -*/ -static __inline uint32_t PIN_TDO_IN (void) { - return (digitalRead(pin_tdo) == HIGH) ? 1 : 0; -} - - -// nTRST Pin I/O ------------------------------------------- - -/** nTRST I/O pin: Get Input. -\return Current status of the nTRST DAP hardware I/O pin. -*/ -static __inline uint32_t PIN_nTRST_IN (void) { - return (0U); -} - -/** nTRST I/O pin: Set Output. -\param bit JTAG TRST Test Reset pin status: - - 0: issue a JTAG TRST Test Reset. - - 1: release JTAG TRST Test Reset. -*/ -static __inline void PIN_nTRST_OUT (uint32_t bit) { - ; -} - -// nRESET Pin I/O------------------------------------------ - -/** nRESET I/O pin: Get Input. -\return Current status of the nRESET DAP hardware I/O pin. -*/ -static __inline uint32_t PIN_nRESET_IN(void) -{ - return (digitalRead(pin_nreset) == HIGH) ? 1 : 0; -} - -/** nRESET I/O pin: Set Output. -\param bit target device hardware reset pin status: - - 0: issue a device hardware reset. - - 1: release device hardware reset. -*/ -static __inline void PIN_nRESET_OUT(uint32_t bit) -{ - digitalWrite(pin_nreset, (bit & 1) ? HIGH : LOW); -} - -///@} - - -//************************************************************************************************** -/** -\defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs -\ingroup DAP_ConfigIO_gr -@{ - -CMSIS-DAP Hardware may provide LEDs that indicate the status of the CMSIS-DAP Debug Unit. - -It is recommended to provide the following LEDs for status indication: - - Connect LED: is active when the DAP hardware is connected to a debugger. - - Running LED: is active when the debugger has put the target device into running state. -*/ - -/** Debug Unit: Set status of Connected LED. -\param bit status of the Connect LED. - - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit. - - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit. -*/ -static __inline void LED_CONNECTED_OUT(uint32_t bit) -{ - digitalWrite(pin_led_connected, bit ? HIGH : LOW); -} - -/** Debug Unit: Set status Target Running LED. -\param bit status of the Target Running LED. - - 1: Target Running LED ON: program execution in target started. - - 0: Target Running LED OFF: program execution in target stopped. -*/ -static __inline void LED_RUNNING_OUT (uint32_t bit) { - digitalWrite(pin_led_running, bit ? HIGH : LOW); -} - -///@} - - -//************************************************************************************************** -/** -\defgroup DAP_Config_Timestamp_gr CMSIS-DAP Timestamp -\ingroup DAP_ConfigIO_gr -@{ -Access function for Test Domain Timer. - -The value of the Test Domain Timer in the Debug Unit is returned by the function \ref TIMESTAMP_GET. By -default, the DWT timer is used. The frequency of this timer is configured with \ref TIMESTAMP_CLOCK. - -*/ - -/** Get timestamp of Test Domain Timer. -\return Current timestamp value. -*/ -static __inline uint32_t TIMESTAMP_GET (void) { - return (ARM_DWT_CYCCNT) / (CPU_CLOCK / TIMESTAMP_CLOCK); -} - -///@} - - -//************************************************************************************************** -/** -\defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization -\ingroup DAP_ConfigIO_gr -@{ - -CMSIS-DAP Hardware I/O and LED Pins are initialized with the function \ref DAP_SETUP. -*/ - -/** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized). -This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the -Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set: - - I/O clock system enabled. - - all I/O pins: input buffer enabled, output pins are set to HighZ mode. - - for nTRST, nRESET a weak pull-up (if available) is enabled. - - LED output pins are enabled and LEDs are turned off. -*/ -static __inline void DAP_SETUP(void) -{ - pinMode(pin_swclk, INPUT); - pinMode(pin_swdio, INPUT); - pinMode(pin_nreset, INPUT); - pinMode(pin_tdi, INPUT); - pinMode(pin_tdo, INPUT); - pinMode(pin_led_connected, OUTPUT); - LED_CONNECTED_OUT(0); - pinMode(pin_led_running, OUTPUT); - LED_RUNNING_OUT(0); -} - -/** Reset Target Device with custom specific I/O pin or command sequence. -This function allows the optional implementation of a device specific reset sequence. -It is called when the command \ref DAP_ResetTarget and is for example required -when a device needs a time-critical unlock sequence that enables the debug port. -\return 0 = no device specific reset sequence is implemented.\n - 1 = a device specific reset sequence is implemented. -*/ -static __inline uint8_t RESET_TARGET (void) { - return (0U); // change to '1' when a device reset sequence is implemented -} - -///@} - - -#endif /* __DAP_CONFIG_H__ */ diff --git a/teensy/src/DAP_vendor.c b/teensy/src/DAP_vendor.c deleted file mode 100644 index bcef4d1..0000000 --- a/teensy/src/DAP_vendor.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2013-2016 ARM Limited. All rights reserved. - * Copyright 2019, Cypress Semiconductor Corporation - * or a subsidiary of Cypress Semiconductor Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - * - * 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. - * - * ---------------------------------------------------------------------- - * - * $Date: 20. May 2015 - * $Revision: V1.10 - * - * Project: CMSIS-DAP Source - * Title: DAP_vendor.c CMSIS-DAP Vendor Commands - * - *---------------------------------------------------------------------------*/ - -//#include "rl_usb.h" -#include "DAP_config.h" -#include "DAP.h" -//#include "info.h" -//#include "main.h" -#include "uart.h" -//#include "settings.h" -//#include "target_family.h" -//#include "flash_manager.h" -#include - - -#ifdef DRAG_N_DROP_SUPPORT -#include "file_stream.h" -#endif - -//************************************************************************************************** -/** -\defgroup DAP_Vendor_Adapt_gr Adapt Vendor Commands -\ingroup DAP_Vendor_gr -@{ - -The file DAP_vendor.c provides template source code for extension of a Debug Unit with -Vendor Commands. Copy this file to the project folder of the Debug Unit and add the -file to the MDK-ARM project under the file group Configuration. -*/ - -/** Process DAP Vendor Command and prepare Response Data -\param request pointer to request data -\param response pointer to response data -\return number of bytes in response (lower 16 bits) - number of bytes in request (upper 16 bits) -*/ -uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { - uint32_t num = (1U << 16) | 1U; - - *response++ = *request; // copy Command ID - - switch (*request++) { // first byte in request is Command ID - /* - case ID_DAP_Vendor0: { - const char *id_str = info_get_unique_id(); - uint8_t len = strlen(id_str); - *response++ = len; - memcpy(response, id_str, len); - num += (len + 1); // increment response count by ID length + length byte - break; - } - case ID_DAP_Vendor1: { - // get line coding - int32_t read_len = sizeof(CDC_LINE_CODING); - CDC_LINE_CODING cdc_line_coding; - USBD_CDC_ACM_PortGetLineCoding(&cdc_line_coding); - memcpy(response, &cdc_line_coding, read_len); - num += (read_len + 1); - break; - } - case ID_DAP_Vendor2: { - // set uart configuration - CDC_LINE_CODING cdc_line_coding; - USBD_CDC_ACM_PortGetLineCoding(&cdc_line_coding); - //set BaudRate - uint32_t baud_rate = 0; - memcpy(&baud_rate, request, sizeof(uint32_t)); - cdc_line_coding.dwDTERate = baud_rate; - USBD_CDC_ACM_PortSetLineCoding(&cdc_line_coding); - USBD_CDC_ACM_SendBreak(0); - *response = 1; - num += (sizeof(uint32_t) << 16) | 1; - break; - } - case ID_DAP_Vendor3: { - // uart read - int32_t read_len = 62; - read_len = uart_read_data(response + 1, read_len); - response[0] = read_len; - // increment request and response count - num += (read_len + 1); - break; - } - case ID_DAP_Vendor4: { - // uart write - int32_t write_len = *request; - request++; - uart_write_data((uint8_t *)request, write_len); - *response = 1; - num += ((write_len + 1) << 16) | 1; - break; - } - case ID_DAP_Vendor5: break; - case ID_DAP_Vendor6: break; - case ID_DAP_Vendor7: break; - case ID_DAP_Vendor8: { - *response = 1; - if (0 == *request) { - main_usb_set_test_mode(false); - } else if (1 == *request) { - main_usb_set_test_mode(true); - } else { - *response = 0; - } - num += (1U << 16) | 1U; // increment request and response count each by 1 - break; - } - case ID_DAP_Vendor9: { - // reset target - *response = 1; - if (!config_get_auto_rst()) { - target_set_state(RESET_RUN); - } - num += 1; - break; - } -#ifdef DRAG_N_DROP_SUPPORT - case ID_DAP_Vendor10: { - // open mass storage device stream - *response = stream_open((stream_type_t)(*request)); - num += (1 << 16) | 1; - break; - } - case ID_DAP_Vendor11: { - // close mass storage device stream - *response = stream_close(); - num += 1; - break; - } - case ID_DAP_Vendor12: { - // write to mass storage device - uint32_t write_len = *request; - request++; - *response = stream_write((uint8_t *)request, write_len); - num += ((write_len + 1) << 16) | 1; - break; - } -#endif - case ID_DAP_Vendor13: { - // switching between chip erase and page erase - // COMMAND(OUT Packet) - // BYTE 0 1000 1110 0x8D - // BYTE 1 Desired Mode: - // 0x00 - Chip Erase - // nonzero - Page Erase - // RESPONSE(IN Packet) - // BYTE 0 - // 0x00 - OK - *response = DAP_OK; - if (0x00U == *request) { - flash_manager_set_page_erase(false); - } else { - flash_manager_set_page_erase(true); - } - num += (1U << 16) | 1U; // increment request and response count each by 1 - break; - } - case ID_DAP_Vendor14: break; - case ID_DAP_Vendor15: break; - case ID_DAP_Vendor16: break; - case ID_DAP_Vendor17: break; - case ID_DAP_Vendor18: break; - case ID_DAP_Vendor19: break; - case ID_DAP_Vendor20: break; - case ID_DAP_Vendor21: break; - case ID_DAP_Vendor22: break; - case ID_DAP_Vendor23: break; - case ID_DAP_Vendor24: break; - case ID_DAP_Vendor25: break; - case ID_DAP_Vendor26: break; - case ID_DAP_Vendor27: break; - case ID_DAP_Vendor28: break; - case ID_DAP_Vendor29: break; - case ID_DAP_Vendor30: break; - case ID_DAP_Vendor31: break; - */ - default: break; - } - - return (num); -} - -///@} diff --git a/teensy/src/IO_Config.c b/teensy/src/IO_Config.c deleted file mode 100644 index 0c3ea29..0000000 --- a/teensy/src/IO_Config.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int pin_swclk = DEFAULT_PIN_SWCLK; -int pin_swdio = DEFAULT_PIN_SWDIO; -int pin_nreset = DEFAULT_PIN_NRESET; -int pin_tdi = DEFAULT_PIN_TDI; -int pin_tdo = DEFAULT_PIN_TDO; -int pin_led_connected = DEFAULT_PIN_LED_CONNECTED; -int pin_led_running = DEFAULT_PIN_LED_RUNNING; \ No newline at end of file diff --git a/teensy/src/IO_Config.h b/teensy/src/IO_Config.h deleted file mode 100644 index 1b7452d..0000000 --- a/teensy/src/IO_Config.h +++ /dev/null @@ -1,83 +0,0 @@ - -#ifndef IO_CONFIG_H -#define IO_CONFIG_H - -#if defined(ARDUINO_TEENSY31) || defined(ARDUINO_TEENSY36) - -#define PIN_RX1 0 -#define PIN_TX1 1 -#define PIN_RX2 9 -#define PIN_TX2 10 -#define PIN_RX3 7 -#define PIN_TX3 8 - -#elif ARDUINO_TEENSY41 - -#define PIN_RX1 0 -#define PIN_TX1 1 -#define PIN_RX2 7 -#define PIN_TX2 8 -#define PIN_RX3 15 -#define PIN_TX3 14 - -#elif ARDUINO_TEENSY40 -#define PIN_RX1 0 -#define PIN_TX1 -1 -#define PIN_RX2 7 -#define PIN_TX2 8 -#define PIN_RX3 15 -#define PIN_TX3 14 -#endif - -#define DEFAULT_PIN_SWCLK 23 -#define DEFAULT_PIN_SWDIO 22 -#define DEFAULT_PIN_NRESET 21 -#define DEFAULT_PIN_TDI 20 -#define DEFAULT_PIN_TDO 24 -#if ARDUINO_TEENSY40 -#define DEFAULT_PIN_LED_CONNECTED 19 -#define DEFAULT_PIN_LED_RUNNING 25 -#else -#define DEFAULT_PIN_LED_CONNECTED 34 -#define DEFAULT_PIN_LED_RUNNING 35 -#endif -extern int pin_swclk; -extern int pin_swdio; -extern int pin_nreset; -extern int pin_tdi; -extern int pin_tdo; -extern int pin_led_connected; -extern int pin_led_running; - -#if defined(ARDUINO_TEENSY31) || defined(ARDUINO_TEENSY36) - -#define SPI_WP 6 -#define SPI_MOSI 11 -#define SPI_MISO 12 -#define SPI_SCK 14 -#define SPI_CS 15 - -#elif ARDUINO_TEENSY41 -#define SPI_WP 6 -#define SPI_MOSI 11 -#define SPI_MISO 12 -#define SPI_SCK 13 -#define SPI_CS 10 - -#elif ARDUINO_TEENSY40 -#define SPI_WP 6 -#define SPI_MOSI 11 -#define SPI_MISO 12 -#define SPI_SCK 13 -#define SPI_CS 10 - -#define SPI1_CS 28 -#define SPI1_DO 26 -#define SPI1_DI 1 -#define SPI1_SCK 27 -#endif - -#define BUTTON_HOST_POWER 16 -#define BUTTON_HOST_RESET 17 - -#endif diff --git a/teensy/src/JTAG_DP.c b/teensy/src/JTAG_DP.c deleted file mode 100644 index 24b1f3f..0000000 --- a/teensy/src/JTAG_DP.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - * - * 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. - * - * ---------------------------------------------------------------------- - * - * $Date: 1. December 2017 - * $Revision: V2.0.0 - * - * Project: CMSIS-DAP Source - * Title: JTAG_DP.c CMSIS-DAP JTAG DP I/O - * - *---------------------------------------------------------------------------*/ - -#include "DAP_config.h" -#include "DAP.h" - - -// JTAG Macros - -#define PIN_TCK_SET PIN_SWCLK_TCK_SET -#define PIN_TCK_CLR PIN_SWCLK_TCK_CLR -#define PIN_TMS_SET PIN_SWDIO_TMS_SET -#define PIN_TMS_CLR PIN_SWDIO_TMS_CLR - -#define JTAG_CYCLE_TCK() \ - PIN_TCK_CLR(); \ - PIN_DELAY(); \ - PIN_TCK_SET(); \ - PIN_DELAY() - -#define JTAG_CYCLE_TDI(tdi) \ - PIN_TDI_OUT(tdi); \ - PIN_TCK_CLR(); \ - PIN_DELAY(); \ - PIN_TCK_SET(); \ - PIN_DELAY() - -#define JTAG_CYCLE_TDO(tdo) \ - PIN_TCK_CLR(); \ - PIN_DELAY(); \ - tdo = PIN_TDO_IN(); \ - PIN_TCK_SET(); \ - PIN_DELAY() - -#define JTAG_CYCLE_TDIO(tdi,tdo) \ - PIN_TDI_OUT(tdi); \ - PIN_TCK_CLR(); \ - PIN_DELAY(); \ - tdo = PIN_TDO_IN(); \ - PIN_TCK_SET(); \ - PIN_DELAY() - -#define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) - - -#if (DAP_JTAG != 0) - - -// Generate JTAG Sequence -// info: sequence information -// tdi: pointer to TDI generated data -// tdo: pointer to TDO captured data -// return: none -void JTAG_Sequence (uint32_t info, const uint8_t *tdi, uint8_t *tdo) { - uint32_t i_val; - uint32_t o_val; - uint32_t bit; - uint32_t n, k; - - n = info & JTAG_SEQUENCE_TCK; - if (n == 0U) { - n = 64U; - } - - if (info & JTAG_SEQUENCE_TMS) { - PIN_TMS_SET(); - } else { - PIN_TMS_CLR(); - } - - while (n) { - i_val = *tdi++; - o_val = 0U; - for (k = 8U; k && n; k--, n--) { - JTAG_CYCLE_TDIO(i_val, bit); - i_val >>= 1; - o_val >>= 1; - o_val |= bit << 7; - } - o_val >>= k; - if (info & JTAG_SEQUENCE_TDO) { - *tdo++ = (uint8_t)o_val; - } - } -} - - -// JTAG Set IR -// ir: IR value -// return: none -#define JTAG_IR_Function(speed) /**/ \ -static void JTAG_IR_##speed (uint32_t ir) { \ - uint32_t n; \ - \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TCK(); /* Select-DR-Scan */ \ - JTAG_CYCLE_TCK(); /* Select-IR-Scan */ \ - PIN_TMS_CLR(); \ - JTAG_CYCLE_TCK(); /* Capture-IR */ \ - JTAG_CYCLE_TCK(); /* Shift-IR */ \ - \ - PIN_TDI_OUT(1U); \ - for (n = DAP_Data.jtag_dev.ir_before[DAP_Data.jtag_dev.index]; n; n--) { \ - JTAG_CYCLE_TCK(); /* Bypass before data */ \ - } \ - for (n = DAP_Data.jtag_dev.ir_length[DAP_Data.jtag_dev.index] - 1U; n; n--) { \ - JTAG_CYCLE_TDI(ir); /* Set IR bits (except last) */ \ - ir >>= 1; \ - } \ - n = DAP_Data.jtag_dev.ir_after[DAP_Data.jtag_dev.index]; \ - if (n) { \ - JTAG_CYCLE_TDI(ir); /* Set last IR bit */ \ - PIN_TDI_OUT(1U); \ - for (--n; n; n--) { \ - JTAG_CYCLE_TCK(); /* Bypass after data */ \ - } \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TCK(); /* Bypass & Exit1-IR */ \ - } else { \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TDI(ir); /* Set last IR bit & Exit1-IR */ \ - } \ - \ - JTAG_CYCLE_TCK(); /* Update-IR */ \ - PIN_TMS_CLR(); \ - JTAG_CYCLE_TCK(); /* Idle */ \ - PIN_TDI_OUT(1U); \ -} - - -// JTAG Transfer I/O -// request: A[3:2] RnW APnDP -// data: DATA[31:0] -// return: ACK[2:0] -#define JTAG_TransferFunction(speed) /**/ \ -static uint8_t JTAG_Transfer##speed (uint32_t request, uint32_t *data) { \ - uint32_t ack; \ - uint32_t bit; \ - uint32_t val; \ - uint32_t n; \ - \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TCK(); /* Select-DR-Scan */ \ - PIN_TMS_CLR(); \ - JTAG_CYCLE_TCK(); /* Capture-DR */ \ - JTAG_CYCLE_TCK(); /* Shift-DR */ \ - \ - for (n = DAP_Data.jtag_dev.index; n; n--) { \ - JTAG_CYCLE_TCK(); /* Bypass before data */ \ - } \ - \ - JTAG_CYCLE_TDIO(request >> 1, bit); /* Set RnW, Get ACK.0 */ \ - ack = bit << 1; \ - JTAG_CYCLE_TDIO(request >> 2, bit); /* Set A2, Get ACK.1 */ \ - ack |= bit << 0; \ - JTAG_CYCLE_TDIO(request >> 3, bit); /* Set A3, Get ACK.2 */ \ - ack |= bit << 2; \ - \ - if (ack != DAP_TRANSFER_OK) { \ - /* Exit on error */ \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TCK(); /* Exit1-DR */ \ - goto exit; \ - } \ - \ - if (request & DAP_TRANSFER_RnW) { \ - /* Read Transfer */ \ - val = 0U; \ - for (n = 31U; n; n--) { \ - JTAG_CYCLE_TDO(bit); /* Get D0..D30 */ \ - val |= bit << 31; \ - val >>= 1; \ - } \ - n = DAP_Data.jtag_dev.count - DAP_Data.jtag_dev.index - 1U; \ - if (n) { \ - JTAG_CYCLE_TDO(bit); /* Get D31 */ \ - for (--n; n; n--) { \ - JTAG_CYCLE_TCK(); /* Bypass after data */ \ - } \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TCK(); /* Bypass & Exit1-DR */ \ - } else { \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TDO(bit); /* Get D31 & Exit1-DR */ \ - } \ - val |= bit << 31; \ - if (data) { *data = val; } \ - } else { \ - /* Write Transfer */ \ - val = *data; \ - for (n = 31U; n; n--) { \ - JTAG_CYCLE_TDI(val); /* Set D0..D30 */ \ - val >>= 1; \ - } \ - n = DAP_Data.jtag_dev.count - DAP_Data.jtag_dev.index - 1U; \ - if (n) { \ - JTAG_CYCLE_TDI(val); /* Set D31 */ \ - for (--n; n; n--) { \ - JTAG_CYCLE_TCK(); /* Bypass after data */ \ - } \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TCK(); /* Bypass & Exit1-DR */ \ - } else { \ - PIN_TMS_SET(); \ - JTAG_CYCLE_TDI(val); /* Set D31 & Exit1-DR */ \ - } \ - } \ - \ -exit: \ - JTAG_CYCLE_TCK(); /* Update-DR */ \ - PIN_TMS_CLR(); \ - JTAG_CYCLE_TCK(); /* Idle */ \ - PIN_TDI_OUT(1U); \ - \ - /* Capture Timestamp */ \ - if (request & DAP_TRANSFER_TIMESTAMP) { \ - DAP_Data.timestamp = TIMESTAMP_GET(); \ - } \ - \ - /* Idle cycles */ \ - n = DAP_Data.transfer.idle_cycles; \ - while (n--) { \ - JTAG_CYCLE_TCK(); /* Idle */ \ - } \ - \ - return ((uint8_t)ack); \ -} - - -#undef PIN_DELAY -#define PIN_DELAY() PIN_DELAY_FAST() -JTAG_IR_Function(Fast) -JTAG_TransferFunction(Fast) - -#undef PIN_DELAY -#define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) -JTAG_IR_Function(Slow) -JTAG_TransferFunction(Slow) - - -// JTAG Read IDCODE register -// return: value read -uint32_t JTAG_ReadIDCode (void) { - uint32_t bit; - uint32_t val; - uint32_t n; - - PIN_TMS_SET(); - JTAG_CYCLE_TCK(); /* Select-DR-Scan */ - PIN_TMS_CLR(); - JTAG_CYCLE_TCK(); /* Capture-DR */ - JTAG_CYCLE_TCK(); /* Shift-DR */ - - for (n = DAP_Data.jtag_dev.index; n; n--) { - JTAG_CYCLE_TCK(); /* Bypass before data */ - } - - val = 0U; - for (n = 31U; n; n--) { - JTAG_CYCLE_TDO(bit); /* Get D0..D30 */ - val |= bit << 31; - val >>= 1; - } - PIN_TMS_SET(); - JTAG_CYCLE_TDO(bit); /* Get D31 & Exit1-DR */ - val |= bit << 31; - - JTAG_CYCLE_TCK(); /* Update-DR */ - PIN_TMS_CLR(); - JTAG_CYCLE_TCK(); /* Idle */ - - return (val); -} - - -// JTAG Write ABORT register -// data: value to write -// return: none -void JTAG_WriteAbort (uint32_t data) { - uint32_t n; - - PIN_TMS_SET(); - JTAG_CYCLE_TCK(); /* Select-DR-Scan */ - PIN_TMS_CLR(); - JTAG_CYCLE_TCK(); /* Capture-DR */ - JTAG_CYCLE_TCK(); /* Shift-DR */ - - for (n = DAP_Data.jtag_dev.index; n; n--) { - JTAG_CYCLE_TCK(); /* Bypass before data */ - } - - PIN_TDI_OUT(0U); - JTAG_CYCLE_TCK(); /* Set RnW=0 (Write) */ - JTAG_CYCLE_TCK(); /* Set A2=0 */ - JTAG_CYCLE_TCK(); /* Set A3=0 */ - - for (n = 31U; n; n--) { - JTAG_CYCLE_TDI(data); /* Set D0..D30 */ - data >>= 1; - } - n = DAP_Data.jtag_dev.count - DAP_Data.jtag_dev.index - 1U; - if (n) { - JTAG_CYCLE_TDI(data); /* Set D31 */ - for (--n; n; n--) { - JTAG_CYCLE_TCK(); /* Bypass after data */ - } - PIN_TMS_SET(); - JTAG_CYCLE_TCK(); /* Bypass & Exit1-DR */ - } else { - PIN_TMS_SET(); - JTAG_CYCLE_TDI(data); /* Set D31 & Exit1-DR */ - } - - JTAG_CYCLE_TCK(); /* Update-DR */ - PIN_TMS_CLR(); - JTAG_CYCLE_TCK(); /* Idle */ - PIN_TDI_OUT(1U); -} - - -// JTAG Set IR -// ir: IR value -// return: none -void JTAG_IR (uint32_t ir) { - if (DAP_Data.fast_clock) { - JTAG_IR_Fast(ir); - } else { - JTAG_IR_Slow(ir); - } -} - - -// JTAG Transfer I/O -// request: A[3:2] RnW APnDP -// data: DATA[31:0] -// return: ACK[2:0] -uint8_t JTAG_Transfer(uint32_t request, uint32_t *data) { - if (DAP_Data.fast_clock) { - return JTAG_TransferFast(request, data); - } else { - return JTAG_TransferSlow(request, data); - } -} - - -#endif /* (DAP_JTAG != 0) */ diff --git a/teensy/src/SW_DP.c b/teensy/src/SW_DP.c deleted file mode 100644 index 803cf42..0000000 --- a/teensy/src/SW_DP.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - * - * 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. - * - * ---------------------------------------------------------------------- - * - * $Date: 1. December 2017 - * $Revision: V2.0.0 - * - * Project: CMSIS-DAP Source - * Title: SW_DP.c CMSIS-DAP SW DP I/O - * - *---------------------------------------------------------------------------*/ - -#include "DAP_config.h" -#include "DAP.h" - - -// SW Macros - -#define PIN_SWCLK_SET PIN_SWCLK_TCK_SET -#define PIN_SWCLK_CLR PIN_SWCLK_TCK_CLR - -#define SW_CLOCK_CYCLE() \ - PIN_SWCLK_CLR(); \ - PIN_DELAY(); \ - PIN_SWCLK_SET(); \ - PIN_DELAY() - -#define SW_WRITE_BIT(bit) \ - PIN_SWDIO_OUT(bit); \ - PIN_SWCLK_CLR(); \ - PIN_DELAY(); \ - PIN_SWCLK_SET(); \ - PIN_DELAY() - -#define SW_READ_BIT(bit) \ - PIN_SWCLK_CLR(); \ - PIN_DELAY(); \ - bit = PIN_SWDIO_IN(); \ - PIN_SWCLK_SET(); \ - PIN_DELAY() - -#define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) - - -// Generate SWJ Sequence -// count: sequence bit count -// data: pointer to sequence bit data -// return: none -#if ((DAP_SWD != 0) || (DAP_JTAG != 0)) -void SWJ_Sequence (uint32_t count, const uint8_t *data) { - uint32_t val; - uint32_t n; - - val = 0U; - n = 0U; - while (count--) { - if (n == 0U) { - val = *data++; - n = 8U; - } - if (val & 1U) { - PIN_SWDIO_TMS_SET(); - } else { - PIN_SWDIO_TMS_CLR(); - } - SW_CLOCK_CYCLE(); - val >>= 1; - n--; - } -} -#endif - - -// Generate SWD Sequence -// info: sequence information -// swdo: pointer to SWDIO generated data -// swdi: pointer to SWDIO captured data -// return: none -#if (DAP_SWD != 0) -void SWD_Sequence (uint32_t info, const uint8_t *swdo, uint8_t *swdi) { - uint32_t val; - uint32_t bit; - uint32_t n, k; - - n = info & SWD_SEQUENCE_CLK; - if (n == 0U) { - n = 64U; - } - - if (info & SWD_SEQUENCE_DIN) { - while (n) { - val = 0U; - for (k = 8U; k && n; k--, n--) { - SW_READ_BIT(bit); - val >>= 1; - val |= bit << 7; - } - val >>= k; - *swdi++ = (uint8_t)val; - } - } else { - while (n) { - val = *swdo++; - for (k = 8U; k && n; k--, n--) { - SW_WRITE_BIT(val); - val >>= 1; - } - } - } -} -#endif - - -#if (DAP_SWD != 0) - - -// SWD Transfer I/O -// request: A[3:2] RnW APnDP -// data: DATA[31:0] -// return: ACK[2:0] -#define SWD_TransferFunction(speed) /**/ \ -static uint8_t SWD_Transfer##speed (uint32_t request, uint32_t *data) { \ - uint32_t ack; \ - uint32_t bit; \ - uint32_t val; \ - uint32_t parity; \ - \ - uint32_t n; \ - \ - /* Packet Request */ \ - parity = 0U; \ - SW_WRITE_BIT(1U); /* Start Bit */ \ - bit = request >> 0; \ - SW_WRITE_BIT(bit); /* APnDP Bit */ \ - parity += bit; \ - bit = request >> 1; \ - SW_WRITE_BIT(bit); /* RnW Bit */ \ - parity += bit; \ - bit = request >> 2; \ - SW_WRITE_BIT(bit); /* A2 Bit */ \ - parity += bit; \ - bit = request >> 3; \ - SW_WRITE_BIT(bit); /* A3 Bit */ \ - parity += bit; \ - SW_WRITE_BIT(parity); /* Parity Bit */ \ - SW_WRITE_BIT(0U); /* Stop Bit */ \ - SW_WRITE_BIT(1U); /* Park Bit */ \ - \ - /* Turnaround */ \ - PIN_SWDIO_OUT_DISABLE(); \ - for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ - SW_CLOCK_CYCLE(); \ - } \ - \ - /* Acknowledge response */ \ - SW_READ_BIT(bit); \ - ack = bit << 0; \ - SW_READ_BIT(bit); \ - ack |= bit << 1; \ - SW_READ_BIT(bit); \ - ack |= bit << 2; \ - \ - if (ack == DAP_TRANSFER_OK) { /* OK response */ \ - /* Data transfer */ \ - if (request & DAP_TRANSFER_RnW) { \ - /* Read data */ \ - val = 0U; \ - parity = 0U; \ - for (n = 32U; n; n--) { \ - SW_READ_BIT(bit); /* Read RDATA[0:31] */ \ - parity += bit; \ - val >>= 1; \ - val |= bit << 31; \ - } \ - SW_READ_BIT(bit); /* Read Parity */ \ - if ((parity ^ bit) & 1U) { \ - ack = DAP_TRANSFER_ERROR; \ - } \ - if (data) { *data = val; } \ - /* Turnaround */ \ - for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ - SW_CLOCK_CYCLE(); \ - } \ - PIN_SWDIO_OUT_ENABLE(); \ - } else { \ - /* Turnaround */ \ - for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ - SW_CLOCK_CYCLE(); \ - } \ - PIN_SWDIO_OUT_ENABLE(); \ - /* Write data */ \ - val = *data; \ - parity = 0U; \ - for (n = 32U; n; n--) { \ - SW_WRITE_BIT(val); /* Write WDATA[0:31] */ \ - parity += val; \ - val >>= 1; \ - } \ - SW_WRITE_BIT(parity); /* Write Parity Bit */ \ - } \ - /* Capture Timestamp */ \ - if (request & DAP_TRANSFER_TIMESTAMP) { \ - DAP_Data.timestamp = TIMESTAMP_GET(); \ - } \ - /* Idle cycles */ \ - n = DAP_Data.transfer.idle_cycles; \ - if (n) { \ - PIN_SWDIO_OUT(0U); \ - for (; n; n--) { \ - SW_CLOCK_CYCLE(); \ - } \ - } \ - PIN_SWDIO_OUT(1U); \ - return ((uint8_t)ack); \ - } \ - \ - if ((ack == DAP_TRANSFER_WAIT) || (ack == DAP_TRANSFER_FAULT)) { \ - /* WAIT or FAULT response */ \ - if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) != 0U)) { \ - for (n = 32U+1U; n; n--) { \ - SW_CLOCK_CYCLE(); /* Dummy Read RDATA[0:31] + Parity */ \ - } \ - } \ - /* Turnaround */ \ - for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ - SW_CLOCK_CYCLE(); \ - } \ - PIN_SWDIO_OUT_ENABLE(); \ - if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) == 0U)) { \ - PIN_SWDIO_OUT(0U); \ - for (n = 32U+1U; n; n--) { \ - SW_CLOCK_CYCLE(); /* Dummy Write WDATA[0:31] + Parity */ \ - } \ - } \ - PIN_SWDIO_OUT(1U); \ - return ((uint8_t)ack); \ - } \ - \ - /* Protocol error */ \ - for (n = DAP_Data.swd_conf.turnaround + 32U + 1U; n; n--) { \ - SW_CLOCK_CYCLE(); /* Back off data phase */ \ - } \ - PIN_SWDIO_OUT_ENABLE(); \ - PIN_SWDIO_OUT(1U); \ - return ((uint8_t)ack); \ -} - - -#undef PIN_DELAY -#define PIN_DELAY() PIN_DELAY_FAST() -SWD_TransferFunction(Fast) - -#undef PIN_DELAY -#define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) -SWD_TransferFunction(Slow) - - -// SWD Transfer I/O -// request: A[3:2] RnW APnDP -// data: DATA[31:0] -// return: ACK[2:0] -uint8_t SWD_Transfer(uint32_t request, uint32_t *data) { - if (DAP_Data.fast_clock) { - return SWD_TransferFast(request, data); - } else { - return SWD_TransferSlow(request, data); - } -} - - -#endif /* (DAP_SWD != 0) */ diff --git a/teensy/src/dap_strings.h b/teensy/src/dap_strings.h deleted file mode 100644 index a838489..0000000 --- a/teensy/src/dap_strings.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @file dap_strings.h - * - * DAPLink Interface Firmware - * Copyright (c) 2019, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * 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 "cmsis_compiler.h" -//#include "info.h" - -/** Get Vendor ID string. -\param str Pointer to buffer to store the string. -\return String length. -*/ -static __inline uint8_t DAP_GetVendorString (char *str) { - (void)str; - return (0U); -} - -/** Get Product ID string. -\param str Pointer to buffer to store the string. -\return String length. -*/ -static __inline uint8_t DAP_GetProductString (char *str) { - (void)str; - return (0U); -} - -/** Get Serial Number string. -\param str Pointer to buffer to store the string. -\return String length. -*/ -static __inline uint8_t DAP_GetSerNumString (char *str) { - const char * data = "1234"; - uint8_t length = (uint8_t)strlen(data) + 1; - memcpy(str, data, length); - return length; -} - -/** Get firmware version string. -\param str Pointer to buffer to store the string. -\return String length. -*/ -static __inline uint8_t DAP_GetFirmwareVersionString (char *str) { - const char * data = "1.2.3.4"; - uint8_t length = (uint8_t)strlen(data) + 1; - memcpy(str, data, length); - return length; -} diff --git a/teensy/src/debug_ca.h b/teensy/src/debug_ca.h deleted file mode 100644 index dbe085a..0000000 --- a/teensy/src/debug_ca.h +++ /dev/null @@ -1,147 +0,0 @@ -/** - * @file debug_ca.h - * @brief Access to ARM DAP (Cortex-A) using CMSIS-DAP protocol - * - * DAPLink Interface Firmware - * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef DEBUG_CA_H -#define DEBUG_CA_H - -#include "debug_cm.h" - -// Debug registers -#define DEBUG_REGSITER_BASE (0x80030000) - -#define DBGDIDR (DEBUG_REGSITER_BASE + (0 * 4)) // Debug ID -#define DBGWFAR (DEBUG_REGSITER_BASE + (6 * 4)) // Watchpoint Fault Address -#define DBGVCR (DEBUG_REGSITER_BASE + (7 * 4)) // Vector Catch -#define DBGECR (DEBUG_REGSITER_BASE + (9 * 4)) // Event Catch -#define DBGDTRRX (DEBUG_REGSITER_BASE + (32 * 4)) // Host to Target Data Transfer -#define DBGITR (DEBUG_REGSITER_BASE + (33 * 4)) // WO Instruction Transfer -#define DBGDSCR (DEBUG_REGSITER_BASE + (34 * 4)) // Debug Status and Control -#define DBGDTRTX (DEBUG_REGSITER_BASE + (35 * 4)) // Target to Host Data Transfer -#define DBGDRCR (DEBUG_REGSITER_BASE + (36 * 4)) // Debug Run Control -#define DBGEACR (DEBUG_REGSITER_BASE + (37 * 4)) // External Auxiliary Control -#define DBGPCSR (DEBUG_REGSITER_BASE + (40 * 4)) // Program Counter Sampling -#define DBGCIDSR (DEBUG_REGSITER_BASE + (41 * 4)) // Context ID Sampling -#define DBGVIDSR (DEBUG_REGSITER_BASE + (42 * 4)) // Virtualization ID Sampling -#define DBGBVR0 (DEBUG_REGSITER_BASE + (64 * 4)) // Breakpoint Value -#define DBGBVR1 (DEBUG_REGSITER_BASE + (65 * 4)) // Breakpoint Value -#define DBGBVR2 (DEBUG_REGSITER_BASE + (66 * 4)) // Breakpoint Value -#define DBGBVR3 (DEBUG_REGSITER_BASE + (67 * 4)) // Breakpoint Value -#define DBGBVR4 (DEBUG_REGSITER_BASE + (68 * 4)) // Breakpoint Value -#define DBGBVR5 (DEBUG_REGSITER_BASE + (69 * 4)) // Breakpoint Value -#define DBGBVR6 (DEBUG_REGSITER_BASE + (70 * 4)) // Breakpoint Value -#define DBGBVR7 (DEBUG_REGSITER_BASE + (71 * 4)) // Breakpoint Value -#define DBGBVR8 (DEBUG_REGSITER_BASE + (72 * 4)) // Breakpoint Value -#define DBGBVR9 (DEBUG_REGSITER_BASE + (73 * 4)) // Breakpoint Value -#define DBGBVR10 (DEBUG_REGSITER_BASE + (74 * 4)) // Breakpoint Value -#define DBGBVR11 (DEBUG_REGSITER_BASE + (75 * 4)) // Breakpoint Value -#define DBGBVR12 (DEBUG_REGSITER_BASE + (76 * 4)) // Breakpoint Value -#define DBGBVR13 (DEBUG_REGSITER_BASE + (77 * 4)) // Breakpoint Value -#define DBGBVR14 (DEBUG_REGSITER_BASE + (78 * 4)) // Breakpoint Value -#define DBGBVR15 (DEBUG_REGSITER_BASE + (79 * 4)) // Breakpoint Value -#define DBGBCR0 (DEBUG_REGSITER_BASE + (80 * 4)) // Breakpoint Control -#define DBGBCR1 (DEBUG_REGSITER_BASE + (81 * 4)) // Breakpoint Control -#define DBGBCR2 (DEBUG_REGSITER_BASE + (82 * 4)) // Breakpoint Control -#define DBGBCR3 (DEBUG_REGSITER_BASE + (83 * 4)) // Breakpoint Control -#define DBGBCR4 (DEBUG_REGSITER_BASE + (84 * 4)) // Breakpoint Control -#define DBGBCR5 (DEBUG_REGSITER_BASE + (85 * 4)) // Breakpoint Control -#define DBGBCR6 (DEBUG_REGSITER_BASE + (86 * 4)) // Breakpoint Control -#define DBGBCR7 (DEBUG_REGSITER_BASE + (87 * 4)) // Breakpoint Control -#define DBGBCR8 (DEBUG_REGSITER_BASE + (88 * 4)) // Breakpoint Control -#define DBGBCR9 (DEBUG_REGSITER_BASE + (89 * 4)) // Breakpoint Control -#define DBGBCR10 (DEBUG_REGSITER_BASE + (90 * 4)) // Breakpoint Control -#define DBGBCR11 (DEBUG_REGSITER_BASE + (91 * 4)) // Breakpoint Control -#define DBGBCR12 (DEBUG_REGSITER_BASE + (92 * 4)) // Breakpoint Control -#define DBGBCR13 (DEBUG_REGSITER_BASE + (93 * 4)) // Breakpoint Control -#define DBGBCR14 (DEBUG_REGSITER_BASE + (94 * 4)) // Breakpoint Control -#define DBGBCR15 (DEBUG_REGSITER_BASE + (95 * 4)) // Breakpoint Control -#define DBGWVR0 (DEBUG_REGSITER_BASE + (96 * 4)) // Watchpoint Value -#define DBGWVR1 (DEBUG_REGSITER_BASE + (97 * 4)) // Watchpoint Value -#define DBGWVR2 (DEBUG_REGSITER_BASE + (98 * 4)) // Watchpoint Value -#define DBGWVR3 (DEBUG_REGSITER_BASE + (99 * 4)) // Watchpoint Value -#define DBGWVR4 (DEBUG_REGSITER_BASE + (100 * 4)) // Watchpoint Value -#define DBGWVR5 (DEBUG_REGSITER_BASE + (101 * 4)) // Watchpoint Value -#define DBGWVR6 (DEBUG_REGSITER_BASE + (102 * 4)) // Watchpoint Value -#define DBGWVR7 (DEBUG_REGSITER_BASE + (103 * 4)) // Watchpoint Value -#define DBGWVR8 (DEBUG_REGSITER_BASE + (104 * 4)) // Watchpoint Value -#define DBGWVR9 (DEBUG_REGSITER_BASE + (105 * 4)) // Watchpoint Value -#define DBGWVR10 (DEBUG_REGSITER_BASE + (106 * 4)) // Watchpoint Value -#define DBGWVR11 (DEBUG_REGSITER_BASE + (107 * 4)) // Watchpoint Value -#define DBGWVR12 (DEBUG_REGSITER_BASE + (108 * 4)) // Watchpoint Value -#define DBGWVR13 (DEBUG_REGSITER_BASE + (109 * 4)) // Watchpoint Value -#define DBGWVR14 (DEBUG_REGSITER_BASE + (110 * 4)) // Watchpoint Value -#define DBGWVR15 (DEBUG_REGSITER_BASE + (111 * 4)) // Watchpoint Value -#define DBGWCR0 (DEBUG_REGSITER_BASE + (112 * 4)) // Watchpoint Control -#define DBGWCR1 (DEBUG_REGSITER_BASE + (113 * 4)) // Watchpoint Control -#define DBGWCR2 (DEBUG_REGSITER_BASE + (114 * 4)) // Watchpoint Control -#define DBGWCR3 (DEBUG_REGSITER_BASE + (115 * 4)) // Watchpoint Control -#define DBGWCR4 (DEBUG_REGSITER_BASE + (116 * 4)) // Watchpoint Control -#define DBGWCR5 (DEBUG_REGSITER_BASE + (117 * 4)) // Watchpoint Control -#define DBGWCR6 (DEBUG_REGSITER_BASE + (118 * 4)) // Watchpoint Control -#define DBGWCR7 (DEBUG_REGSITER_BASE + (119 * 4)) // Watchpoint Control -#define DBGWCR8 (DEBUG_REGSITER_BASE + (120 * 4)) // Watchpoint Control -#define DBGWCR9 (DEBUG_REGSITER_BASE + (121 * 4)) // Watchpoint Control -#define DBGWCR10 (DEBUG_REGSITER_BASE + (122 * 4)) // Watchpoint Control -#define DBGWCR11 (DEBUG_REGSITER_BASE + (123 * 4)) // Watchpoint Control -#define DBGWCR12 (DEBUG_REGSITER_BASE + (124 * 4)) // Watchpoint Control -#define DBGWCR13 (DEBUG_REGSITER_BASE + (125 * 4)) // Watchpoint Control -#define DBGWCR14 (DEBUG_REGSITER_BASE + (126 * 4)) // Watchpoint Control -#define DBGWCR15 (DEBUG_REGSITER_BASE + (127 * 4)) // Watchpoint Control -#define DBGBXVR0 (DEBUG_REGSITER_BASE + (144 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR1 (DEBUG_REGSITER_BASE + (145 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR2 (DEBUG_REGSITER_BASE + (146 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR3 (DEBUG_REGSITER_BASE + (147 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR4 (DEBUG_REGSITER_BASE + (148 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR5 (DEBUG_REGSITER_BASE + (149 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR6 (DEBUG_REGSITER_BASE + (150 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR7 (DEBUG_REGSITER_BASE + (151 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR8 (DEBUG_REGSITER_BASE + (152 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR9 (DEBUG_REGSITER_BASE + (153 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR10 (DEBUG_REGSITER_BASE + (154 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR11 (DEBUG_REGSITER_BASE + (155 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR12 (DEBUG_REGSITER_BASE + (156 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR13 (DEBUG_REGSITER_BASE + (157 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR14 (DEBUG_REGSITER_BASE + (158 * 4)) // Breakpoint Extended Valueb -#define DBGBXVR15 (DEBUG_REGSITER_BASE + (159 * 4)) // Breakpoint Extended Valueb -#define DBGOSLAR (DEBUG_REGSITER_BASE + (192 * 4)) // OS Lock Access -#define DBGOSLSR (DEBUG_REGSITER_BASE + (193 * 4)) // OS Lock Status -#define DBGPRCR (DEBUG_REGSITER_BASE + (196 * 4)) // Powerdown and Reset Control -#define DBGPRSR (DEBUG_REGSITER_BASE + (197 * 4)) // Powerdown and Reset Status -#define DBGITCTRL (DEBUG_REGSITER_BASE + (960 * 4)) // Integration Mode Control -#define DBGCLAIMSET (DEBUG_REGSITER_BASE + (1000 * 4)) // Claim Tag Set -#define DBGCLAIMCLR (DEBUG_REGSITER_BASE + (1001 * 4)) // Claim Tag Clear -#define DBGLAR (DEBUG_REGSITER_BASE + (1004 * 4)) // Lock Access -#define DBGLSR (DEBUG_REGSITER_BASE + (1005 * 4)) // Lock Status -#define DBGAUTHSTATUS (DEBUG_REGSITER_BASE + (1006 * 4)) // Authentication Status -#define DBGDEVID2 (DEBUG_REGSITER_BASE + (1008 * 4)) // Debug Device ID 2 -#define DBGDEVID1 (DEBUG_REGSITER_BASE + (1009 * 4)) // Debug Device ID 1 -#define DBGDEVID (DEBUG_REGSITER_BASE + (1010 * 4)) // Debug Device ID -#define DBGDEVTYPE (DEBUG_REGSITER_BASE + (1011 * 4)) // Device Type -#define DBGPID0 (DEBUG_REGSITER_BASE + (1012 * 4)) // Debug Peripheral ID -#define DBGPID1 (DEBUG_REGSITER_BASE + (1013 * 4)) // Debug Peripheral ID -#define DBGPID2 (DEBUG_REGSITER_BASE + (1014 * 4)) // Debug Peripheral ID -#define DBGPID3 (DEBUG_REGSITER_BASE + (1015 * 4)) // Debug Peripheral ID -#define DBGPID4 (DEBUG_REGSITER_BASE + (1016 * 4)) // Debug Peripheral ID -#define DBGCID0 (DEBUG_REGSITER_BASE + (1020 * 4)) // Debug Component ID -#define DBGCID1 (DEBUG_REGSITER_BASE + (1021 * 4)) // Debug Component ID -#define DBGCID2 (DEBUG_REGSITER_BASE + (1022 * 4)) // Debug Component ID -#define DBGCID3 (DEBUG_REGSITER_BASE + (1023 * 4)) // Debug Component ID - -#endif diff --git a/teensy/src/debug_cm.h b/teensy/src/debug_cm.h deleted file mode 100644 index 42a47a8..0000000 --- a/teensy/src/debug_cm.h +++ /dev/null @@ -1,168 +0,0 @@ -/** - * @file debug_cm.h - * @brief Access to ARM DAP (Cortex-M) using CMSIS-DAP protocol - * - * DAPLink Interface Firmware - * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef DEBUG_CM_H -#define DEBUG_CM_H - -#include "DAP.h" - -// SWD register access -#define SWD_REG_AP (1) -#define SWD_REG_DP (0) -#define SWD_REG_R (1<<1) -#define SWD_REG_W (0<<1) -#define SWD_REG_ADR(a) (a & 0x0c) - -// Abort Register definitions -#define DAPABORT 0x00000001 // DAP Abort -#define STKCMPCLR 0x00000002 // Clear STICKYCMP Flag (SW Only) -#define STKERRCLR 0x00000004 // Clear STICKYERR Flag (SW Only) -#define WDERRCLR 0x00000008 // Clear WDATAERR Flag (SW Only) -#define ORUNERRCLR 0x00000010 // Clear STICKYORUN Flag (SW Only) - -// Debug Control and Status definitions -#define ORUNDETECT 0x00000001 // Overrun Detect -#define STICKYORUN 0x00000002 // Sticky Overrun -#define TRNMODE 0x0000000C // Transfer Mode Mask -#define TRNNORMAL 0x00000000 // Transfer Mode: Normal -#define TRNVERIFY 0x00000004 // Transfer Mode: Pushed Verify -#define TRNCOMPARE 0x00000008 // Transfer Mode: Pushed Compare -#define STICKYCMP 0x00000010 // Sticky Compare -#define STICKYERR 0x00000020 // Sticky Error -#define READOK 0x00000040 // Read OK (SW Only) -#define WDATAERR 0x00000080 // Write Data Error (SW Only) -#define MASKLANE 0x00000F00 // Mask Lane Mask -#define MASKLANE0 0x00000100 // Mask Lane 0 -#define MASKLANE1 0x00000200 // Mask Lane 1 -#define MASKLANE2 0x00000400 // Mask Lane 2 -#define MASKLANE3 0x00000800 // Mask Lane 3 -#define TRNCNT 0x001FF000 // Transaction Counter Mask -#define CDBGRSTREQ 0x04000000 // Debug Reset Request -#define CDBGRSTACK 0x08000000 // Debug Reset Acknowledge -#define CDBGPWRUPREQ 0x10000000 // Debug Power-up Request -#define CDBGPWRUPACK 0x20000000 // Debug Power-up Acknowledge -#define CSYSPWRUPREQ 0x40000000 // System Power-up Request -#define CSYSPWRUPACK 0x80000000 // System Power-up Acknowledge - -// Debug Select Register definitions -#define CTRLSEL 0x00000001 // CTRLSEL (SW Only) -#define APBANKSEL 0x000000F0 // APBANKSEL Mask -#define APSEL 0xFF000000 // APSEL Mask - -// Access Port Register Addresses -#define AP_CSW 0x00 // Control and Status Word -#define AP_TAR 0x04 // Transfer Address -#define AP_DRW 0x0C // Data Read/Write -#define AP_BD0 0x10 // Banked Data 0 -#define AP_BD1 0x14 // Banked Data 1 -#define AP_BD2 0x18 // Banked Data 2 -#define AP_BD3 0x1C // Banked Data 3 -#define AP_ROM 0xF8 // Debug ROM Address -#define AP_IDR 0xFC // Identification Register - -// AP Control and Status Word definitions -#define CSW_SIZE 0x00000007 // Access Size: Selection Mask -#define CSW_SIZE8 0x00000000 // Access Size: 8-bit -#define CSW_SIZE16 0x00000001 // Access Size: 16-bit -#define CSW_SIZE32 0x00000002 // Access Size: 32-bit -#define CSW_ADDRINC 0x00000030 // Auto Address Increment Mask -#define CSW_NADDRINC 0x00000000 // No Address Increment -#define CSW_SADDRINC 0x00000010 // Single Address Increment -#define CSW_PADDRINC 0x00000020 // Packed Address Increment -#define CSW_DBGSTAT 0x00000040 // Debug Status -#define CSW_TINPROG 0x00000080 // Transfer in progress -#define CSW_HPROT 0x02000000 // User/Privilege Control -#define CSW_MSTRTYPE 0x20000000 // Master Type Mask -#define CSW_MSTRCORE 0x00000000 // Master Type: Core -#define CSW_MSTRDBG 0x20000000 // Master Type: Debug -#define CSW_RESERVED 0x01000000 // Reserved Value - -// Core Debug Register Address Offsets -#define DBG_OFS 0x0DF0 // Debug Register Offset inside NVIC -#define DBG_HCSR_OFS 0x00 // Debug Halting Control & Status Register -#define DBG_CRSR_OFS 0x04 // Debug Core Register Selector Register -#define DBG_CRDR_OFS 0x08 // Debug Core Register Data Register -#define DBG_EMCR_OFS 0x0C // Debug Exception & Monitor Control Register - -// Core Debug Register Addresses -#define DBG_HCSR (DBG_Addr + DBG_HCSR_OFS) -#define DBG_CRSR (DBG_Addr + DBG_CRSR_OFS) -#define DBG_CRDR (DBG_Addr + DBG_CRDR_OFS) -#define DBG_EMCR (DBG_Addr + DBG_EMCR_OFS) - -// Debug Halting Control and Status Register definitions -#define C_DEBUGEN 0x00000001 // Debug Enable -#define C_HALT 0x00000002 // Halt -#define C_STEP 0x00000004 // Step -#define C_MASKINTS 0x00000008 // Mask Interrupts -#define C_SNAPSTALL 0x00000020 // Snap Stall -#define S_REGRDY 0x00010000 // Register R/W Ready Flag -#define S_HALT 0x00020000 // Halt Flag -#define S_SLEEP 0x00040000 // Sleep Flag -#define S_LOCKUP 0x00080000 // Lockup Flag -#define S_RETIRE_ST 0x01000000 // Sticky Retire Flag -#define S_RESET_ST 0x02000000 // Sticky Reset Flag -#define DBGKEY 0xA05F0000 // Debug Key - -// Debug Exception and Monitor Control Register definitions -#define VC_CORERESET 0x00000001 // Reset Vector Catch -#define VC_MMERR 0x00000010 // Debug Trap on MMU Fault -#define VC_NOCPERR 0x00000020 // Debug Trap on No Coprocessor Fault -#define VC_CHKERR 0x00000040 // Debug Trap on Checking Error Fault -#define VC_STATERR 0x00000080 // Debug Trap on State Error Fault -#define VC_BUSERR 0x00000100 // Debug Trap on Bus Error Fault -#define VC_INTERR 0x00000200 // Debug Trap on Interrupt Error Fault -#define VC_HARDERR 0x00000400 // Debug Trap on Hard Fault -#define MON_EN 0x00010000 // Monitor Enable -#define MON_PEND 0x00020000 // Monitor Pend -#define MON_STEP 0x00040000 // Monitor Step -#define MON_REQ 0x00080000 // Monitor Request -#define TRCENA 0x01000000 // Trace Enable (DWT, ITM, ETM, TPIU) - -// NVIC: Interrupt Controller Type Register -#define NVIC_ICT (NVIC_Addr + 0x0004) -#define INTLINESNUM 0x0000001F // Interrupt Line Numbers - -// NVIC: CPUID Base Register -#define NVIC_CPUID (NVIC_Addr + 0x0D00) -#define CPUID_PARTNO 0x0000FFF0 // Part Number Mask -#define CPUID_REVISION 0x0000000F // Revision Mask -#define CPUID_VARIANT 0x00F00000 // Variant Mask - -// NVIC: Application Interrupt/Reset Control Register -#define NVIC_AIRCR (NVIC_Addr + 0x0D0C) -#define VECTRESET 0x00000001 // Reset Cortex-M (except Debug) -#define VECTCLRACTIVE 0x00000002 // Clear Active Vector Bit -#define SYSRESETREQ 0x00000004 // Reset System (except Debug) -#define VECTKEY 0x05FA0000 // Write Key - -// NVIC: Debug Fault Status Register -#define NVIC_DFSR (NVIC_Addr + 0x0D30) -#define HALTED 0x00000001 // Halt Flag -#define BKPT 0x00000002 // BKPT Flag -#define DWTTRAP 0x00000004 // DWT Match -#define VCATCH 0x00000008 // Vector Catch Flag -#define EXTERNAL 0x00000010 // External Debug Request - -// Data Watchpoint and Trace unit -#define DWT_PCSR 0xe000101c // DWT PC Sampling Register - -#endif diff --git a/teensy/src/flash_raw.cpp b/teensy/src/flash_raw.cpp deleted file mode 100644 index 4cf75a1..0000000 --- a/teensy/src/flash_raw.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "flash_raw.h" - -#include - -#if 0 -extern "C" { - extern uint8_t external_psram_size; -} -//#define FLASH_MEMMAP 1 //Use memory-mapped access - -#define FLASH_SIZE_MB 32 - - -uint8_t _spiffs_region; -static const uint32_t flashBaseAddr[3] = { 0x800000u, 0x800000u}; -static const uint32_t eramBaseAddr = 0x07000000u; -static char flashID[8]; -static const void* extBase = (void*)0x70000000u; -static const uint32_t blocksize = 4096; //or 32k or 64k (set correct flash commands above) -static uint32_t flashCapacity[3] = {FLASH_SIZE_MB * 1024u * 1024u, 8u * 1024u * 1024u}; - -#define LUT0(opcode, pads, operand) (FLEXSPI_LUT_INSTRUCTION((opcode), (pads), (operand))) -#define LUT1(opcode, pads, operand) (FLEXSPI_LUT_INSTRUCTION((opcode), (pads), (operand)) << 16) -#define CMD_SDR FLEXSPI_LUT_OPCODE_CMD_SDR -#define ADDR_SDR FLEXSPI_LUT_OPCODE_RADDR_SDR -#define READ_SDR FLEXSPI_LUT_OPCODE_READ_SDR -#define WRITE_SDR FLEXSPI_LUT_OPCODE_WRITE_SDR -#define DUMMY_SDR FLEXSPI_LUT_OPCODE_DUMMY_SDR -#define MODE8_SDR FLEXSPI_LUT_OPCODE_MODE8_SDR -#define PINS1 FLEXSPI_LUT_NUM_PADS_1 -#define PINS4 FLEXSPI_LUT_NUM_PADS_4 - -// IDs -//Manufacturers codes - -// Error management -#define ERROR_0 0 // Success -#define ERROR_1 1 // Data too long to fit the transmission buffer on Arduino -#define ERROR_2 2 // received NACK on transmit of address -#define ERROR_3 3 // received NACK on transmit of data -#define ERROR_4 4 // Serial seems not available -#define ERROR_5 5 // Not referenced device ID -#define ERROR_6 6 // Unused -#define ERROR_7 7 // Fram chip unidentified -#define ERROR_8 8 // Number of bytes asked to read null -#define ERROR_9 9 // Bit position out of range -#define ERROR_10 10 // Not permitted opération -#define ERROR_11 11 // Memory address out of range - - -bool flash_wait(uint32_t timeout) { - uint8_t val; - uint32_t t = millis(); - FLEXSPI_IPRXFCR = FLEXSPI_IPRXFCR_CLRIPRXF; // clear rx fifo - do { - if(_spiffs_region == 0) { - flexspi_ip_read(8, flashBaseAddr[_spiffs_region], &val, 1 ); - } else { - flexspi_ip_read(5, flashBaseAddr[_spiffs_region], &val, 1 ); - } - if (timeout && (millis() - t > timeout)) { - return 1; } - } while ((val & 0x01) == 1); - return 0; -} - - int32_t flash_erase(uint32_t addr, uint32_t size) { - int s = size; - while (s > 0) { //TODO: Is this loop needed, or is size max 4096? - flexspi_ip_command(11, flashBaseAddr[_spiffs_region]); //write enable - flexspi_ip_command(12, addr); -#ifdef FLASH_MEMMAP - arm_dcache_delete((void*)((uint32_t)extBase + addr), size); -#endif - addr += blocksize; - s -= blocksize; - flash_wait(0); //TODO: Can we wait at the beginning intead? - } - return 0; -} - - int32_t flash_read(uint32_t addr, uint32_t size, void * dst) { - uint8_t *p; - p = (uint8_t *)extBase; - p += addr; - FLEXSPI_IPRXFCR = FLEXSPI_IPRXFCR_CLRIPRXF; // clear rx fifo - -#ifdef FLASH_MEMMAP - memcpy(dst, p, size); -#else - flexspi_ip_read(5, addr, dst, size); -#endif - return 0; -} - - int32_t flash_write(uint32_t addr, uint32_t size, void * src) { - if(_spiffs_region == 0) { - flexspi_ip_command(11, flashBaseAddr[_spiffs_region]); //write enable - flexspi_ip_write(13, addr, src, size); - } else { - flexspi_ip_write(6, addr, src, size); - } -#ifdef FLASH_MEMMAP - arm_dcache_delete((void*)((uint32_t)extBase + addr), size); -#endif - if(_spiffs_region == 0) - flash_wait(0); //TODO: Can we wait at the beginning instead? - return 0; -} - -void flash_chip_erase(void) { - flexspi_ip_command(11, flashBaseAddr[_spiffs_region]); - Serial.println("Erasing... (may take some time)"); - uint32_t t = millis(); - FLEXSPI2_LUT60 = LUT0(CMD_SDR, PINS4, 0x60); //Chip erase - flexspi_ip_command(15, flashBaseAddr[_spiffs_region]); -#ifdef FLASH_MEMMAP - arm_dcache_delete((void*)((uint32_t)extBase + flashBaseAddr[_spiffs_region]), flashCapacity[_spiffs_region]); -#endif - while (flash_wait(500)) { - Serial.print("."); - } - t = millis() - t; - Serial.printf("\nChip erased in %d seconds.\n", t / 1000); -} -#endif \ No newline at end of file diff --git a/teensy/src/flash_raw.h b/teensy/src/flash_raw.h deleted file mode 100644 index d7b6c3a..0000000 --- a/teensy/src/flash_raw.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _FLASH_RAW_H_ -#define _FLASH_RAW_H_ - -#include -#include -#include - - -#ifdef ARDUINO_TEENSY41 -int8_t flexspi_begin(void); -void flexspi_ip_command(uint32_t index, uint32_t addr); -void flexspi_ip_read(uint32_t index, uint32_t addr, void *data, uint32_t length); -void flexspi_ip_write(uint32_t index, uint32_t addr, const void *data, uint32_t length); -#endif - - -int32_t flash_write(uint32_t addr, uint32_t size, void * src); -int32_t flash_read(uint32_t addr, uint32_t size, void * dst); -int32_t flash_erase(uint32_t addr, uint32_t size); -void flash_chip_erase(void); -#endif \ No newline at end of file diff --git a/teensy/src/main.cpp b/teensy/src/main.cpp deleted file mode 100644 index d92b51e..0000000 --- a/teensy/src/main.cpp +++ /dev/null @@ -1,926 +0,0 @@ -#include "main.h" -#include -#include - -#include "frser.h" -#include "spihw_teensyspi.h" - - -uint8_t rawhidRequest[DAP_PACKET_SIZE]; -uint8_t rawhidResponse[DAP_PACKET_SIZE]; - - -struct interrupt_notifier { - bool active = false; - unsigned long last_update = 0; - volatile uint32_t isr_count[CORE_NUM_INTERRUPT] = {}; - volatile uint32_t handler_count[CORE_NUM_INTERRUPT] = {}; -}; - -interrupt_notifier pin_interrupt_state; - -#define FRSER_TERM 8 -#define FRSER_TERM2 9 -#define INTERRUPT_HANDLER_DEF(N) \ -void interrupt_handler_##N(void) { \ - ++pin_interrupt_state.isr_count[ N ]; \ -} - -INTERRUPT_HANDLER_DEF(0) -INTERRUPT_HANDLER_DEF(1) -INTERRUPT_HANDLER_DEF(2) -INTERRUPT_HANDLER_DEF(3) -INTERRUPT_HANDLER_DEF(4) -INTERRUPT_HANDLER_DEF(5) -INTERRUPT_HANDLER_DEF(6) -INTERRUPT_HANDLER_DEF(7) -INTERRUPT_HANDLER_DEF(8) -INTERRUPT_HANDLER_DEF(9) -INTERRUPT_HANDLER_DEF(10) -INTERRUPT_HANDLER_DEF(11) -INTERRUPT_HANDLER_DEF(12) -INTERRUPT_HANDLER_DEF(13) -INTERRUPT_HANDLER_DEF(14) -INTERRUPT_HANDLER_DEF(15) -INTERRUPT_HANDLER_DEF(16) -INTERRUPT_HANDLER_DEF(17) -INTERRUPT_HANDLER_DEF(18) -INTERRUPT_HANDLER_DEF(19) -INTERRUPT_HANDLER_DEF(20) -INTERRUPT_HANDLER_DEF(21) -INTERRUPT_HANDLER_DEF(22) -INTERRUPT_HANDLER_DEF(23) -INTERRUPT_HANDLER_DEF(24) -INTERRUPT_HANDLER_DEF(25) -INTERRUPT_HANDLER_DEF(26) -INTERRUPT_HANDLER_DEF(27) -INTERRUPT_HANDLER_DEF(28) -INTERRUPT_HANDLER_DEF(29) -INTERRUPT_HANDLER_DEF(30) -INTERRUPT_HANDLER_DEF(31) -INTERRUPT_HANDLER_DEF(32) -INTERRUPT_HANDLER_DEF(33) -#if defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY36) -INTERRUPT_HANDLER_DEF(34) -INTERRUPT_HANDLER_DEF(35) -INTERRUPT_HANDLER_DEF(36) -INTERRUPT_HANDLER_DEF(37) -INTERRUPT_HANDLER_DEF(38) -INTERRUPT_HANDLER_DEF(39) -#endif -#if defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY36) -INTERRUPT_HANDLER_DEF(40) -INTERRUPT_HANDLER_DEF(41) -INTERRUPT_HANDLER_DEF(42) -INTERRUPT_HANDLER_DEF(43) -INTERRUPT_HANDLER_DEF(44) -INTERRUPT_HANDLER_DEF(45) -INTERRUPT_HANDLER_DEF(46) -INTERRUPT_HANDLER_DEF(47) -INTERRUPT_HANDLER_DEF(48) -INTERRUPT_HANDLER_DEF(49) -INTERRUPT_HANDLER_DEF(50) -INTERRUPT_HANDLER_DEF(51) -INTERRUPT_HANDLER_DEF(52) -INTERRUPT_HANDLER_DEF(53) -INTERRUPT_HANDLER_DEF(54) -#endif - -#if defined(ARDUINO_TEENSY36) -INTERRUPT_HANDLER_DEF(55) -INTERRUPT_HANDLER_DEF(56) -INTERRUPT_HANDLER_DEF(57) -INTERRUPT_HANDLER_DEF(58) -INTERRUPT_HANDLER_DEF(59) -INTERRUPT_HANDLER_DEF(60) -INTERRUPT_HANDLER_DEF(61) -INTERRUPT_HANDLER_DEF(62) -INTERRUPT_HANDLER_DEF(63) -#endif -#if defined(ARDUINO_TEENSY31) -static_assert(CORE_NUM_INTERRUPT == 34, "interrupt handler length does not match processor"); -#elif defined(ARDUINO_TEENSY40) -static_assert(CORE_NUM_INTERRUPT == 40, "interrupt handler length does not match processor 40"); -#elif defined(ARDUINO_TEENSY41) -static_assert(CORE_NUM_INTERRUPT == 55, "interrupt handler length does not match processor for 36 or 41"); - -# elif defined(ARDUINO_TEENSY36) -static_assert(CORE_NUM_INTERRUPT == 64, "interrupt handler length does not match processor for 36 or 41"); - -#endif - -#define INTERRUPT_HANDLER(N) \ -interrupt_handler_##N - - -#define REGISTER_PIN_INTERRUPT(N) \ - case N: \ - attachInterrupt(digitalPinToInterrupt(N), INTERRUPT_HANDLER(N), CHANGE); \ - break - - - -#define INA260_DEFAULT_ADDR 0x40 -#define MFG_ID 0xFE -#define DIE_ID 0xFF -#define DIE_ID 0xFF -#define INA260_CONFIG 0x00 -#define INA260_CURRENT 0x01 -#define INA260_BUSVOLTAGE 0x02 -#define INA260_POWER 0x03 -struct ina260config { - int continuious = 0; - int address = INA260_DEFAULT_ADDR; - unsigned long last_update = 0; -}ina260config_t; -void printina230(auto dev); - -CLI_COMMAND(resetFunc); -CLI_COMMAND(termFunc); -CLI_COMMAND(powerFunc); -CLI_COMMAND(swdFunc); -CLI_COMMAND(serialFunc); -CLI_COMMAND(pinFunc); -CLI_COMMAND(anaFunc); -CLI_COMMAND(helpFunc); -CLI_COMMAND(bootloaderFunc); -CLI_COMMAND(i2cFunc); - -CLI_COMMAND(interruptFunc); -CLI_COMMAND(interruptdisFunc); - -CLI_COMMAND(ina260Func); - - - -void setup() { - -#ifdef ARDUINO_TEENSY40 - pinMode(1, INPUT); - pinMode(26, INPUT); - pinMode(27, INPUT); - pinMode(28, INPUT); - pinMode(29, INPUT); -#endif - - pinMode(SPI_WP, INPUT); - pinMode(SPI_MOSI, INPUT); - pinMode(SPI_MISO, INPUT); - pinMode(SPI_SCK, INPUT); - pinMode(SPI_CS, INPUT); - - - pinMode(BUTTON_HOST_POWER, OUTPUT_OPENDRAIN); - digitalWrite(BUTTON_HOST_POWER, HIGH); - //orb seems to have no pullup on reset circuit - //pinMode(BUTTON_HOST_RESET, INPUT); - pinMode(BUTTON_HOST_RESET, OUTPUT_OPENDRAIN); - digitalWrite(BUTTON_HOST_RESET, HIGH); - ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; - - Serial.begin(115200); - -#ifdef ARDUINO_TEENSY40 - //Serial1.setTX(0); - Serial1.setRX(0); -#endif - - Serial1.begin(115200); -#ifdef ARDUINO_TEENSY40 - pinMode(1, INPUT); - pinMode(26, INPUT); - pinMode(27, INPUT); - pinMode(28, INPUT); - pinMode(29, INPUT); -#endif - Serial2.begin(115200); - - Serial3.begin(115200); - pinMode(1, INPUT); - - - // put your setup code here, to run once: - //RawHID.begin(rawhidRequest, DAP_PACKET_SIZE); - CLI.setDefaultPrompt("> "); - CLI.addCommand("reset", resetFunc); - CLI.addCommand("term", termFunc); - CLI.addCommand("power", powerFunc); - CLI.addCommand("swd", swdFunc); - - CLI.addCommand("serial", serialFunc); - CLI.addCommand("pin", pinFunc); - CLI.addCommand("ana", anaFunc); - CLI.addCommand("help", helpFunc); - CLI.addCommand("?", helpFunc); - CLI.addCommand("bootloader", bootloaderFunc); - - CLI.addCommand("i2c", i2cFunc); - CLI.addCommand("int", interruptFunc); - CLI.addCommand("intd", interruptdisFunc); - - CLI.addCommand("ina260", ina260Func); - - - CLI.addClient(Serial); - - Wire.begin(); - - DAP_Setup(); - -#ifdef ARDUINO_TEENSY40 - pinMode(1, INPUT_PULLDOWN); - pinMode(26, INPUT_PULLDOWN); - pinMode(27, INPUT_PULLDOWN); - pinMode(28, INPUT_PULLDOWN); - pinMode(29, INPUT_PULLDOWN); -#endif -} - -#if defined(ARDUINO_TEENSY31) || defined(ARDUINO_TEENSY36) -#define DEFAULT_HW_TERM_1 1 -#define DEFAULT_HW_TERM_2 2 -#elif defined(ARDUINO_TEENSY40) || defined (ARDUINO_TEENSY41) -#define DEFAULT_HW_TERM_1 2 -#define DEFAULT_HW_TERM_2 1 -#endif - -//terminal 0 is command, 1 is redirect all to hw port 1, 2 is port 2, etc. -int current_terminal_1 = DEFAULT_HW_TERM_1; -int current_terminal_2 = DEFAULT_HW_TERM_2; -uint32_t term1_baud = 0; -uint32_t term2_baud = 0; - -HardwareSerial * getPort(int portnumber) -{ - switch (portnumber) { - case 1: - return &Serial1; - break; - case 2: - return &Serial2; - break; - case 3: - return &Serial3; - break; -#if defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY40) - case 4: - return &Serial4; - break; - case 5: - return &Serial5; - break; - case 6: - return &Serial6; - break; -#endif - default: - return NULL; - } - -} - -void handle_serial(){ - static const int serial_rx_loop_max = 128; - int serial_rx_count = 0; - HardwareSerial * hw = NULL; - CLI.process(); - - if (SerialUSB1.baud() != term1_baud){ - term1_baud = SerialUSB1.baud(); - Serial.print("USB Term 1 Baud set to "); - Serial.println(term1_baud); - hw = getPort(current_terminal_1); - if (hw) - hw->begin(term1_baud); - } - - if (SerialUSB2.baud() != term2_baud){ - term2_baud = SerialUSB2.baud(); - Serial.print("USB Term 2 Baud set to "); - Serial.println(term2_baud); - hw = getPort(current_terminal_2); - if (hw) - hw->begin(term2_baud); - } - - - hw = getPort(current_terminal_1); - if (hw) { - while(SerialUSB1.available() > 0) { - - hw->write(SerialUSB1.read()); - } - while(hw->available()) { - SerialUSB1.write(hw->read()); - if (serial_rx_count++ > serial_rx_loop_max) break; - } - - } - - hw = getPort(current_terminal_2); - if (hw) { - while(SerialUSB2.available() > 0) { - hw->write(SerialUSB2.read()); - } - while(hw->available()) { - SerialUSB2.write(hw->read()); - if (serial_rx_count++ > serial_rx_loop_max) break; - } - } else { - if (current_terminal_2 == FRSER_TERM || current_terminal_2 == FRSER_TERM2) { - while(SerialUSB2.available() > 0) { - frser_operation(SerialUSB2.read()); - } - } - } -} -//#define DAP_DEBUG - -void loop() { - // put your main code here, to run repeatedly: - // - - handle_serial(); - - auto bytesAvailable = RawHID.recv(rawhidRequest, 0); - if (bytesAvailable > 0) { - - #ifdef DAP_DEBUG - Serial.print("dap "); - Serial.print(rawhidRequest[0], HEX); - Serial.print(" "); - Serial.print(rawhidRequest[1], HEX); - Serial.print(" "); - #endif /* DAP_DEBUG */ - - auto sz = DAP_ProcessCommand(rawhidRequest, rawhidResponse); - - #ifdef DAP_DEBUG - Serial.print("rsp "); - Serial.print(sz, HEX); - Serial.println(" B"); - #endif /* DAP_DEBUG */ - - if (sz > 0) { - RawHID.send(rawhidResponse, 100); - } - } - //only print interrupt status updates max 10hz - if (pin_interrupt_state.active && millis() > (pin_interrupt_state.last_update + 100)){ - pin_interrupt_state.last_update = millis(); - for (size_t i = 0; i < CORE_NUM_INTERRUPT; i++){ - if (pin_interrupt_state.isr_count[i] != pin_interrupt_state.handler_count[i]){ - Serial.print("pin "); - Serial.print(i); - Serial.print(" changed "); - Serial.print(pin_interrupt_state.isr_count[i] - pin_interrupt_state.handler_count[i]); - Serial.println(" times"); - pin_interrupt_state.handler_count[i] = pin_interrupt_state.isr_count[i]; - } - } - } - - /* Print power readings */ - if (ina260config_t.continuious != 0 && (millis() > (ina260config_t.last_update + ina260config_t.continuious))) { - ina260config_t.last_update = millis(); - printina230(&Serial); - } - -} - - -CLI_COMMAND(resetFunc) { - pinMode(BUTTON_HOST_RESET, OUTPUT_OPENDRAIN); - digitalWrite(BUTTON_HOST_RESET, LOW); - delay(500); - digitalWrite(BUTTON_HOST_RESET, HIGH); - pinMode(BUTTON_HOST_RESET, INPUT); - dev->println("reset complete"); - - return 0; -} - - -CLI_COMMAND(powerFunc) { - pinMode(BUTTON_HOST_POWER, OUTPUT_OPENDRAIN); - digitalWrite(BUTTON_HOST_POWER, LOW); - delay(1000); - digitalWrite(BUTTON_HOST_POWER, HIGH); - dev->println("power complete"); - - return 0; -} - -CLI_COMMAND(termFunc) { - if (argc != 3) { - dev->print("Usage: term vcpid(1,2) id(1=hw port 1, 2=hw port 2 ... N=hw port N | "); - - dev->print(FRSER_TERM); - dev->print("=flashrom) "); -#ifdef ARDUINO_TEENSY41 - dev->print(FRSER_TERM2); - dev->print("=flashrom (Teensy4.1 onboard QSPI header))"); -#endif - dev->println(); - return 10; - } - int term = atoi(argv[2]); - int usb_term = atoi(argv[1]); - if (usb_term == 1){ - current_terminal_1 = term; - term1_baud = 0; - dev->print("ACM1 Set to HW Uart "); - dev->println(term); - - }else if (usb_term == 2){ - if (current_terminal_2 != term && current_terminal_2 == FRSER_TERM) { - dev->println("Disabling frser spi pins"); - //make sure flashrom pins are disabled (spi) - pinMode(SPI_WP, INPUT); - pinMode(SPI_MOSI, INPUT); - pinMode(SPI_MISO, INPUT); - pinMode(SPI_SCK, INPUT); - pinMode(SPI_CS, INPUT); -#ifdef ARDUINO_TEENSY40 - pinMode(SPI1_DO, INPUT); - pinMode(SPI1_DI, INPUT); - pinMode(SPI1_SCK, INPUT); - pinMode(SPI1_CS, INPUT); -#endif - } - current_terminal_2 = term; - term2_baud = 0; - if (term == FRSER_TERM){ - spi_set_port(0); - frser_init(); - } - if (term == FRSER_TERM2) { - spi_set_port(1); - frser_init(); - } - - dev->print("ACM2 Set to "); - switch(term){ - case 1: - dev->println("HW Uart 1"); - break; - case 2: - dev->println("HW Uart 2"); - break; - case 3: - dev->println("HW Uart 3"); - break; - case 4: - dev->println("HW Uart 4"); - break; - case 5: - dev->println("HW Uart 5"); - break; - case 6: - dev->println("HW Uart 6"); - break; - case FRSER_TERM: - dev->println("Serprog"); - break; - case FRSER_TERM2: - dev->println("Serprog Teensy Onboard Flash Header"); - break; - default: - dev->println("Invalid"); - break; - } - - }else{ - dev->println("Invalid usb terminal id "); - } - - return 0; -} - -CLI_COMMAND(swdFunc) { - if ((argc != 4) || (argc != 6) ) { - dev->println("Usage: swd swclk swdio nRESET [tdi tdo]"); - dev->println("Current Pin settings:"); - dev->print("\tswclk:"); - dev->println(pin_swclk); - dev->print("\tswdio:"); - dev->println(pin_swdio); - dev->print("\tnRESET:"); - dev->println(pin_nreset); - dev->print("\ttdi:"); - dev->println(pin_tdi); - dev->print("\ttdo:"); - dev->println(pin_tdo); - return 10; - } - //set all old values to input disabled: - pinMode(pin_swclk, INPUT); - pinMode(pin_swdio, INPUT); - pinMode(pin_nreset, INPUT); - pinMode(pin_tdi, INPUT); - pinMode(pin_tdo, INPUT); - - pin_swclk = atoi(argv[1]); - pin_swdio = atoi(argv[2]); - pin_nreset = atoi(argv[3]); - if (argc == 6) { - pin_tdi = atoi(argv[4]); - pin_tdo = atoi(argv[5]); - dev->println("tdi/tdo pins set\n"); - } - DAP_SETUP(); - dev->println("swd pins set\n"); - - return 0; -} - - -CLI_COMMAND(serialFunc) { - if (argc < 3) { - dev->println("Usage: serial port baud [txpin rxpin]"); - return 10; - } - int port = atoi(argv[1]); - int baudrate = atoi(argv[2]); - int txpin = -1; - int rxpin = -1; - HardwareSerial * hw = NULL; - - - hw = getPort(port); - if (hw) { - hw->begin(baudrate); - - dev->print("serial baud set to:"); - dev->print(baudrate); - - if (argc == 5) { - txpin= atoi(argv[3]); - rxpin = atoi(argv[4]); - - hw->setTX(txpin); - hw->setRX(rxpin); - - dev->print(" serial pin set TX:"); - dev->print(txpin); - dev->print(" RX:"); - dev->print(rxpin); - } - - } else { - dev->println("Invalid port"); - return 10; - } - - dev->println(); - - return 0; -} - -CLI_COMMAND(anaFunc) { - if (argc != 2) { - dev->println("Usage: ana pin"); - return 10; - } - int pin = atoi(argv[1]); - dev->print("pin "); - dev->print(pin); - dev->print("="); - dev->println(analogRead(pin)); - - - return 0; -} - -CLI_COMMAND(pinFunc) { - if (argc < 2) { - dev->println("Usage: pin pin 1|0 [in,inup,indown,out,opendrain]"); - for (int i=0; i<34; i++){ - dev->print("pin"); - dev->print(i); - dev->print("\t="); - dev->println((digitalRead(i) == HIGH) ? 1 : 0); - - } - return 10; - } - int pin = atoi(argv[1]); - - - dev->print("pin "); - dev->print(pin); - dev->print(" "); - if (argc >= 4) { - if (strcmp("disable",argv[3]) == 0){ - pinMode(pin, INPUT_DISABLE); - dev->print("disabled "); - } - if (strcmp("in",argv[3]) == 0){ - pinMode(pin, INPUT); - dev->print("input "); - } - if (strcmp("inup",argv[3]) == 0){ - pinMode(pin, INPUT_PULLUP); - dev->print("input pullup "); - } - if (strcmp("indown",argv[3]) == 0){ - pinMode(pin, INPUT_PULLDOWN); - dev->print("input pulldown "); - - } - if (strcmp("out",argv[3]) == 0){ - pinMode(pin, OUTPUT); - dev->print("output "); - - } - if (strcmp("opendrain",argv[3]) == 0){ - pinMode(pin, OUTPUT_OPENDRAIN); - dev->print("output opendrain "); - - } - } - if (argc >= 3) { - int state = atoi(argv[2]); - dev->print("set to "); - dev->print(state); - dev->print(" "); - - digitalWrite(pin, (state == 1) ? HIGH: LOW ); - } - if (argc >= 2) { - dev->print("="); - dev->println((digitalRead(pin) == HIGH) ? 1 : 0); - } - - return 0; -} - -CLI_COMMAND(helpFunc) { - dev->println("reset - toggle reset (pin 17) open drain"); - dev->println("power - toggle power (pin 16) open drain"); - dev->println("term vcpid(1,2) id(1=hw port 1, 2=hw port 2, 3=hw port 3 4=flashrom)"); - dev->println("serial port baud [txpin rxpin]"); - dev->println("ana pin"); - dev->println(" pin 15 - read analog value of pin 15"); - - dev->println("pin pin 1|0 [in,inup,indown,out,opendrain]"); - dev->println(" pin 10 - read digital value of pin 10"); - dev->println(" pin 10 1 out- Drive pin 10 high, set output"); - - dev->println("int[d] pin - enable or [d]isable notifications of pin change interrupt"); - - dev->println("i2c - perform i2c [r]ead [w]rite operations"); - dev->println(" i2c addr [w] hex_bytes [r] number of bytes"); - dev->println(" i2c clk frequency_hz"); - dev->println(" note you can string a sequence of reads/writes together:"); - dev->println(" i2c 10 w 0 r 2 will write 0, then read 2 bytes"); - - dev->println("swd swclk swdio nRESET [tdi tdo]"); - return 0; -} - -CLI_COMMAND(bootloaderFunc) { - -#if defined(ARDUINO_TEENSY31) || defined(ARDUINO_TEENSY36) - _reboot_Teensyduino_(); -#else - asm("bkpt #251"); -#endif - return 0; -} -#define CMD_MODE_IDLE 0 -#define CMD_MODE_READ 1 -#define CMD_MODE_WRITE 2 - -void print_i2c_status(auto dev, int status){ - switch(status){ - case 0: - break; - case 1: - dev->println("I2C Data too long"); - break; - case 2: - dev->println("I2C NAK On address"); - break; - case 3: - dev->println("I2C NAK on data"); - break; - default: - dev->println("I2C Unknown error"); - } -} -CLI_COMMAND(i2cFunc) { - int success = 0; - if (argc < 2) { - int error = 0; - dev->println("Usage: i2c addr [w] hex_bytes [r] number of bytes"); - dev->println("Usage: i2c clk frequency_hz"); - - dev->println("Devices"); - for (int hdr=0; hdr<0xf; hdr++){ - dev->print(hdr,HEX); - dev->print("\t"); - } - dev->println(); - for (int address=0; address<0x7f; address++){ - Wire.beginTransmission(address); - error = Wire.endTransmission(); - if (error == 0) { - dev->print(address,HEX); - dev->print("\t"); - } - else{ - dev->print("--\t"); - } - if ((address % 0x0f) == 0x0e){ - dev->println(); - } - } - dev->println(); - return 10; - } - - if (argc == 3){ - if (strcmp("clk",argv[1]) == 0){ - int speed = atoi(argv[2]); - Wire.setClock(speed); - dev->print("I2C Clock set to "); - dev->print(speed); - dev->println("Hz"); - } - } - uint8_t address = strtol(argv[1], 0, 16); - int cmd_mode = CMD_MODE_READ; - for(int cmd = 2; cmd < argc; cmd++){ - if (strcmp("r",argv[cmd]) == 0){ - if (cmd_mode == CMD_MODE_WRITE){ - success = Wire.endTransmission(false); - print_i2c_status(dev, success); - } - cmd_mode = CMD_MODE_READ; - if (cmd+1 < argc){ - int num_bytes = Wire.requestFrom(address, strtol(argv[cmd+1], 0, 16)); - while(Wire.available()){ - dev->print(Wire.read(), HEX); - dev->print(" "); - } - } - else { - dev->println("Invalid i2c r, missing number of bytes to read"); - return 10; - } - cmd++; - } - else if (strcmp("w",argv[cmd]) == 0){ - if (cmd_mode == CMD_MODE_WRITE){ - success = Wire.endTransmission(true); //send cached data - print_i2c_status(dev, success); - } - Wire.beginTransmission(address); - cmd_mode = CMD_MODE_WRITE; - } - else { - uint8_t data = strtol(argv[cmd], 0, 16); - if (cmd_mode == CMD_MODE_WRITE){ - Wire.write(data); - } - else { - dev->print(argv[cmd]); - dev->println(" - invalid command data"); - } - } - } - if (cmd_mode == CMD_MODE_WRITE){ - success = Wire.endTransmission(); //send cached data - print_i2c_status(dev, success); - } - dev->println(); - return 0; -} - - -CLI_COMMAND(interruptFunc) { - if (argc != 2) { - dev->println("Usage: int pin"); - return 10; - } - int pin = atoi(argv[1]); - switch(pin){ - REGISTER_PIN_INTERRUPT(0); - REGISTER_PIN_INTERRUPT(1); - REGISTER_PIN_INTERRUPT(2); - REGISTER_PIN_INTERRUPT(3); - REGISTER_PIN_INTERRUPT(4); - REGISTER_PIN_INTERRUPT(5); - REGISTER_PIN_INTERRUPT(6); - REGISTER_PIN_INTERRUPT(7); - REGISTER_PIN_INTERRUPT(8); - REGISTER_PIN_INTERRUPT(9); - REGISTER_PIN_INTERRUPT(10); - REGISTER_PIN_INTERRUPT(11); - REGISTER_PIN_INTERRUPT(12); - REGISTER_PIN_INTERRUPT(13); - REGISTER_PIN_INTERRUPT(14); - REGISTER_PIN_INTERRUPT(15); - REGISTER_PIN_INTERRUPT(16); - REGISTER_PIN_INTERRUPT(17); - REGISTER_PIN_INTERRUPT(18); - REGISTER_PIN_INTERRUPT(19); - REGISTER_PIN_INTERRUPT(20); - REGISTER_PIN_INTERRUPT(21); - REGISTER_PIN_INTERRUPT(22); - REGISTER_PIN_INTERRUPT(23); - REGISTER_PIN_INTERRUPT(24); - REGISTER_PIN_INTERRUPT(25); - REGISTER_PIN_INTERRUPT(26); - REGISTER_PIN_INTERRUPT(27); - REGISTER_PIN_INTERRUPT(28); - REGISTER_PIN_INTERRUPT(29); - REGISTER_PIN_INTERRUPT(30); - REGISTER_PIN_INTERRUPT(31); - REGISTER_PIN_INTERRUPT(32); - REGISTER_PIN_INTERRUPT(33); - } - dev->print("Registering pin change notification on "); - dev->println(pin); - pin_interrupt_state.active = true; - return 0; -} - - -CLI_COMMAND(interruptdisFunc) { - if (argc != 2) { - dev->println("Usage: intd pin"); - return 10; - } - int pin = atoi(argv[1]); - detachInterrupt(digitalPinToInterrupt(pin)); - dev->print("Unregistering pin change notification on "); - dev->println(pin); - return 0; -} - -int ina260reg(int address, int reg, int writeVal = -1) { - uint32_t result = 0; - int success = 0; - Wire.beginTransmission(address); - Wire.write(reg); - if (writeVal != -1) { - Wire.write((writeVal >> 8) & 0xFF); - Wire.write(writeVal & 0xFF); - } - success = Wire.endTransmission(writeVal != -1); - print_i2c_status(&Serial, success); - if (writeVal == -1) { - int num_bytes = Wire.requestFrom(address, 2); - while(Wire.available()){ - result = (result << 8) + Wire.read(); - } - success = Wire.endTransmission(true); - print_i2c_status(&Serial, success); - - } - return result; -} - -void printina230(auto dev) { - int ret = 0; - float voltage = 0; - float current = 0; - float power = 0; - voltage = ina260reg(ina260config_t.address, INA260_BUSVOLTAGE); - voltage *= 1.25; - - current = ina260reg(ina260config_t.address, INA260_CURRENT); - current *= 1.25; - - power = ina260reg(ina260config_t.address, INA260_POWER); - power *= 10; - - dev->print("ina260 Voltage:\t"); - dev->print(voltage); - dev->print("\tCurrent:\t"); - dev->print(current); - dev->print("\tPower:\t"); - dev->println(power); -} - -CLI_COMMAND(ina260Func) { - int ret = 0; - if (argc < 2) { - dev->println("Usage: ina260 i2caddr "); - - } - uint8_t address = strtol(argv[1], NULL, 16); - ina260config_t.address = address; - ret = ina260reg(address, MFG_ID); - if (ret != 0x5449) { - dev->println("Did not detect INA260"); - } - printina230(dev); - if (argc >= 3) { - ina260config_t.continuious = strtol(argv[2], NULL, 0); - } - - return 0; -} diff --git a/teensy/src/main.h b/teensy/src/main.h deleted file mode 100644 index 5080617..0000000 --- a/teensy/src/main.h +++ /dev/null @@ -1,5 +0,0 @@ -#include -#include "DAP_config.h" -#include "DAP.h" -#include -#include "IO_Config.h" \ No newline at end of file diff --git a/teensy/src/teensy_usb_descriptor_override.c b/teensy/src/teensy_usb_descriptor_override.c deleted file mode 100644 index 79d4b56..0000000 --- a/teensy/src/teensy_usb_descriptor_override.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "usb_names.h" - -#define PRODUCT_NAME {'C','M','S','I','S','-','D','A','P'} -#define PRODUCT_NAME_LEN 9 - -struct usb_string_descriptor_struct usb_string_product_name = { - 2 + PRODUCT_NAME_LEN * 2, - 3, - PRODUCT_NAME -}; - - #define MANUFACTURER_NAME {'F','r','a','m','e','w','o','r','k'} - #define MANUFACTURER_NAME_LEN 9 - -struct usb_string_descriptor_struct usb_string_manufacturer_name = { - 2 + MANUFACTURER_NAME_LEN * 2, - 3, - MANUFACTURER_NAME -}; \ No newline at end of file diff --git a/teensy/src/uart.h b/teensy/src/uart.h deleted file mode 100644 index 639c494..0000000 --- a/teensy/src/uart.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @file uart.h - * @brief - * - * DAPLink Interface Firmware - * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef UART_H -#define UART_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Parity enumerator */ -typedef enum { - UART_PARITY_NONE = 0, - UART_PARITY_ODD = 1, - UART_PARITY_EVEN = 2, - UART_PARITY_MARK = 3, - UART_PARITY_SPACE = 4 -} UART_Parity; - -/* Stop Bits enumerator */ -typedef enum { - UART_STOP_BITS_1 = 0, - UART_STOP_BITS_1_5 = 1, - UART_STOP_BITS_2 = 2 -} UART_StopBits; - -/* Data Bits enumerator */ -typedef enum { - UART_DATA_BITS_5 = 5, - UART_DATA_BITS_6 = 6, - UART_DATA_BITS_7 = 7, - UART_DATA_BITS_8 = 8, - UART_DATA_BITS_16 = 16 -} UART_DataBits; - -/* Flow control enumerator */ -typedef enum { - UART_FLOW_CONTROL_NONE = 0, - UART_FLOW_CONTROL_RTS_CTS = 1, - UART_FLOW_CONTROL_XON_XOFF = 2 -} UART_FlowControl; - -/* UART Port Properties structure */ -typedef struct { - uint32_t Baudrate; - UART_DataBits DataBits; - UART_Parity Parity; - UART_StopBits StopBits; - UART_FlowControl FlowControl; -} UART_Configuration; - -/*----------------------------------------------------------------------------- - * FUNCTION PROTOTYPES - *----------------------------------------------------------------------------*/ - -/* UART driver function prototypes */ -extern int32_t uart_initialize(void); -extern int32_t uart_uninitialize(void); -extern int32_t uart_reset(void); -extern int32_t uart_set_configuration(UART_Configuration *config); -extern int32_t uart_get_configuration(UART_Configuration *config); -extern int32_t uart_write_free(void); -extern int32_t uart_write_data(uint8_t *data, uint16_t size); -extern int32_t uart_read_data(uint8_t *data, uint16_t size); -extern void uart_set_control_line_state(uint16_t ctrl_bmp); -extern void uart_software_flow_control(void); -extern void uart_enable_flow_control(bool enabled); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/teensy/terminal.py b/teensy/terminal.py deleted file mode 100644 index e943290..0000000 --- a/teensy/terminal.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python3 -#requires pyusb - -import usb.core -import usb.util -import argparse -import os -import sys -import tty -import termios -import threading - - -class Terminal(object): - def __init__(self, devicepath): - - self.devicepath = devicepath - #self.rawhid = open(self.devicepath, "r+b") - self.setup_hid() - self.fd = sys.stdin.fileno() - - - self.run = 1 - self.receiver_thread = threading.Thread(target=self.reader, name='reader') - self.transmitter_thread = threading.Thread(target=self.writer, name='transmitter') - - self.transmitter_thread.daemon = True - self.receiver_thread.daemon = True - - def setup_hid(self): - dev = usb.core.find(idVendor=0x16c0, idProduct=0x0486) - if dev is None: - raise ValueError('Device not found') - - # get an endpoint instance - for interface in dev.get_active_configuration(): - #if interface.bInterfaceNumber in [1,2]: - if dev.is_kernel_driver_active(interface.bInterfaceNumber): - # Detach kernel drivers and claim through libusb - dev.detach_kernel_driver(interface.bInterfaceNumber) - usb.util.claim_interface(dev, interface.bInterfaceNumber) - - dev.set_configuration() - self.dev = dev - - def runterminal(self): - self.setup_terminal() - self.receiver_thread.start() - - self.transmitter_thread.start() - - self.receiver_thread.join() - self.transmitter_thread.join() - - self.restore_terminal() - print("\r\n") - - def setup_terminal(self): - self.old_settings = termios.tcgetattr(self.fd) - tty.setraw(self.fd) - - def restore_terminal(self): - tty.tcsetattr(self.fd, termios.TCSANOW, self.old_settings) - - - def reader(self): - while self.run: - data = sys.stdin.buffer.read(1) - #print ("{:02x}\r\n".format(data[0])) - if data == b'~': - self.run = 0 - output = bytearray(64) - output[0] = data[0] - self.dev.write(0x02,data) - - def writer(self): - while self.run: - data = [] - sret = "" - try: - data = self.dev.read(0x81, 64, 1000) - sret = ''.join([chr(x) for x in data]).strip('\0') - except: - pass - - sys.stdout.buffer.write(sret.encode('utf-8', errors='backslashreplace')) - sys.stdout.buffer.flush() - -if __name__ == '__main__': - t = Terminal(None) - - t.runterminal() - sys.exit() diff --git a/teensy/test/README b/teensy/test/README deleted file mode 100644 index df5066e..0000000 --- a/teensy/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PIO Unit Testing and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PIO Unit Testing: -- https://docs.platformio.org/page/plus/unit-testing.html