Skip to content

Commit e352f1b

Browse files
committed
k64f: Added SPI block write using DSPI_MasterTransferBlocking
performance improvements: naive block writes 3.997Mbps DSPI block writes 17.809Mbps
1 parent c1de19e commit e352f1b

File tree

1 file changed

+8
-7
lines changed
  • targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F

1 file changed

+8
-7
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ int spi_master_write(spi_t *obj, int value)
130130
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) {
131131
int total = (tx_length > rx_length) ? tx_length : rx_length;
132132

133-
for (int i = 0; i < total; i++) {
134-
char out = (i < tx_length) ? tx_buffer[i] : 0xff;
135-
char in = spi_master_write(obj, out);
136-
if (i < rx_length) {
137-
rx_buffer[i] = in;
138-
}
139-
}
133+
DSPI_MasterTransferBlocking(spi_address[obj->spi.instance], &(dspi_transfer_t){
134+
.txData = (uint8_t *)tx_buffer,
135+
.rxData = (uint8_t *)rx_buffer,
136+
.dataSize = total,
137+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
138+
});
139+
140+
DSPI_ClearStatusFlags(spi_address[obj->spi.instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
140141

141142
return total;
142143
}

0 commit comments

Comments
 (0)