Skip to content

Commit 5ec463c

Browse files
committed
feat: Support 3-wire spi
1 parent 8429361 commit 5ec463c

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

components/DAP/source/spi_op.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
* @brief Using SPI for common transfer operations
55
* @change: 2020-11-25 first version
66
* 2021-2-11 Support SWD sequence
7-
* @version 0.2
8-
* @date 2021-2-11
7+
* 2021-3-10 Support 3-wire SPI
8+
* @version 0.3
9+
* @date 2021-3-10
910
*
1011
* @copyright Copyright (c) 2021
1112
*
1213
*/
1314
#include <stdio.h>
15+
#include <stdbool.h>
1416

1517
#include "esp8266/spi_struct.h"
1618
#include "cmsis_compiler.h"
1719
#include "spi_op.h"
20+
#include "dap_configuration.h"
1821

1922
#define DAP_SPI SPI1
2023

@@ -103,13 +106,21 @@ void DAP_SPI_ReadBits(const uint8_t count, uint8_t *buf) {
103106
DAP_SPI.user.usr_mosi = 0;
104107
DAP_SPI.user.usr_miso = 1;
105108

109+
#if (USE_SPI_SIO == 1)
110+
DAP_SPI.user.sio = true;
111+
#endif
112+
106113
DAP_SPI.user1.usr_miso_bitlen = count - 1U;
107114

108115
// Start transmission
109116
DAP_SPI.cmd.usr = 1;
110117
// Wait for reading to complete
111118
while (DAP_SPI.cmd.usr) continue;
112119

120+
#if (USE_SPI_SIO == 1)
121+
DAP_SPI.user.sio = false;
122+
#endif
123+
113124
data_buf[0] = DAP_SPI.data_buf[0];
114125
data_buf[1] = DAP_SPI.data_buf[1];
115126

@@ -139,6 +150,10 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
139150

140151
DAP_SPI.user.usr_miso = 1;
141152

153+
#if (USE_SPI_SIO == 1)
154+
DAP_SPI.user.sio = true;
155+
#endif
156+
142157
// 1 bit Trn(Before ACK) + 3bits ACK + TrnAferACK - 1(prescribed)
143158
DAP_SPI.user1.usr_miso_bitlen = 1U + 3U + TrnAfterACK - 1U;
144159

@@ -150,6 +165,10 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
150165
// Wait for sending to complete
151166
while (DAP_SPI.cmd.usr) continue;
152167

168+
#if (USE_SPI_SIO == 1)
169+
DAP_SPI.user.sio = false;
170+
#endif
171+
153172
dataBuf = DAP_SPI.data_buf[0];
154173
*ack = (dataBuf >> 1) & 0b111;
155174
}
@@ -169,6 +188,10 @@ __FORCEINLINE void DAP_SPI_Read_Data(uint32_t *resData, uint8_t *resParity)
169188
DAP_SPI.user.usr_mosi = 0;
170189
DAP_SPI.user.usr_miso = 1;
171190

191+
#if (USE_SPI_SIO == 1)
192+
DAP_SPI.user.sio = true;
193+
#endif
194+
172195
// 1 bit Trn(End) + 3bits ACK + 32bis data + 1bit parity - 1(prescribed)
173196
DAP_SPI.user1.usr_miso_bitlen = 1U + 32U + 1U - 1U;
174197

@@ -177,6 +200,10 @@ __FORCEINLINE void DAP_SPI_Read_Data(uint32_t *resData, uint8_t *resParity)
177200
// Wait for sending to complete
178201
while (DAP_SPI.cmd.usr) continue;
179202

203+
#if (USE_SPI_SIO == 1)
204+
DAP_SPI.user.sio = false;
205+
#endif
206+
180207
pU32Data[0] = DAP_SPI.data_buf[0];
181208
pU32Data[1] = DAP_SPI.data_buf[1];
182209

components/DAP/source/spi_switch.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "cmsis_compiler.h"
2020
#include "spi_switch.h"
21+
#include "dap_configuration.h"
2122

2223

2324
#define DAP_SPI SPI1
@@ -106,11 +107,13 @@ void DAP_SPI_Init()
106107
pin_reg.pullup = 0;
107108
WRITE_PERI_REG(GPIO_PIN_REG(13), pin_reg.val);
108109

110+
#if (USE_SPI_SIO != 1)
109111
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_HSPIQ_MISO); // GPIO12 is SPI MISO pin (Master Data In)
110112
// esp8266 in is always connected
111113
pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(12));
112114
pin_reg.pullup = 0;
113115
WRITE_PERI_REG(GPIO_PIN_REG(12), pin_reg.val);
116+
#endif // (USE_SPI_SIO != 1)
114117

115118

116119

@@ -136,10 +139,12 @@ __FORCEINLINE void DAP_SPI_Deinit()
136139
{
137140
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14);
138141
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); // MOSI
142+
#if (USE_SPI_SIO != 1)
139143
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); // MISO
140144

141145
// disable MISO output connect
142146
GPIO.enable_w1tc |= (0x1 << 12);
147+
#endif // (USE_SPI_SIO != 1)
143148

144149
gpio_pin_reg_t pin_reg;
145150
GPIO.enable_w1ts |= (0x1 << 13);

main/dap_configuration.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
/**
55
* @brief Specify the use of WINUSB
6-
*
6+
*
77
*/
88
#define USE_WINUSB 1
99

10+
/**
11+
* @brief Enable this option, no need to physically connect MOSI and MISO
12+
*
13+
*/
14+
#define USE_SPI_SIO 1
15+
1016
/// Maximum Package Size for Command and Response data.
1117
/// This configuration settings is used to optimize the communication performance with the
1218
/// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB,

0 commit comments

Comments
 (0)