Skip to content

Commit 2a9c88c

Browse files
author
Deepika
committed
Use DSPI SDK driver API's in spi block read
1 parent 8a1c7fa commit 2a9c88c

File tree

1 file changed

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

1 file changed

+11
-7
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,17 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
131131
char *rx_buffer, int rx_length, char write_fill) {
132132
int total = (tx_length > rx_length) ? tx_length : rx_length;
133133

134-
for (int i = 0; i < total; i++) {
135-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
136-
char in = spi_master_write(obj, out);
137-
if (i < rx_length) {
138-
rx_buffer[i] = in;
139-
}
140-
}
134+
// Default write is done in each and every call, in future can create HAL API instead
135+
DSPI_SetDummyData(spi_address[obj->spi.instance], write_fill);
136+
137+
DSPI_MasterTransferBlocking(spi_address[obj->spi.instance], &(dspi_transfer_t){
138+
.txData = (uint8_t *)tx_buffer,
139+
.rxData = (uint8_t *)rx_buffer,
140+
.dataSize = total,
141+
.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous,
142+
});
143+
144+
DSPI_ClearStatusFlags(spi_address[obj->spi.instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag);
141145

142146
return total;
143147
}

0 commit comments

Comments
 (0)