Skip to content

Commit c0ca645

Browse files
authored
Merge pull request #13063 from liugang-gavin/feature-wisun
[feature-wisun] targets:lpspi and uart_3: Update the lpspi driver and add uart_3 support
2 parents 72fa02d + a22f596 commit c0ca645

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_IMX/spi_api.c

100644100755
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,21 @@ int spi_master_write(spi_t *obj, int value)
123123
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
124124
char *rx_buffer, int rx_length, char write_fill) {
125125
int total = (tx_length > rx_length) ? tx_length : rx_length;
126+
int ret;
126127

127128
// Default write is done in each and every call, in future can create HAL API instead
128129
LPSPI_SetDummyData(spi_address[obj->instance], write_fill);
129130

130-
LPSPI_MasterTransferBlocking(spi_address[obj->instance], &(lpspi_transfer_t){
131-
.txData = (uint8_t *)tx_buffer,
132-
.rxData = (uint8_t *)rx_buffer,
133-
.dataSize = total,
134-
.configFlags = kLPSPI_MasterPcs0 | kLPSPI_MasterPcsContinuous | kLPSPI_SlaveByteSwap,
135-
});
131+
do
132+
{
133+
ret = LPSPI_MasterTransferBlocking(spi_address[obj->instance], &(lpspi_transfer_t){
134+
.txData = (uint8_t *)tx_buffer,
135+
.rxData = (uint8_t *)rx_buffer,
136+
.dataSize = total,
137+
.configFlags = kLPSPI_MasterPcs0 | kLPSPI_MasterPcsContinuous | kLPSPI_SlaveByteSwap,
138+
});
139+
140+
} while((ret == kStatus_LPSPI_Busy));
136141

137142
return total;
138143
}

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/TARGET_EVK/PeripheralPins.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ const PinMap PinMap_I2C_SCL[] = {
5151
/************UART***************/
5252
const PinMap PinMap_UART_TX[] = {
5353
{GPIO_AD_B0_12, UART_1, 2},
54+
{GPIO_AD_B1_06, UART_3, 2},
5455
{NC , NC , 0}
5556
};
5657

5758
const PinMap PinMap_UART_RX[] = {
5859
{GPIO_AD_B0_13, UART_1, 2},
60+
{GPIO_AD_B1_07, UART_3, 2},
5961
{NC , NC , 0}
6062
};
6163

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_lpspi.c

100644100755
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ void LPSPI_MasterGetDefaultConfig(lpspi_master_config_t *masterConfig)
258258
masterConfig->cpha = kLPSPI_ClockPhaseFirstEdge;
259259
masterConfig->direction = kLPSPI_MsbFirst;
260260

261-
masterConfig->pcsToSckDelayInNanoSec = 1000000000 / masterConfig->baudRate * 2;
262-
masterConfig->lastSckToPcsDelayInNanoSec = 1000000000 / masterConfig->baudRate * 2;
263-
masterConfig->betweenTransferDelayInNanoSec = 1000000000 / masterConfig->baudRate * 2;
261+
masterConfig->pcsToSckDelayInNanoSec = 80;
262+
masterConfig->lastSckToPcsDelayInNanoSec = 60;
263+
masterConfig->betweenTransferDelayInNanoSec = 160;
264264

265265
masterConfig->whichPcs = kLPSPI_Pcs0;
266266
masterConfig->pcsActiveHighOrLow = kLPSPI_PcsActiveLow;
@@ -871,14 +871,18 @@ status_t LPSPI_MasterTransferBlocking(LPSPI_Type *base, lpspi_transfer_t *transf
871871
{
872872
}
873873

874-
if (txData)
874+
/* To prevent rxfifo overflow, ensure transmitting and receiving are executed in parallel */
875+
if(((NULL == rxData) || (rxRemainingByteCount - txRemainingByteCount)/bytesEachRead < fifoSize))
875876
{
876-
wordToSend = LPSPI_CombineWriteData(txData, bytesEachWrite, isByteSwap);
877-
txData += bytesEachWrite;
878-
}
877+
if (txData)
878+
{
879+
wordToSend = LPSPI_CombineWriteData(txData, bytesEachWrite, isByteSwap);
880+
txData += bytesEachWrite;
881+
}
879882

880-
LPSPI_WriteData(base, wordToSend);
881-
txRemainingByteCount -= bytesEachWrite;
883+
LPSPI_WriteData(base, wordToSend);
884+
txRemainingByteCount -= bytesEachWrite;
885+
}
882886

883887
/*Check whether there is RX data in RX FIFO . Read out the RX data so that the RX FIFO would not overrun.*/
884888
if (rxData)

0 commit comments

Comments
 (0)