AnsweredAssumed Answered

HAL_SPI_TransmitReceive

Question asked by brown.geoffrey.001 on Jun 3, 2016
Latest reply on Mar 1, 2017 by Turboman
I'm having some peculiar behavior using the polling mode spin routines (F3), so I took a look at the HAL code.      I'm sending 8 bit data using an array of 8-bit quantities.  Inside the TransmitReceive routine I see this:

HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size\

, uint32_t Timeout)




/* Transmit and Receive data in 8 Bit mode */

  else

  {

    while((hspi->TxXferCount > 0) || (hspi->RxXferCount > 0))

    {

      /* check TXE flag */

      if((hspi->TxXferCount > 0) && ((hspi->Instance->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE))

      {

        if(hspi->TxXferCount > 1)

        {

          hspi->Instance->DR = *((uint16_t*)hspi->pTxBuffPtr);

          hspi->pTxBuffPtr += sizeof(uint16_t);

          hspi->TxXferCount -= 2;

        }


There's just so much wrong with this code.  First there's the cast from uint8_t * to uint16_t *-- really ?  All of a sudden you're introducing non-aligned accesses.  Then there's the assumption that I want to send a multiple of 2 bytes -- NO NO NO.

It appears I'll have to write my own transmission SPI routines since I can't trust these libraries.

Geoffrey



Outcomes