Common mistakes
Informative
Pitfalls when using the SPI driver, and how to avoid them. Each maps to a rule in Spi — Requirements or an error in Errors.
Passing a real pointer to
Spi_Init.configPtrMUST beNULL_PTR— a non-null pointer raisesSPI_DEVERR_PARAM_POINTER(CHI-SPI-MUST-09). The configuration is selected at build time.Modifying or freeing the buffer too early. The TX/RX buffer sets and their data must stay valid and unmodified from
Spi_StartTransactionuntilSpi_Callout_OnTransactionEndfires (CHI-SPI-MUST-13). The driver does not copy them.Inconsistent TX/RX lengths. The total transfer length across
txBuffSetPtrandrxBuffSetPtrmust match; a mismatch raisesSPI_DEVERR_PARAM_LENGTH(CHI-SPI-MUST-20).Forgetting to stage a target response. A target only transfers data you staged with
Spi_StartTransactionbefore the controller selects it; otherwise it sendsdefault_dataand ignores what it receives, still firingSpi_Callout_OnTransactionEndwithlength = 0(CHI-SPI-MUST-15).Expecting
Spi_CancelTransactionto abort a live transfer. It only cancels a staged target transaction that has not started on the bus; once transferring it returnsE_NOT_OK(CHI-SPI-MUST-17). To stop a live transfer, useSpi_DeInit.Driving the CS pin twice. With
cs_ctrl: ViaGPIOthe driver callsSpi_Callout_CsControland the integration code owns the pin; withViaHWthe hardware owns it. Do not toggle CS from both (CHI-SPI-MUST-16).Forgetting to service polled events. If a channel is configured for
Pollingyou must callSpi_PollFunctioncyclically, or no transfer progresses and no callout fires (CHI-SPI-MAY-01).Using
Spi_OnCswhen the hardware detects CS.Spi_OnCsis only for target channels whose hardware cannot detect chip-select deactivation (CHI-SPI-SHOULD-01).Calling
Spi_DeInitmid-transaction. It aborts immediately and can leave a target in an undefined state; call it when the channel isSPI_CH_STATE_IDLE(CHI-SPI-MUST-10).