SPI wrong readDataSizePtr value


readDataSizePtr should inform how many bytes was read. But system always returns original value. Problem is in functions le_spi_ReadHD, le_spi_WriteReadFD, le_spi_WriteReadHD.

  uint8_t Data[40];
  size_t S = NUM_ARRAY_MEMBERS(Data);
  Res = le_spi_ReadHD(SPIHandle, Data, &S);
  if(Res == LE_OK)
  	char Str[10];
  	sprintf(Str, "%d", S);
    //S value is always 40 does not matter if system receives 2,3,10 or 20 bytes, S is incorrect 
    //and it is always 40. 


I don’t have SPI hardware available to test but from Legato SPI library code review, it seems that readDataLength is not updated in le_spiLib_ReadHD() function:

I guess we should add the following line before “result = LE_OK;”:

*readDataLength = transferResult;

Could try to rebuild Legato with this mod?



The is no way for a SPI slave to indicate end of data. As long as the slave is selected the master will read a bit on every clock cycle. So it makes sense that the call will return the same number of bytes given that’s how long the slave is selected. If the slave is actually sending less, it will be padded with 0’s or 1’s.