Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support dspi for s32z270dc2 #435

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dts/nxp/s32/S32Z27-BGA400-pinctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@
#define PA11_DSPI_10_PCS0_O NXP_S32_PINMUX(0, 0, 11, 1, 0, 0)
#define PA12_DSPI_10_PCS1 NXP_S32_PINMUX(0, 0, 12, 1, 0, 0)
#define PB6_DSPI_10_PCS2 NXP_S32_PINMUX(0, 0, 22, 6, 0, 0)
#define LVDS_DSPI_10_SIN NXP_S32_PINMUX(0, 0, 500, 0, 0, 0)
#define LVDS_DSPI_10_SOUT NXP_S32_PINMUX(0, 0, 501, 0, 0, 0)
#define LVDS_DSPI_10_SCK NXP_S32_PINMUX(0, 0, 502, 0, 0, 0)

/* SPI_1 */
#define PA11_DSPI_1_PCS4 NXP_S32_PINMUX(0, 0, 11, 5, 0, 0)
Expand Down
3 changes: 3 additions & 0 deletions dts/nxp/s32/S32Z27-BGA594-pinctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@
#define PA11_DSPI_10_PCS0_O NXP_S32_PINMUX(0, 0, 11, 1, 0, 0)
#define PA12_DSPI_10_PCS1 NXP_S32_PINMUX(0, 0, 12, 1, 0, 0)
#define PB6_DSPI_10_PCS2 NXP_S32_PINMUX(0, 0, 22, 6, 0, 0)
#define LVDS_DSPI_10_SIN NXP_S32_PINMUX(0, 0, 500, 0, 0, 0)
#define LVDS_DSPI_10_SOUT NXP_S32_PINMUX(0, 0, 501, 0, 0, 0)
#define LVDS_DSPI_10_SCK NXP_S32_PINMUX(0, 0, 502, 0, 0, 0)

/* SPI_1 */
#define PA11_DSPI_1_PCS4 NXP_S32_PINMUX(0, 0, 11, 5, 0, 0)
Expand Down
2 changes: 2 additions & 0 deletions mcux/README
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ Patch List:
- Add missing CMAKE file to ccm32k driver driver_ccm32k.cmake.
- Add missing CMAKE file to flash_k4 driver driver_flash_k4.cmake.
- Add missing CMAKE file to spc driver driver_spc.cmake
- mcux-sdk/drivers/dspi/fsl_dspi.c, mcux-sdk/drivers/dspi/fsl_dspi.h, mcux-sdk/drivers/dspi/fsl_dspi_edma.c,
mcux-sdk/drivers/dspi/fsl_dspi_edma.h: add the guards for unsupport features on S32Z27x devices
48 changes: 45 additions & 3 deletions mcux/mcux-sdk/drivers/dspi/fsl_dspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
/*! @brief Typedef for master interrupt handler. */
typedef void (*dspi_master_isr_t)(SPI_Type *base, dspi_master_handle_t *handle);

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*! @brief Typedef for slave interrupt handler. */
typedef void (*dspi_slave_isr_t)(SPI_Type *base, dspi_slave_handle_t *handle);
#endif

/*******************************************************************************
* Prototypes
Expand Down Expand Up @@ -53,18 +55,22 @@ static void DSPI_MasterTransferFillUpTxFifo(SPI_Type *base, dspi_master_handle_t
*/
static void DSPI_MasterTransferComplete(SPI_Type *base, dspi_master_handle_t *handle);

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* @brief Slave fill up the TX FIFO with data.
* This is not a public API.
*/
static void DSPI_SlaveTransferFillUpTxFifo(SPI_Type *base, dspi_slave_handle_t *handle);
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* @brief Slave finish up a transfer.
* It would call back if there is callback function and set the state to idle.
* This is not a public API.
*/
static void DSPI_SlaveTransferComplete(SPI_Type *base, dspi_slave_handle_t *handle);
#endif

/*!
* @brief DSPI common interrupt handler.
Expand Down Expand Up @@ -111,8 +117,10 @@ static void *g_dspiHandle[ARRAY_SIZE(s_dspiBases)];
/*! @brief Pointer to master IRQ handler for each instance. */
static dspi_master_isr_t s_dspiMasterIsr;

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*! @brief Pointer to slave IRQ handler for each instance. */
static dspi_slave_isr_t s_dspiSlaveIsr;
#endif

/* @brief Dummy data for each instance. This data is used when user's tx buffer is NULL*/
volatile uint8_t g_dspiDummyData[ARRAY_SIZE(s_dspiBases)] = {0};
Expand Down Expand Up @@ -285,6 +293,7 @@ void DSPI_MasterGetDefaultConfig(dspi_master_config_t *masterConfig)
masterConfig->samplePoint = kDSPI_SckToSin0Clock;
}

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief DSPI slave configuration.
*
Expand Down Expand Up @@ -342,7 +351,9 @@ void DSPI_SlaveInit(SPI_Type *base, const dspi_slave_config_t *slaveConfig)

DSPI_StartTransfer(base);
}
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief Sets the dspi_slave_config_t structure to a default value.
*
Expand Down Expand Up @@ -373,6 +384,7 @@ void DSPI_SlaveGetDefaultConfig(dspi_slave_config_t *slaveConfig)
slaveConfig->enableModifiedTimingFormat = false;
slaveConfig->samplePoint = kDSPI_SckToSin0Clock;
}
#endif

/*!
* brief De-initializes the DSPI peripheral. Call this API to disable the DSPI clock.
Expand Down Expand Up @@ -787,6 +799,7 @@ void DSPI_MasterWriteCommandDataBlocking(SPI_Type *base, uint32_t data)
}
}

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief Writes data into the data buffer in slave mode, waits till data was transmitted, and returns.
*
Expand Down Expand Up @@ -815,6 +828,7 @@ void DSPI_SlaveWriteDataBlocking(SPI_Type *base, uint32_t data)
{
}
}
#endif

/*!
* brief Enables the DSPI interrupts.
Expand Down Expand Up @@ -1707,6 +1721,7 @@ void DSPI_MasterTransferHandleIRQ(SPI_Type *base, dspi_master_handle_t *handle)
}

/*Transactional APIs -- Slave*/
#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief Initializes the DSPI slave handle.
*
Expand All @@ -1733,7 +1748,9 @@ void DSPI_SlaveTransferCreateHandle(SPI_Type *base,
handle->callback = callback;
handle->userData = userData;
}
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief DSPI slave transfers data using an interrupt.
*
Expand Down Expand Up @@ -1800,11 +1817,13 @@ status_t DSPI_SlaveTransferNonBlocking(SPI_Type *base, dspi_slave_handle_t *hand
/* RX FIFO overflow request enable */
DSPI_EnableInterrupts(base, (uint32_t)kDSPI_RxFifoOverflowInterruptEnable);
}
#if !(defined(FSL_FEATURE_FLEXCAN_HAS_NO_RSER_TFUF_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_NO_RSER_TFUF_SUPPORT)
if (NULL != handle->txData)
{
/* TX FIFO underflow request enable */
DSPI_EnableInterrupts(base, (uint32_t)kDSPI_TxFifoUnderflowInterruptEnable);
}
#endif

DSPI_StartTransfer(base);

Expand All @@ -1813,7 +1832,9 @@ status_t DSPI_SlaveTransferNonBlocking(SPI_Type *base, dspi_slave_handle_t *hand

return kStatus_Success;
}
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief Gets the slave transfer count.
*
Expand Down Expand Up @@ -1843,7 +1864,9 @@ status_t DSPI_SlaveTransferGetCount(SPI_Type *base, dspi_slave_handle_t *handle,
*count = handle->totalByteCount - handle->remainingReceiveByteCount;
return kStatus_Success;
}
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
static void DSPI_SlaveTransferFillUpTxFifo(SPI_Type *base, dspi_slave_handle_t *handle)
{
assert(NULL != handle);
Expand Down Expand Up @@ -1931,15 +1954,21 @@ static void DSPI_SlaveTransferFillUpTxFifo(SPI_Type *base, dspi_slave_handle_t *
DSPI_ClearStatusFlags(base, (uint32_t)kDSPI_TxFifoFillRequestFlag);
}
}
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
static void DSPI_SlaveTransferComplete(SPI_Type *base, dspi_slave_handle_t *handle)
{
assert(NULL != handle);

/* Disable interrupt requests */
DSPI_DisableInterrupts(
base, ((uint32_t)kDSPI_TxFifoUnderflowInterruptEnable | (uint32_t)kDSPI_TxFifoFillRequestInterruptEnable |
(uint32_t)kDSPI_RxFifoOverflowInterruptEnable | (uint32_t)kDSPI_RxFifoDrainRequestInterruptEnable));
base, (
#if !(defined(FSL_FEATURE_FLEXCAN_HAS_NO_RSER_TFUF_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_NO_RSER_TFUF_SUPPORT)
(uint32_t)kDSPI_TxFifoUnderflowInterruptEnable |
#endif
(uint32_t)kDSPI_TxFifoFillRequestInterruptEnable |
(uint32_t)kDSPI_RxFifoOverflowInterruptEnable | (uint32_t)kDSPI_RxFifoDrainRequestInterruptEnable));

/* The transfer is complete. */
handle->txData = NULL;
Expand All @@ -1964,7 +1993,9 @@ static void DSPI_SlaveTransferComplete(SPI_Type *base, dspi_slave_handle_t *hand
handle->callback(base, handle, status, handle->userData);
}
}
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief DSPI slave aborts a transfer using an interrupt.
*
Expand All @@ -1981,14 +2012,20 @@ void DSPI_SlaveTransferAbort(SPI_Type *base, dspi_slave_handle_t *handle)

/* Disable interrupt requests */
DSPI_DisableInterrupts(
base, ((uint32_t)kDSPI_TxFifoUnderflowInterruptEnable | (uint32_t)kDSPI_TxFifoFillRequestInterruptEnable |
base, (
#if !(defined(FSL_FEATURE_FLEXCAN_HAS_NO_RSER_TFUF_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_NO_RSER_TFUF_SUPPORT)
(uint32_t)kDSPI_TxFifoUnderflowInterruptEnable |
#endif
(uint32_t)kDSPI_TxFifoFillRequestInterruptEnable |
(uint32_t)kDSPI_RxFifoOverflowInterruptEnable | (uint32_t)kDSPI_RxFifoDrainRequestInterruptEnable));

handle->state = (uint8_t)kDSPI_Idle;
handle->remainingSendByteCount = 0;
handle->remainingReceiveByteCount = 0;
}
#endif

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
/*!
* brief DSPI Master IRQ handler function.
*
Expand Down Expand Up @@ -2145,6 +2182,7 @@ void DSPI_SlaveTransferHandleIRQ(SPI_Type *base, dspi_slave_handle_t *handle)
return;
}

#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SR_TFUF_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SR_TFUF_SUPPORT)
/* Catch tx fifo underflow conditions, service only if tx under flow interrupt enabled */
if (0U != (DSPI_GetStatusFlags(base) & (uint32_t)kDSPI_TxFifoUnderflowFlag))
{
Expand All @@ -2159,6 +2197,7 @@ void DSPI_SlaveTransferHandleIRQ(SPI_Type *base, dspi_slave_handle_t *handle)
handle->errorCount++;
}
}
#endif

/* Catch rx fifo overflow conditions, service only if rx over flow interrupt enabled */
if (0U != (DSPI_GetStatusFlags(base) & (uint32_t)kDSPI_RxFifoOverflowFlag))
Expand All @@ -2175,17 +2214,20 @@ void DSPI_SlaveTransferHandleIRQ(SPI_Type *base, dspi_slave_handle_t *handle)
}
}
}
#endif

static void DSPI_CommonIRQHandler(SPI_Type *base, void *param)
{
if (DSPI_IsMaster(base))
{
s_dspiMasterIsr(base, (dspi_master_handle_t *)param);
}
#if !(defined(FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT) && FSL_FEATURE_DSPI_HAS_NO_SLAVE_SUPPORT)
else
{
s_dspiSlaveIsr(base, (dspi_slave_handle_t *)param);
}
#endif
SDK_ISR_EXIT_BARRIER;
}

Expand Down
Loading