4
4
* @brief Using SPI for common transfer operations
5
5
* @change: 2020-11-25 first version
6
6
* 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
9
10
*
10
11
* @copyright Copyright (c) 2021
11
12
*
12
13
*/
13
14
#include <stdio.h>
15
+ #include <stdbool.h>
14
16
15
17
#include "esp8266/spi_struct.h"
16
18
#include "cmsis_compiler.h"
17
19
#include "spi_op.h"
20
+ #include "dap_configuration.h"
18
21
19
22
#define DAP_SPI SPI1
20
23
@@ -103,13 +106,21 @@ void DAP_SPI_ReadBits(const uint8_t count, uint8_t *buf) {
103
106
DAP_SPI .user .usr_mosi = 0 ;
104
107
DAP_SPI .user .usr_miso = 1 ;
105
108
109
+ #if (USE_SPI_SIO == 1 )
110
+ DAP_SPI .user .sio = true;
111
+ #endif
112
+
106
113
DAP_SPI .user1 .usr_miso_bitlen = count - 1U ;
107
114
108
115
// Start transmission
109
116
DAP_SPI .cmd .usr = 1 ;
110
117
// Wait for reading to complete
111
118
while (DAP_SPI .cmd .usr ) continue ;
112
119
120
+ #if (USE_SPI_SIO == 1 )
121
+ DAP_SPI .user .sio = false;
122
+ #endif
123
+
113
124
data_buf [0 ] = DAP_SPI .data_buf [0 ];
114
125
data_buf [1 ] = DAP_SPI .data_buf [1 ];
115
126
@@ -139,6 +150,10 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
139
150
140
151
DAP_SPI .user .usr_miso = 1 ;
141
152
153
+ #if (USE_SPI_SIO == 1 )
154
+ DAP_SPI .user .sio = true;
155
+ #endif
156
+
142
157
// 1 bit Trn(Before ACK) + 3bits ACK + TrnAferACK - 1(prescribed)
143
158
DAP_SPI .user1 .usr_miso_bitlen = 1U + 3U + TrnAfterACK - 1U ;
144
159
@@ -150,6 +165,10 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
150
165
// Wait for sending to complete
151
166
while (DAP_SPI .cmd .usr ) continue ;
152
167
168
+ #if (USE_SPI_SIO == 1 )
169
+ DAP_SPI .user .sio = false;
170
+ #endif
171
+
153
172
dataBuf = DAP_SPI .data_buf [0 ];
154
173
* ack = (dataBuf >> 1 ) & 0b111 ;
155
174
}
@@ -169,6 +188,10 @@ __FORCEINLINE void DAP_SPI_Read_Data(uint32_t *resData, uint8_t *resParity)
169
188
DAP_SPI .user .usr_mosi = 0 ;
170
189
DAP_SPI .user .usr_miso = 1 ;
171
190
191
+ #if (USE_SPI_SIO == 1 )
192
+ DAP_SPI .user .sio = true;
193
+ #endif
194
+
172
195
// 1 bit Trn(End) + 3bits ACK + 32bis data + 1bit parity - 1(prescribed)
173
196
DAP_SPI .user1 .usr_miso_bitlen = 1U + 32U + 1U - 1U ;
174
197
@@ -177,6 +200,10 @@ __FORCEINLINE void DAP_SPI_Read_Data(uint32_t *resData, uint8_t *resParity)
177
200
// Wait for sending to complete
178
201
while (DAP_SPI .cmd .usr ) continue ;
179
202
203
+ #if (USE_SPI_SIO == 1 )
204
+ DAP_SPI .user .sio = false;
205
+ #endif
206
+
180
207
pU32Data [0 ] = DAP_SPI .data_buf [0 ];
181
208
pU32Data [1 ] = DAP_SPI .data_buf [1 ];
182
209
0 commit comments