Skip to content

Commit a150d05

Browse files
committed
Merge branch 'release/winusb-V0.1'
2 parents e975818 + 810c11c commit a150d05

21 files changed

+1337
-793
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode/
22
build/
3+
tmp/

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
cmake_minimum_required(VERSION 3.5)
44
#set(COMPONENT_DIRS "${IDF_PATH}/components ${PROJECT_PATH}/components")
55

6+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/main)
7+
68
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
79
project(esp8266_dap)

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center"><img src="https://user-images.githubusercontent.com/17078589/73821108-300bda00-482e-11ea-89f6-011a50037a12.png"/></p>
22
<h1 align="center">Wireless ESP8266 DAP</h1>
33

4-
[![Build Status](https://travis-ci.com/windowsair/wireless-esp8266-dap.svg?branch=master)](https://travis-ci.com/windowsair/wireless-esp8266-dap) master
5-
[![Build Status](https://travis-ci.com/windowsair/wireless-esp8266-dap.svg?branch=develop)](https://travis-ci.com/windowsair/wireless-esp8266-dap) develop
4+
[![Build Status](https://github.com/windowsair/wireless-esp8266-dap/workflows/build/badge.svg?branch=master)](https://github.com/windowsair/wireless-esp8266-dap/actions?query=branch%3Amaster) master
5+
[![Build Status](https://github.com/windowsair/wireless-esp8266-dap/workflows/build/badge.svg?branch=develop)](https://github.com/windowsair/wireless-esp8266-dap/actions?query=branch%3Adevelop) develop
66

77
[![](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](https://github.com/windowsair/wireless-esp8266-dap/LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg?style=flat-square)](https://github.com/windowsair/wireless-esp8266-dap/pulls) [![%e2%9d%a4](https://img.shields.io/badge/made%20with-%e2%9d%a4-ff69b4.svg?style=flat-square)](https://github.com/windowsair/wireless-esp8266-dap)
88

@@ -32,8 +32,9 @@ Realized by USBIP and CMSIS-DAP protocol stack.
3232
- [ ] SWO Streaming Trace
3333

3434
4. More..
35-
- [x] Custom maximum debug clock ~~(more than 10MHz)~~ (experimental)
36-
- [ ] ...
35+
- [x] Custom maximum debug clock (40MHz, SWD only)
36+
- [x] SWD protocol based on SPI acceleration
37+
- [x] ...
3738

3839

3940

@@ -82,6 +83,14 @@ You can modify these pin definitions in [DAP_config.h](components/DAP/config/DAP
8283
8384
## Build
8485

86+
You can build locally or use Github Action to build online
87+
88+
### Build with Github Action Online
89+
90+
See: [Build with Github Action](https://github.com/windowsair/wireless-esp8266-dap/wiki/Build-with-Github-Action)
91+
92+
### General build
93+
8594
1. Get ESP8266 RTOS Software Development Kit
8695

8796
For now, use the 3.3-rc1 version of the SDK (this is a known issue)
@@ -117,14 +126,14 @@ python ./idf.py -p /dev/ttyS5 flash
117126
3. Connect it with usbip:
118127

119128
```bash
120-
# HID Mode
129+
# HID Mode only
121130
# for pre-compiled version on SourceForge
122131
# or usbip old version
123132
.\usbip.exe -D -a <your-esp8266-ip-address> 1-1
124133

125134
# HID Mode Or WinUSB Mode
126135
# for usbip-win 0.3.0 kmdf ude
127-
.\usbip.exe attach-ude -r <your-esp8266-ip-address> -b 1-1
136+
.\usbip.exe attach_ude -r <your-esp8266-ip-address> -b 1-1
128137

129138
```
130139

@@ -141,6 +150,8 @@ Then test it under MDK:
141150

142151
## Develop
143152

153+
0. Check other branches to know the latest development progress.
154+
144155
1. Use WinUSB Mode:
145156

146157
change `USE_WINUSB` macor in [USBd_config.h](components/USBIP/USBd_config.h)
@@ -153,16 +164,20 @@ Then test it under MDK:
153164
> - https://github.com/cezanne/usbip-win for usbip windows
154165
155166

156-
In this repo you can find the complete implementation of the USB protocol stack including USB-HID, WCID, WinUSB. Although WinUSB-based mode currently does not work on USBIP :disappointed_relieved: . They are very easy and can help you quickly build your own DAP on other hardware platforms.
167+
In this repo you can find the complete implementation of the USB protocol stack including USB-HID, WCID, WinUSB. ~~Although WinUSB-based mode currently does not work on USBIP~~ :disappointed_relieved: . They are very easy and can help you quickly build your own DAP on other hardware platforms.
157168

158169

159-
Currently using USB-HID for transmission is still slightly slower, If you have any ideas, welcome:
170+
Currently TCP transmission speed needs to be further improved, If you have any ideas, welcome:
160171
- [New issues](https://github.com/windowsair/wireless-esp8266-dap/issues)
161172
- [New pull](https://github.com/windowsair/wireless-esp8266-dap/pulls)
162173

163174

164175
### Issue
165176

177+
2020.12.1
178+
179+
TCP transmission speed needs to be further improved.
180+
166181
2020.11.11
167182

168183
Winusb is now available, but it is very slow.

components/DAP/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(COMPONENT_ADD_INCLUDEDIRS "config include $ENV{IDF_PATH}/components/esp8266/include/esp8266/ $ENV{IDF_PATH}//components/esp_ringbuf/include/")
2-
set(COMPONENT_SRCS "./source/DAP.c ./source/DAP_vendor.c ./source/JTAG_DP.c ./source/SW_DP.c ./source/SWO.c ./source/uart_modify.c")
2+
set(COMPONENT_SRCS "./source/DAP.c ./source/DAP_vendor.c ./source/JTAG_DP.c ./source/SW_DP.c ./source/SWO.c ./source/uart_modify.c ./source/spi_op.c ./source/spi_switch.c ./source/dap_utility.c")
3+
34

45

56
register_component()

components/DAP/config/DAP_config.h

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "timer_struct.h"
3737
#include "esp8266/pin_mux_register.h"
3838

39+
#include "spi_switch.h"
40+
#include "dap_configuration.h"
3941
//**************************************************************************************************
4042
/**
4143
\defgroup DAP_Config_Debug_gr CMSIS-DAP Debug Unit Information
@@ -64,7 +66,7 @@ This information includes:
6466
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<160MHz
6567

6668
// This value is used to replace the largest 10MHZ speed clock in Keil
67-
#define MAX_USER_CLOCK 10000000 ///< Specifies the max Debug Clock in Hz.
69+
#define MAX_USER_CLOCK 16000000 ///< Specifies the max Debug Clock in Hz.
6870

6971
/// Number of processor cycles for I/O Port write operations.
7072
/// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O
@@ -96,18 +98,11 @@ This information includes:
9698
#define DAP_DEFAULT_SWJ_CLOCK 1000000U ///< Default SWD/JTAG clock frequency in Hz.
9799
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<1MHz
98100

99-
/// Maximum Package Size for Command and Response data.
100-
/// This configuration settings is used to optimize the communication performance with the
101-
/// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB,
102-
/// 1024 for High-speed USB HID and 512 for High-speed USB WinUSB.
103-
#define DAP_PACKET_SIZE 255U ///< Specifies Packet Size in bytes.
104-
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<< 512 for High-speed USB WinUSB.
105-
106101
/// Maximum Package Buffers for Command and Response data.
107102
/// This configuration settings is used to optimize the communication performance with the
108103
/// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the
109104
/// setting can be reduced (valid range is 1 .. 255).
110-
#define DAP_PACKET_COUNT 20 ///< Specifies number of packets buffered.
105+
#define DAP_PACKET_COUNT 255 ///< Specifies number of packets buffered.
111106

112107
/// Indicate that UART Serial Wire Output (SWO) trace is available.
113108
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
@@ -189,12 +184,13 @@ __STATIC_INLINE uint8_t DAP_GetSerNumString(char *str)
189184
// Modify your pins here
190185

191186
// ATTENTION: DO NOT USE RTC GPIO16
192-
#define PIN_SWDIO 4
193-
#define PIN_SWCLK 5
194-
#define PIN_TDO 13
195-
#define PIN_TDI 12
187+
#define PIN_SWDIO 12
188+
#define PIN_SWDIO_MOSI 13 // SPI MOSI
189+
#define PIN_SWCLK 14
190+
#define PIN_TDO 4
191+
#define PIN_TDI 0
196192
#define PIN_nTRST 0 // optional
197-
#define PIN_nRESET 14
193+
#define PIN_nRESET 5
198194
// LED_BUILTIN
199195
#define PIN_LED_CONNECTED 2
200196
// LED_BUILTIN
@@ -300,18 +296,25 @@ __STATIC_INLINE void PORT_SWD_SETUP(void)
300296
{
301297
gpio_pin_reg_t pin_reg;
302298

303-
// gpio_set_direction(PIN_SWCLK, GPIO_MODE_OUTPUT);
304-
// gpio_set_direction(PIN_SWDIO, GPIO_MODE_OUTPUT);
305-
GPIO.enable_w1ts |= (0x1 << PIN_SWCLK);
306-
GPIO.pin[PIN_SWCLK].driver = 0;
307-
pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(PIN_SWCLK));
308-
pin_reg.pullup = 0;
309-
WRITE_PERI_REG(GPIO_PIN_REG(PIN_SWCLK), pin_reg.val);
310-
GPIO.enable_w1ts |= (0x1 << PIN_SWDIO);
311-
GPIO.pin[PIN_SWDIO].driver = 0;
312-
pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(PIN_SWDIO));
313-
pin_reg.pullup = 0;
314-
WRITE_PERI_REG(GPIO_PIN_REG(PIN_SWDIO), pin_reg.val);
299+
300+
// PIN_SWCLK -> OUTPUT
301+
// PIN_SWDIO -> OUTPUT
302+
// GPIO.enable_w1ts |= (0x1 << PIN_SWCLK);
303+
// GPIO.pin[PIN_SWCLK].driver = 0;
304+
// pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(PIN_SWCLK));
305+
// pin_reg.pullup = 0;
306+
// WRITE_PERI_REG(GPIO_PIN_REG(PIN_SWCLK), pin_reg.val);
307+
// GPIO.enable_w1ts |= (0x1 << PIN_SWDIO);
308+
// GPIO.pin[PIN_SWDIO].driver = 0;
309+
// pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(PIN_SWDIO));
310+
// pin_reg.pullup = 0;
311+
// WRITE_PERI_REG(GPIO_PIN_REG(PIN_SWDIO), pin_reg.val);
312+
313+
DAP_SPI_Disable();
314+
GPIO.out_w1tc |= (0x1 << PIN_SWCLK);
315+
GPIO.out_w1ts |= (0x1 << PIN_SWDIO_MOSI);
316+
317+
315318

316319
// gpio_set_direction(PIN_TDO, GPIO_MODE_DEF_INPUT);
317320
GPIO.enable_w1tc |= (0x1 << PIN_TDO);
@@ -360,11 +363,18 @@ __STATIC_INLINE void PORT_OFF(void)
360363

361364
// gpio_set_direction(PIN_nTRST, GPIO_MODE_DEF_DISABLE);
362365
// gpio_set_direction(PIN_nRESET, GPIO_MODE_DEF_DISABLE);
363-
GPIO.pin[PIN_SWCLK].driver = 0;
364-
GPIO.enable_w1tc |= (0x1 << PIN_SWCLK);
366+
// GPIO.pin[PIN_SWCLK].driver = 0;
367+
// GPIO.enable_w1tc |= (0x1 << PIN_SWCLK);
365368

366-
GPIO.pin[PIN_SWDIO].driver = 0;
367-
GPIO.enable_w1tc |= (0x1 << PIN_SWDIO);
369+
// GPIO.pin[PIN_SWDIO].driver = 0;
370+
// GPIO.enable_w1tc |= (0x1 << PIN_SWDIO);
371+
372+
// GPIO.pin[PIN_SWDIO].driver = 0;
373+
// GPIO.enable_w1tc |= (0x1 << PIN_SWDIO_MOSI);
374+
DAP_SPI_Disable();
375+
GPIO.out_w1tc |= (0x1 << PIN_SWCLK);
376+
GPIO.out_w1ts |= (0x1 << PIN_SWDIO_MOSI);
377+
368378

369379
GPIO.pin[PIN_TDO].driver = 0;
370380
GPIO.enable_w1tc |= (0x1 << PIN_TDO);
@@ -431,7 +441,7 @@ __STATIC_FORCEINLINE uint32_t PIN_SWDIO_TMS_IN(void)
431441
*/
432442
__STATIC_FORCEINLINE void PIN_SWDIO_TMS_SET(void)
433443
{
434-
GPIO.out_w1ts |= (0x1 << PIN_SWDIO);
444+
GPIO.out_w1ts |= (0x1 << PIN_SWDIO_MOSI);
435445
}
436446

437447
/**
@@ -441,7 +451,7 @@ __STATIC_FORCEINLINE void PIN_SWDIO_TMS_SET(void)
441451
*/
442452
__STATIC_FORCEINLINE void PIN_SWDIO_TMS_CLR(void)
443453
{
444-
GPIO.out_w1tc |= (0x1 << PIN_SWDIO);
454+
GPIO.out_w1tc |= (0x1 << PIN_SWDIO_MOSI);
445455
}
446456

447457
/**
@@ -470,13 +480,13 @@ __STATIC_FORCEINLINE void PIN_SWDIO_OUT(uint32_t bit)
470480
if ((bit & 1U) == 1)
471481
{
472482
//set bit
473-
GPIO.out_w1ts |= (0x1 << PIN_SWDIO);
483+
GPIO.out_w1ts |= (0x1 << PIN_SWDIO_MOSI);
474484

475485
}
476486
else
477487
{
478488
//reset bit
479-
GPIO.out_w1tc |= (0x1 << PIN_SWDIO);
489+
GPIO.out_w1tc |= (0x1 << PIN_SWDIO_MOSI);
480490

481491
}
482492
}
@@ -489,10 +499,12 @@ __STATIC_FORCEINLINE void PIN_SWDIO_OUT(uint32_t bit)
489499
__STATIC_FORCEINLINE void PIN_SWDIO_OUT_ENABLE(void)
490500
{
491501
// Need fast response
492-
502+
//// TODO: low speed
493503
// set \ref gpio_set_direction -> OUTPUT
494-
GPIO.enable_w1ts |= (0x1 << PIN_SWDIO);
495-
GPIO.pin[PIN_SWDIO].driver = 0;
504+
// GPIO.enable_w1ts |= (0x1 << PIN_SWDIO_MOSI);
505+
// GPIO.pin[PIN_SWDIO_MOSI].driver = 0;
506+
do {}while (0);
507+
496508
}
497509

498510
/**
@@ -505,8 +517,9 @@ __STATIC_FORCEINLINE void PIN_SWDIO_OUT_DISABLE(void)
505517
// Need fast response
506518
// set \ref gpio_set_dircetion -> INPUT
507519
// esp8266 input is always connected
508-
GPIO.enable_w1tc |= (0x1 << PIN_SWDIO);
509-
GPIO.pin[PIN_SWDIO].driver = 0;
520+
// GPIO.enable_w1tc |= (0x1 << PIN_SWDIO_MOSI);
521+
// GPIO.pin[PIN_SWDIO_MOSI].driver = 0;
522+
GPIO.out_w1ts |= (0x1 << PIN_SWDIO_MOSI);
510523
}
511524

512525
// TDI Pin I/O ---------------------------------------------
@@ -576,17 +589,7 @@ __STATIC_FORCEINLINE uint32_t PIN_nTRST_IN(void)
576589
*/
577590
__STATIC_FORCEINLINE void PIN_nTRST_OUT(uint32_t bit)
578591
{
579-
// ////TODO: What does this mean? ? ?
580-
// if ((bit & 1U) == 1)
581-
// {
582-
// //set bit
583-
// GPIO.out_w1ts |= (0x1 << PIN_nTRST);
584-
// }
585-
// else
586-
// {
587-
// //reset bit
588-
// GPIO.out_w1tc |= (0x1 << PIN_nTRST);
589-
// }
592+
// Vendor reset sequence
590593
; // not available
591594
}
592595

@@ -611,7 +614,8 @@ __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN(void)
611614
*/
612615
__STATIC_FORCEINLINE void PIN_nRESET_OUT(uint32_t bit)
613616
{
614-
////TODO: What does this mean? ? ?
617+
// Vendor reset sequence
618+
//// FIXME: unavailable
615619
if ((bit & 1U) == 1)
616620
{
617621
//set bit
@@ -733,9 +737,13 @@ Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled an
733737
*/
734738
__STATIC_INLINE void DAP_SETUP(void)
735739
{
740+
DAP_SPI_Init();
741+
DAP_SPI_Disable();
742+
743+
736744
// This function maybe unnecessary...
737-
gpio_set_direction(PIN_SWCLK, GPIO_MODE_DEF_INPUT);
738-
gpio_set_direction(PIN_SWDIO, GPIO_MODE_DEF_INPUT); //
745+
// gpio_set_direction(PIN_SWCLK, GPIO_MODE_DEF_INPUT);
746+
// gpio_set_direction(PIN_SWDIO, GPIO_MODE_DEF_INPUT); //
739747
gpio_set_direction(PIN_nRESET, GPIO_MODE_DEF_INPUT); //
740748
gpio_set_direction(PIN_TDI, GPIO_MODE_DEF_INPUT);
741749
gpio_set_direction(PIN_TDO, GPIO_MODE_DEF_INPUT);
@@ -745,6 +753,8 @@ __STATIC_INLINE void DAP_SETUP(void)
745753
LED_CONNECTED_OUT(0);
746754
gpio_set_direction(PIN_LED_RUNNING, GPIO_MODE_DEF_OUTPUT);
747755
LED_RUNNING_OUT(0);
756+
757+
PORT_OFF();
748758
}
749759

750760
/** Reset Target Device with custom specific I/O pin or command sequence.

components/DAP/include/cmsis_compiler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef __STATIC_INLINE
88
#define __STATIC_INLINE static inline __attribute__((always_inline))
99
#endif
10+
#ifndef __FORCEINLINE
11+
#define __FORCEINLINE inline __attribute__((always_inline))
12+
#endif
1013
#ifndef __WEAK
1114
#define __WEAK __attribute__((weak))
1215
#endif
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef __DAP_UTILITY_H__
2+
#define __DAP_UTILITY_H__
3+
4+
#include <stdint.h>
5+
6+
#ifndef __STATIC_FORCEINLINE
7+
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
8+
#endif
9+
#ifndef __STATIC_INLINE
10+
#define __STATIC_INLINE static inline __attribute__((always_inline))
11+
#endif
12+
#ifndef __WEAK
13+
#define __WEAK __attribute__((weak))
14+
#endif
15+
16+
17+
extern const uint8_t kParityByteTable[256];
18+
19+
__STATIC_FORCEINLINE uint8_t ParityEvenUint32(uint32_t v)
20+
{
21+
v ^= v >> 16;
22+
v ^= v >> 8;
23+
v ^= v >> 4;
24+
v &= 0xf;
25+
return (0x6996 >> v) & 1;
26+
}
27+
28+
__STATIC_FORCEINLINE uint8_t ParityEvenUint8(uint8_t v)
29+
{
30+
return kParityByteTable[v];
31+
}
32+
33+
#endif

0 commit comments

Comments
 (0)