Skip to content

Commit 5eb2607

Browse files
Chris Reedc1728p9
authored andcommitted
Fix erroneous read of extra word in swd_read_block().
- Also replaced some literal constants with macros to improve readability.
1 parent 7101d42 commit 5eb2607

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

source/daplink/interface/swd_host.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,32 +298,32 @@ static uint8_t swd_read_block(uint32_t address, uint8_t *data, uint32_t size)
298298
}
299299

300300
// TAR write
301-
req = SWD_REG_AP | SWD_REG_W | (1 << 2);
301+
req = SWD_REG_AP | SWD_REG_W | AP_TAR;
302302
int2array(tmp_in, address, 4);
303303

304-
if (swd_transfer_retry(req, (uint32_t *)tmp_in) != 0x01) {
304+
if (swd_transfer_retry(req, (uint32_t *)tmp_in) != DAP_TRANSFER_OK) {
305305
return 0;
306306
}
307307

308308
// read data
309-
req = SWD_REG_AP | SWD_REG_R | (3 << 2);
309+
req = SWD_REG_AP | SWD_REG_R | AP_DRW;
310310

311-
// dummy read
312-
if (swd_transfer_retry(req, (uint32_t *)data) != 0x01) {
311+
// initiate first read, data comes back in next read
312+
if (swd_transfer_retry(req, NULL) != 0x01) {
313313
return 0;
314314
}
315315

316-
for (i = 0; i < size_in_words; i++) {
317-
if (swd_transfer_retry(req, (uint32_t *)data) != 0x01) {
316+
for (i = 0; i < (size_in_words - 1); i++) {
317+
if (swd_transfer_retry(req, (uint32_t *)data) != DAP_TRANSFER_OK) {
318318
return 0;
319319
}
320320

321321
data += 4;
322322
}
323323

324-
// dummy read
324+
// read last word
325325
req = SWD_REG_DP | SWD_REG_R | SWD_REG_ADR(DP_RDBUFF);
326-
ack = swd_transfer_retry(req, NULL);
326+
ack = swd_transfer_retry(req, (uint32_t *)data);
327327
return (ack == 0x01);
328328
}
329329

@@ -836,17 +836,17 @@ uint8_t swd_uninit_debug(void)
836836
// Assume debug is powered up already
837837
// Clear (CSYSPWRUPREQ | CDBGPWRUPREQ) in DP_CTRL_STAT register
838838
uint32_t ctrl_stat_read;
839-
839+
840840
if (!swd_write_dp(DP_CTRL_STAT, 0x0)) {
841841
return 0;
842842
}
843-
843+
844844
do {
845845
if (!swd_read_dp(DP_CTRL_STAT, &ctrl_stat_read)) {
846846
return 0;
847847
}
848848
} while ((ctrl_stat_read & (CSYSPWRUPREQ | CDBGPWRUPREQ)));
849-
849+
850850
return 1;
851851
}
852852

0 commit comments

Comments
 (0)