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