Skip to content

Commit

Permalink
fix: 修复SWD模式下不同上位机导致的兼容性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfSweet committed Sep 7, 2024
1 parent 60ce7bd commit d52e0d9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions projects/HSLink-Pro/src/SW_DP/SW_DP_SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,21 @@ void SPI_SWJ_Sequence (uint32_t count, const uint8_t *data)
// printf("SWJ_Sequence %d\n", count);
gpio_write_pin(PIN_SWDIO_DIR_GPIO, GPIO_GET_PORT_INDEX(SWDIO_DIR), GPIO_GET_PIN_INDEX(SWDIO_DIR), 1);
spi_set_transfer_mode(SWD_SPI_BASE, spi_trans_write_only);
spi_set_data_bits(SWD_SPI_BASE, 8);
SWD_SPI_BASE->CTRL |= SPI_CTRL_RXFIFORST_MASK | SPI_CTRL_TXFIFORST_MASK;
while (SWD_SPI_BASE->STATUS & (SPI_CTRL_RXFIFORST_MASK | SPI_CTRL_TXFIFORST_MASK)) {
};
spi_set_write_data_count(SWD_SPI_BASE, integer_val);
SWD_SPI_BASE->CMD = 0xFF;
for (n = 0; n < integer_val; n++) {
SWD_SPI_BASE->DATA = *(data + n);
if (integer_val > 0)
{
spi_set_data_bits(SWD_SPI_BASE, 8);
spi_set_write_data_count(SWD_SPI_BASE, integer_val);
SWD_SPI_BASE->CMD = 0xFF;
for (n = 0; n < integer_val; n++) {
SWD_SPI_BASE->DATA = *(data + n);
}
while (SWD_SPI_BASE->STATUS & SPI_STATUS_SPIACTIVE_MASK) {
}
}
while (SWD_SPI_BASE->STATUS & SPI_STATUS_SPIACTIVE_MASK) {
};

if (remaind_val > 0) {
spi_set_write_data_count(SWD_SPI_BASE, 1);
spi_set_data_bits(SWD_SPI_BASE, remaind_val);
Expand Down Expand Up @@ -274,7 +278,11 @@ uint8_t SPI_SWD_Transfer(uint32_t request, uint32_t *data)
SWD_SPI_BASE->TRANSFMT = 0x0018; /* datalen = 1bit, mosibidir = 1, lsb=1 */
spi_set_write_data_count(SWD_SPI_BASE, DAP_Data.transfer.idle_cycles);
SWD_SPI_BASE->CMD = 0xFF;
SWD_SPI_BASE->DATA = 0;
for (int i = 0; i < DAP_Data.transfer.idle_cycles; i++) {
SWD_SPI_BASE->DATA = 0;
while ((SWD_SPI_BASE->STATUS & SPI_STATUS_TXFULL_MASK) == SPI_STATUS_TXFULL_MASK) {
};
}
while ((SWD_SPI_BASE->STATUS & SPI_STATUS_TXFULL_MASK) == SPI_STATUS_TXFULL_MASK) {
};
while (SWD_SPI_BASE->STATUS & SPI_STATUS_SPIACTIVE_MASK) {
Expand Down

0 comments on commit d52e0d9

Please sign in to comment.