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.
0 commit comments