This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0L1228-Q1: MSPM0 SPI code doesn't work for 3-wire

Part Number: MSPM0L1228-Q1

In the file SPIMSPM0.c, in the initHw() function there is the following code:

   if (hwAttrs->csnPin && ((format & SPI_CTL0_FRF_MASK) == SPI_CTL0_FRF_MOTOROLA_3WIRE))
    {
        /*
         * A CS pin was specified, upgrade the 3WIRE to a 4WIRE mode
         */
        format |= SPI_CTL0_FRF_MOTOROLA_4WIRE;
    }

 However, csnPin==0 is a valid pin.  So if you set it to 0, the code elsewhere will configure pin 0.  However, if you set csnPin to GPIO_INVALID_INDEX, then this helpfully (NOT) sets the format to 4-wire.

I believe that first line should be:

if (hwAttrs->csnPin != GPIO_INVALID_INDEX && ((format & SPI_CTL0_FRF_MASK) == SPI_CTL0_FRF_MOTOROLA_3WIRE))

Or really, that whole check should just go away.  Let the user set the value they want.

However, the handling of 3-wire seems to be poorly thought through in the whole file.  It above works, but it should really be using format to know if CS is being used and ignore all CS operations if that is the case.