DragonProbe/README.md

191 lines
9.0 KiB
Markdown
Raw Normal View History

2021-01-31 03:43:09 +00:00
## Dapper Mime
2021-02-01 16:01:11 +00:00
This unearths the name of a weekend project that I did in 2014. Both then and now, this is a port of [ARM's CMSIS-DAP code](https://github.com/arm-software/CMSIS_5) to a platform without the need for an expensive proprietary compiler and USB drivers.
2021-01-31 03:43:09 +00:00
Whereas the original code used ST's STM32 USB drivers, this new iteration uses [TinyUSB](https://github.com/hathach/tinyusb), an open source cross-platform USB stack for embedded systems.
## Variants
2021-02-04 23:17:56 +00:00
2021-02-19 17:31:18 +00:00
Most [TinyUSB supported MCUs](https://github.com/hathach/tinyusb/blob/master/docs/boards.md) can run this code; a subdirectory under bsp needs to be added for the "BOARD" name with a DAP_config.h to control the SWD/JTAG GPIOs and a unique.h to provide unique serial number (if any) and prefix to the USB product name.
Already added BOARD variants include:
For BOARD=raspberry_pi_pico, this project results in a standards-based CMSIS-DAP alternative to the approaches suggested in Chapter 5 and Appendix A of [Getting Started with Raspberry Pi Pico](https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf). This uses two RP2040 boards (see wiring loom shown in Figure 34 of Appendix A) where one RP2040 is the debugger and the other RP2040 is being debugged. The instructions in Chapter 5 apply, except no Raspberry Pi is needed.
Alternatively, a special one RP2040 “Raspberry Pi Pico” variant is [available here](https://github.com/majbthrd/pico-debug).
For BOARD=stm32f072disco, the inexpensive [32F072BDISCOVERY evaluation board](https://www.st.com/en/evaluation-tools/32f072bdiscovery.html) can be used as a CMSIS-DAP SWD debugger.
2021-02-04 23:17:56 +00:00
2021-01-31 03:43:09 +00:00
## Building
After initially downloading this project's code, issue the following command to download TinyUSB and CMSIS_5 code:
2021-01-31 03:43:09 +00:00
```
git submodule update --init --recursive
2021-01-31 03:43:09 +00:00
```
Follow the TinyUSB build instructions [available here](https://github.com/hathach/tinyusb/tree/master/docs), but issue the make command in the base directory of Dapper Mime.
Note that each TinyUSB board name being targeted needs a corresponding subdirectory under the Dapper Mime ./bsp/ subdirectory and a customized version of DAP_config.h for the target.
2021-01-31 03:43:09 +00:00
Alternatively, one can compile with CMake:
```
mkdir cmake-build && cd cmake-build
cmake -DBOARD=raspberry_pi_pico -DFAMILIY=rp2040 -DCMAKE_BUILD_TYPE=Debug ..
```
If you have the Pico SDK installed on your system, and the `PICO_SDK_PATH`
environment variable is specified properly, you can omit the `--recursive` flag
in the `git submodule` invocation (to avoid many many git clones), and pass
the `-DUSE_SYSTEMWIDE_PICOSDK=On` flag to CMake, too.
## Usage
2021-06-02 22:45:32 +00:00
These microcontrollers support the following protocols:
2021-06-02 22:48:28 +00:00
| MCU | SWD | JTAG | UART | SPI (flashrom) | I2C | AVR programming |
|:------ |:---:|:----:|:----:|:-------------- |:--- |:--------------- |
2021-06-08 00:32:06 +00:00
| RP2040 | X | X | X | X | Planned | Planned |
2021-06-02 22:48:28 +00:00
| STM32F072B Discovery | X | | X | | | |
2021-06-02 22:45:32 +00:00
2021-06-02 22:49:37 +00:00
The [original repository](https://github.com/majbthrd/DapperMime/) (Dapper
Mime) supported only SWD and UART, and worked for these two boards. This fork
focusses on adding more protocols, but the author of this fork only has a
Raspberry Pi Pico.
2021-06-02 22:45:32 +00:00
The pin mapping for the RP2040 is as follows:
| Pin number | Usage | Usage | Pin number |
|:---------- |:-------------- | --------------:| ----------:|
| GP0 | stdio UART TX | | VBUS |
| GP1 | stdio UART RX | | VSYS |
| GND | <ground> | <ground> | GND |
| GP2 | SWCLK/TCK | | 3V3 EN |
| GP3 | SWDIO/TMS | | 3V3 OUT |
| GP4 | UART TX | | ADC VREF |
| GP5 | UART RX | | GP28 / ADC2|
| GND | <ground> | <ground> | GND / AGND|
| GP6 | TDI | | GP27 / ADC1|
| GP7 | TDO | | GP26 / ADC0|
| GP8 | nTRST | | RUN |
| GP9 | nRESET | | GP22 |
| GND | <ground> | <ground> | GND |
| GP10 | UART CTS | SCL | GP21 |
| GP11 | UART RTS | SDA | GP20 |
| GP12 | MISO | | GP19 |
| GP13 | nCS | | GP18 |
| GND | <ground> | <ground> | GND |
| GP14 | SCLK | | GP17 |
| GP15 | MOSI | | GP16 |
| <end>| <bottom> | <bottom> | <end>|
2021-06-08 00:32:06 +00:00
On the RP2040, two USB CDC interfaces are exposed: the first is the UART
2021-06-12 19:55:09 +00:00
interface, the second is for Serprog. If you have no other USB-CDC intefaces,
2021-06-08 00:32:06 +00:00
these will be `/dev/ttyACM0` and `/dev/ttyACM1`, respectively.
The UART pins are for connecting to the device to be debugged, the data is
2021-05-31 10:51:07 +00:00
echoed back over the USB CDC interface (typically a `/dev/ttyACMx` device on
2021-06-12 19:55:09 +00:00
Linux). If you want to get stdio readout of this program on your computer,
connect GP0 to GP5, and GP1 to GP4, or alternatively, use the
`USE_USBCDC_FOR_STDIO` CMake flag, which adds an extra USB-CDC interface for
which stdio is used exclusively, while disabling stdio on the UART.
In SWD mode, the pin mapping is entirely as with the standard Picoprobe setup,
as described in Chapter 5 and Appendix A of [Getting Started with Raspberry Pi
Pico](https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf)
2021-06-02 22:45:32 +00:00
In JTAG mode, TCK and TMS have the same pins as SWCLK and SWDIO, respectively,
TDI and TDO are on the next two consecutive free pins.
In your OpenOCD flags, use `-f interface/cmsis-dap.cfg`. Default transport is
JTAG, if OpenOCD doesn't specify a default to the probe.
2021-06-08 00:32:06 +00:00
For Serprog, use the following `flashrom` options (if `/dev/ttyACM1` is the USB
serial device on your machine corresponding to the Serprog CDC interface of the
Pico):
```
flashrom -c <flashchip> -p serprog:dev=/dev/ttyACM1:115200 <rest of the read/write cmd>
```
Different serial speeds can be used, too. Serprog support is *techincally*
untested, as in it does output the correct SPI commands as seen by my logic
analyzer, but I don't have a SPI flash chip to test it on.
2021-06-12 19:55:09 +00:00
### Runtime configuration
Several settings can be applied at runtime, using the `dmctl` Python script.
Settings are communicated over the Serprog USB serial port.
The currently implemented options are:
- `ctsrts`: Enable/disable CTS/RTS-based hardware flow control for the UART port
```
usage: dmctl [-h] [-v] [--ctsrts [CTSRTS]] tty
Runtime configuration control for DapperMime-JTAG
positional arguments:
tty Path to DapperMime-JTAG Serprog UART device
optional arguments:
-h, --help show this help message and exit
-v, --verbose Verbose logging (for this utility)
--ctsrts [CTSRTS] Enable or disable CTS/RTS flow control (--ctsrts [true|false])
```
example:
```
$ ./dmctl.py /dev/ttyACM1 --ctsrts true
```
2021-01-31 03:43:09 +00:00
## License
TinyUSB is licensed under the [MIT license](https://opensource.org/licenses/MIT).
ARM's CMSIS_5 code is licensed under the [Apache 2.0 license](https://opensource.org/licenses/Apache-2.0).
2021-06-08 00:32:06 +00:00
libco is licensed under the [ISC license](https://opensource.org/licenses/ISC)
2021-06-02 22:45:32 +00:00
## TODO
- [x] CMSIS-DAP JTAG implementation
2021-06-08 00:32:06 +00:00
- [x] Flashrom/SPI support using Serprog
- [ ] Parallel ROM flashing support, too, by having the device switch into a
separate mode that temporarily disables all other IO protocols
2021-06-12 19:35:06 +00:00
- [x] UART with CTS/RTS flow control
- [x] Needs configurable stuff as well, as some UART interfaces won't use this.
- [x] Debug interface to send printf stuff directly to USB, instead of having
- to use the UART interface as a loopback thing.
2021-06-02 22:45:32 +00:00
- [ ] I2C support by emulating the I2C Tiny USB
- [ ] Expose RP2040-internal temperature ADC on I2C-over-USB bus?
- Does SMBus stuff need special treatment here?
2021-06-12 19:35:06 +00:00
- [ ] Host-side script that is an XVC (or hw_server) cable and communicates
with the device to perform the JTAG commands, because Vivado no likey
OpenOCD.
- CMSIS-DAP interface can be used directly, see CMSIS_5/CMSIS/DoxyGen/DAP/src/dap_USB_cmds.txt
- https://github.com/BerkeleyLab/XVC-FTDI-JTAG
- https://www.eevblog.com/forum/fpga/xilinx-jtag-and-tcf/
- https://git.eclipse.org/c/tcf/org.eclipse.tcf.git/plain/docs/TCF%20Linux%20Agent%20Prototype.html
- http://www.eclipse.org/tcf/
- https://debugmo.de/2012/02/xvcd-the-xilinx-virtual-cable-daemon/
- https://github.com/Xilinx/XilinxVirtualCable/
- https://github.com/derekmulcahy/xvcpi
- OpenOCD as XVC client??
- [ ] Maybe use the ADCs for something?
2021-06-02 22:45:32 +00:00
- [ ] AVR programming (USBavr emulation?)
- AVR ISP is hardly used anymore
- TPI/UPDI requires 5V levels, Pico doesn't do that :/
- debugWIRE????
- Renesas E7-{0,1,2} programming thing????
- Renesas tell us how this works pls
- Maybe steal other features from the Bus Pirate or Glasgow or so
- 1-wire? Never seen this one in the wild
- MIDI? Feels mostly gimmicky...
- PS/2? Hmmmm idk
- HD44780 LCD? See MIDI
- CAN? If I'd first be able to find a CAN device to test it with, sure
2021-06-02 22:45:32 +00:00