Skip to content

Commit 5af80db

Browse files
committed
MCUXpresso Kinetis SPI drive: Add a delay between CS assertion and first sclk edge
1. FPGA test shield requires at least half sclk period delay between CS assertion and first sclk edge 2. Update Kinetis SPI drivers to match what is already done for K64F Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent a1540c5 commit 5af80db

File tree

7 files changed

+15
-17
lines changed

7 files changed

+15
-17
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/spi_api.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ void spi_free(spi_t *obj)
8080

8181
void spi_format(spi_t *obj, int bits, int mode, int slave)
8282
{
83-
8483
dspi_master_config_t master_config;
8584
dspi_slave_config_t slave_config;
8685

@@ -100,7 +99,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
10099
master_config.ctarConfig.cpol = (mode & 0x2) ? kDSPI_ClockPolarityActiveLow : kDSPI_ClockPolarityActiveHigh;
101100
master_config.ctarConfig.cpha = (mode & 0x1) ? kDSPI_ClockPhaseSecondEdge : kDSPI_ClockPhaseFirstEdge;
102101
master_config.ctarConfig.direction = kDSPI_MsbFirst;
103-
master_config.ctarConfig.pcsToSckDelayInNanoSec = 0;
102+
master_config.ctarConfig.pcsToSckDelayInNanoSec = 100;
104103

105104
DSPI_MasterInit(spi_address[obj->instance], &master_config, CLOCK_GetFreq(spi_clocks[obj->instance]));
106105
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/spi_api.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void spi_free(spi_t *obj)
6161

6262
void spi_format(spi_t *obj, int bits, int mode, int slave)
6363
{
64-
6564
dspi_master_config_t master_config;
6665
dspi_slave_config_t slave_config;
6766

@@ -81,7 +80,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
8180
master_config.ctarConfig.cpol = (mode & 0x2) ? kDSPI_ClockPolarityActiveLow : kDSPI_ClockPolarityActiveHigh;
8281
master_config.ctarConfig.cpha = (mode & 0x1) ? kDSPI_ClockPhaseSecondEdge : kDSPI_ClockPhaseFirstEdge;
8382
master_config.ctarConfig.direction = kDSPI_MsbFirst;
84-
master_config.ctarConfig.pcsToSckDelayInNanoSec = 0;
83+
master_config.ctarConfig.pcsToSckDelayInNanoSec = 100;
8584

8685
DSPI_MasterInit(spi_address[obj->instance], &master_config, CLOCK_GetFreq(spi_clocks[obj->instance]));
8786
}
@@ -95,7 +94,7 @@ void spi_frequency(spi_t *obj, int hz)
9594
DSPI_MasterSetDelayTimes(spi_address[obj->instance], kDSPI_Ctar0, kDSPI_LastSckToPcs, busClock, 500000000 / hz);
9695
}
9796

98-
static inline int spi_readable(spi_t * obj)
97+
static inline int spi_readable(spi_t *obj)
9998
{
10099
return (DSPI_GetStatusFlags(spi_address[obj->instance]) & kDSPI_RxFifoDrainRequestFlag);
101100
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/spi_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
8080
master_config.ctarConfig.cpol = (mode & 0x2) ? kDSPI_ClockPolarityActiveLow : kDSPI_ClockPolarityActiveHigh;
8181
master_config.ctarConfig.cpha = (mode & 0x1) ? kDSPI_ClockPhaseSecondEdge : kDSPI_ClockPhaseFirstEdge;
8282
master_config.ctarConfig.direction = kDSPI_MsbFirst;
83-
master_config.ctarConfig.pcsToSckDelayInNanoSec = 0;
83+
master_config.ctarConfig.pcsToSckDelayInNanoSec = 100;
8484

8585
DSPI_MasterInit(spi_address[obj->instance], &master_config, CLOCK_GetFreq(spi_clocks[obj->instance]));
8686
}
@@ -94,7 +94,7 @@ void spi_frequency(spi_t *obj, int hz)
9494
DSPI_MasterSetDelayTimes(spi_address[obj->instance], kDSPI_Ctar0, kDSPI_LastSckToPcs, busClock, 500000000 / hz);
9595
}
9696

97-
static inline int spi_readable(spi_t * obj)
97+
static inline int spi_readable(spi_t *obj)
9898
{
9999
return (DSPI_GetStatusFlags(spi_address[obj->instance]) & kDSPI_RxFifoDrainRequestFlag);
100100
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/spi_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
9999
master_config.ctarConfig.cpol = (mode & 0x2) ? kDSPI_ClockPolarityActiveLow : kDSPI_ClockPolarityActiveHigh;
100100
master_config.ctarConfig.cpha = (mode & 0x1) ? kDSPI_ClockPhaseSecondEdge : kDSPI_ClockPhaseFirstEdge;
101101
master_config.ctarConfig.direction = kDSPI_MsbFirst;
102-
master_config.ctarConfig.pcsToSckDelayInNanoSec = 0;
102+
master_config.ctarConfig.pcsToSckDelayInNanoSec = 100;
103103

104104
DSPI_MasterInit(spi_address[obj->instance], &master_config, CLOCK_GetFreq(spi_clocks[obj->instance]));
105105
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/spi_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
9999
master_config.ctarConfig.cpol = (mode & 0x2) ? kDSPI_ClockPolarityActiveLow : kDSPI_ClockPolarityActiveHigh;
100100
master_config.ctarConfig.cpha = (mode & 0x1) ? kDSPI_ClockPhaseSecondEdge : kDSPI_ClockPhaseFirstEdge;
101101
master_config.ctarConfig.direction = kDSPI_MsbFirst;
102-
master_config.ctarConfig.pcsToSckDelayInNanoSec = 0;
102+
master_config.ctarConfig.pcsToSckDelayInNanoSec = 100;
103103

104104
DSPI_MasterInit(spi_address[obj->instance], &master_config, CLOCK_GetFreq(spi_clocks[obj->instance]));
105105
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/spi_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
8080
master_config.ctarConfig.cpol = (mode & 0x2) ? kDSPI_ClockPolarityActiveLow : kDSPI_ClockPolarityActiveHigh;
8181
master_config.ctarConfig.cpha = (mode & 0x1) ? kDSPI_ClockPhaseSecondEdge : kDSPI_ClockPhaseFirstEdge;
8282
master_config.ctarConfig.direction = kDSPI_MsbFirst;
83-
master_config.ctarConfig.pcsToSckDelayInNanoSec = 0;
83+
master_config.ctarConfig.pcsToSckDelayInNanoSec = 100;
8484

8585
DSPI_MasterInit(spi_address[obj->instance], &master_config, CLOCK_GetFreq(spi_clocks[obj->instance]));
8686
}
@@ -94,7 +94,7 @@ void spi_frequency(spi_t *obj, int hz)
9494
DSPI_MasterSetDelayTimes(spi_address[obj->instance], kDSPI_Ctar0, kDSPI_LastSckToPcs, busClock, 500000000 / hz);
9595
}
9696

97-
static inline int spi_readable(spi_t * obj)
97+
static inline int spi_readable(spi_t *obj)
9898
{
9999
return (DSPI_GetStatusFlags(spi_address[obj->instance]) & kDSPI_RxFifoDrainRequestFlag);
100100
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/spi_api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
9090
master_config.ctarConfig.cpol = (mode & 0x2) ? kDSPI_ClockPolarityActiveLow : kDSPI_ClockPolarityActiveHigh;
9191
master_config.ctarConfig.cpha = (mode & 0x1) ? kDSPI_ClockPhaseSecondEdge : kDSPI_ClockPhaseFirstEdge;
9292
master_config.ctarConfig.direction = kDSPI_MsbFirst;
93-
master_config.ctarConfig.pcsToSckDelayInNanoSec = 0;
93+
master_config.ctarConfig.pcsToSckDelayInNanoSec = 100;
9494

9595
DSPI_MasterInit(spi_address[obj->spi.instance], &master_config, CLOCK_GetFreq(spi_clocks[obj->spi.instance]));
9696
}
@@ -104,7 +104,7 @@ void spi_frequency(spi_t *obj, int hz)
104104
DSPI_MasterSetDelayTimes(spi_address[obj->spi.instance], kDSPI_Ctar0, kDSPI_LastSckToPcs, busClock, 500000000 / hz);
105105
}
106106

107-
static inline int spi_readable(spi_t * obj)
107+
static inline int spi_readable(spi_t *obj)
108108
{
109109
return (DSPI_GetStatusFlags(spi_address[obj->spi.instance]) & kDSPI_RxFifoDrainRequestFlag);
110110
}
@@ -314,14 +314,14 @@ static void spi_buffer_set(spi_t *obj, const void *tx, uint32_t tx_length, void
314314

315315
void spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint)
316316
{
317-
if(spi_active(obj)) {
317+
if (spi_active(obj)) {
318318
return;
319319
}
320320

321321
/* check corner case */
322-
if(tx_length == 0) {
322+
if (tx_length == 0) {
323323
tx_length = rx_length;
324-
tx = (void*) 0;
324+
tx = (void *) 0;
325325
}
326326

327327
/* First, set the buffer */
@@ -422,7 +422,7 @@ uint32_t spi_irq_handler_asynch(spi_t *obj)
422422
void spi_abort_asynch(spi_t *obj)
423423
{
424424
// If we're not currently transferring, then there's nothing to do here
425-
if(spi_active(obj) == 0) {
425+
if (spi_active(obj) == 0) {
426426
return;
427427
}
428428

0 commit comments

Comments
 (0)