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.

TM4C1290NCZAD: How to clear the Tx FIFO

Part Number: TM4C1290NCZAD
Other Parts Discussed in Thread: EK-TM4C1294XL

Hi team

Regarding SSI of TM4C1290, how to clear the Tx FIFO? When using TM4C as a SPI slave, it would receive the data from the master and send the data back. The master would need to reset sometimes, so there is some data left in the slave Tx FIFO(TM4C side). Next time the master has to send several dummy bytes to clear the Tx FIFO of the slave.

Now, customer uses another way, they reset the SPI module as below, but they found that the first byte is still the byte received from last time, that’s what makes them confused.(what is the reason for this?)

Code:

       ROM_SSIDisable(SSI2_BASE);

       ROM_SSIConfigSetExpClk(SSI2_BASE, 120000000, SSI_FRF_MOTO_MODE_1, SSI_MODE_SLAVE, 120000, 16);

       ROM_SSIEnable(SSI2_BASE);

 

So we may need you insight, to explain the reason for the case mentioned above and clarify how to clear the SPI Tx FIFO of TM4C.Thanks.

  • Hi Shaofeng,

    Now, customer uses another way, they reset the SPI module as below, but they found that the first byte is still the byte received from last time, that’s what makes them confused.

    Can you elaborate the behavior again? Do you mean the first byte on TXFIFO is the same as what was received on RXFIFO?  Or do you mean what was transmitted on the TX pin was one of the very early bytes in the TXFIFO? There is below description on the datasheet. Please note that when you disable the SSI module, it does not clear the TXFIFO. Your TXFIFO after the SSI is re-enabled could be either empty or not empty. If TXFIFO after you re-enable SSI happens to be empty then the state machine will transmit the 8th most recent value. If TXFIFO happens to be not empty then 0 is transmitted for those bytes when TXFIFO becomes empty. To address your described problem, I still believe your first method is the correct way of handling - the master sends several dummy bytes to clear the slave's TXFIFO. Please bear in mind that the slave has no way of knowing the master has been reset in the middle. The slave just  expects SPICLK from the master. Once the clock is received, it starts transmitting whatever it has left in the FIFO.

  • Hi Charles

    Thanks for your reply~ Yes, I mean what was transmitted on the TX pin was one of the very early bytes in the Tx FIFO, and just one byte, the next data is the ones from DMA. And it can be repeated every time, it's tricky if FIFO can be empty or not empty.

    Besides, there are some points that still need your help to clarify:

    Please note that when you disable the SSI module, it does not clear the TXFIFO

    1. So how can we clear the Tx FIFO? Only by power cycle reset?

    The startup routine is as below, the slave will run this routine if the master is offline(the master will notify the slave by a GPIO)

    void SafeMcuSsiStartUp(uint8_t * RxBuffAddr,uint32_t RxBuffSize,uint8_t * TxBuffAddr,uint32_t TxBuffSize)
    {
    	uint32_t rsv;
    	
    	ROM_SSIDisable(SSI2_BASE);
    	ROM_SSIConfigSetExpClk(SSI2_BASE, 120000000, SSI_FRF_MOTO_MODE_1, SSI_MODE_SLAVE, 120000, 16);
    	ROM_SSIEnable(SSI2_BASE);
    		
    	while((HWREG(SSI2_BASE + SSI_O_SR) & SSI_SR_RNE) != 0)
    	{
    		rsv = HWREG(SSI2_BASE + SSI_O_DR);
    	}
    	rsv = rsv;
    	SSI1RxNum = 0;
    	ROM_SSIIntEnable(SSI2_BASE, SSI_DMATX);												
    	ROM_uDMAChannelTransferSet(
    															UDMA_CH13_SSI2TX|
    															UDMA_PRI_SELECT,
    															UDMA_MODE_BASIC,
    															TxBuffAddr,
    															(void *)(SSI2_BASE + SSI_O_DR),
    															(TxBuffSize/2)
    														);
    	ROM_uDMAChannelEnable(UDMA_CH13_SSI2TX);														
    }

    2. The method they are using is abandoning the first byte, but I think it's unreliable if we can't explain this. So what's your recommendation for restarting the communication?

    Expect for your reply, thanks!

  • Hello Shaofeng,

    Other than power cycle reset, the other method is entirely disabling the SSI peripheral and reconfiguring once again. To my understanding, that would clear the FIFO as well. This would be better than a full POR.

    I will let Charles also share his thoughts on the restart of communication, he may have different ideas, but my thought would be to send out dummy bytes to clear the FIFO followed by resuming communication with some form of 'retry' packet to prompt the slave to send over the 'lost' data.

    Best Regards,
    Ralph

  • Hi Shaofeng,

      As suggested by Ralph, have you tried to reset the SSI module by calling SysCtlPeripheralReset(SYSCTL_PERIPH_SSI2)?

  • Customer has already tried reseting the SSI module by calling peripheral reset, but it can not clear the Tx FIFO, there are still some previous date inside. From your side, the best way is to send the dummy data to refresh the FIFO, right?

  • Hi Charles

    BTW, for the resetting, could you test on the EVM board for crossing check? Customer also complaint that we did not provide the Slave mode demo, can we provide an official demo for the Slave mode?

  • Hi Shaofeng,

    Customer has already tried reseting the SSI module by calling peripheral reset, but it can not clear the Tx FIFO, there are still some previous date inside. From your side, the best way is to send the dummy data to refresh the FIFO, right?

    That is correct. The best way is for the master to send out dummy clocks to the slave to clear out the FIFO. 

    You can find below example demonstrates master and slave communication. 

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl\ssi_master_slave_xfer

    There are a few more examples in C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\ssi.

  • Hi Charles

    One more thing needed to confirm with you, customer reflected that the issue:

    "what was transmitted on the TX pin was one of the very early bytes in the Tx FIFO, and just one byte, the next data is the ones from DMA."

    will occur when they use

           ROM_SSIDisable(SSI2_BASE);

           ROM_SSIConfigSetExpClk(SSI2_BASE, 120000000, SSI_FRF_MOTO_MODE_1, SSI_MODE_SLAVE, 120000, 16);

           ROM_SSIEnable(SSI2_BASE);

    Could you help to confirm that what the influence to the FIFO is using these codes?

  • Hello Shaofeng,

    I don't believe we have a means to provide full confirmation of how that will impact the FIFO. It isn't explicitly stated in the device datasheet what the behavior would be in that case. Our expectation would be that the FIFO is cleared when the peripheral is fully disabled and then restarted, but it is not something that we can give a confirmation of will be the case for all attempts across different operating situations and devices which is why the best way to avoid the situation is to use dummy clocks to clear out the FIFO.

    Best Regards,

    Ralph Jacobi