Correction proposal to STM SPI master transfer ( stm_spi_api.c )

02 Apr 2017

Hello,

I faced the problem described in the following discussion: https://community.st.com/thread/31361

SPI master transfer are wrong on the "receive" side : data is read with an offset. You should flush something before trying to transfer.

I am using the Nucleo L432KC board .

I have found how to correct that : In stm_spi_api.c you should add HAL_SPIEx_FlushRxFifo (handle); inside the spi_master_start_asynch_transfer function

Could you please make this modification (or a better one) in the official mbed library?

spi_master_start_asynch_transfer() inside stm_spi_api.c

    // enable the right hal transfer
    int rc = 0;
    HAL_SPIEx_FlushRxFifo (handle);  // <-- NEW LINE ADDED
    switch(transfer_type) {
        case SPI_TRANSFER_TYPE_TXRX:
            rc = HAL_SPI_TransmitReceive_IT(handle, (uint8_t*)tx, (uint8_t*)rx, words);
            break;
        case SPI_TRANSFER_TYPE_TX:
            rc = HAL_SPI_Transmit_IT(handle, (uint8_t*)tx, words);
            break;
        case SPI_TRANSFER_TYPE_RX:
            // the receive function also "transmits" the receive buffer so in order
            // to guarantee that 0xff is on the line, we explicitly memset it here
            memset(rx, SPI_FILL_WORD, length);
            rc = HAL_SPI_Receive_IT(handle, (uint8_t*)rx, words);
            break;
        default:
            length = 0;
    }

regards,

F4HDK

05 Feb 2018

Hi

Please, check https://github.com/ARMmbed/mbed-os/pull/6012

Regards,

Jerome