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.

TMS570LS1227: MibSPI Dynamic Transfer Group Length

Part Number: TMS570LS1227

I am using the MibSPI framework from the HalGen where I am using Transfer Group 0 and 1. These group are set to a length on 10 using a 16 bit data format. This is my maximim length I will need. However the transfer can be from 1 to 10 16-bit words and hence, I need to dynamically change the transfer length. To do this, I wrote the following function which I setup just before the MibSPI transfer command:

typedef enum {
    QSPI_TRANSFER_OUTPUT_GROUP,
    QSPI_TRANSFER_INPUT_GROUP,
    QSPI_TRANSFER_LAST_GROUP
}QSPI_TRANSFER_GROUP_ENUM;

#define QSPI_PORT                       mibspiREG5

void QSPI_TransferSetup(uint16_t u16Size, QSPI_TRANSFER_GROUP_ENUM TransferGroup)
{
    uint8_t     loop;
    uint32_t    BufferSizeTotal;

    transferGroupSize[TransferGroup] = (uint32_t)u16Size;

    QSPI_PORT->TGCTRL[QSPI_TRANSFER_INPUT_GROUP] &= 0xFFFF0000;
    QSPI_PORT->TGCTRL[QSPI_TRANSFER_INPUT_GROUP] |= (transferGroupSize[QSPI_TRANSFER_OUTPUT_GROUP] << 8);

    BufferSizeTotal = transferGroupSize[QSPI_TRANSFER_OUTPUT_GROUP] + transferGroupSize[QSPI_TRANSFER_INPUT_GROUP];

    for(loop = QSPI_TRANSFER_LAST_GROUP; loop < 8; loop++)
    {
        QSPI_PORT->TGCTRL[loop] &= 0xFFFF0000;
        QSPI_PORT->TGCTRL[loop] |= (BufferSizeTotal << 8);
    }

    QSPI_PORT->TGCTRL[8U] = BufferSizeTotal << 8U;
    QSPI_PORT->LTGPEND = (QSPI_PORT->LTGPEND & 0xFFFF00FFU) | ((BufferSizeTotal - 1U) << 8U);
}

Array transferGroupSize is just a local sortage of the new size per transfer group.

But this does not work. The transfer group size is always 10 when looking at the signals on an oscilloscope.

What am I missing?

I have looked at

but it did not help.

Andy

  • Hello Andy,

    You are right, you can change the buffer number of the group dynamically. 

    Clear the bit field[15:0] and disable the TG: 

    mibspiREG5->TGCTRL[0] &= 0x7FFF0000;  

    mibspiREG5->TGCTRL[1] &= 0x7FFF0000;  

    mibspiREG5->TGCTRL[2] &= 0x7FFF0000;  

    To change the size of group 0 to TG0_Size: 

    mibspiREG5->TGCTRL[1] |= (TG0_Size-1) <<  8);

    To change the size of group 1 to TG1_Size: 

    mibspiREG5->TGCTRL[2] |= (TG1_Size-1) <<  8);

  • Hi QJ,

    This works perfectly.

    Thank you.

    Andy

  • Hi,

    I thought this fixed my problem, but it does not.

    If I set the size to 5 groups (10 bytes as Data Format set to 16 bits), The device sends 4 groups, and then holds the CS low forever.

    Regards

    Andy

  • Hi Andy,

    For the last buffer of each transfer group, please disable the chip select hold. 

    for (index = 40; index < 49; index++)
    {
        mibspiRAM5->tx[index].control |= 1 << 12;          /* chip select hold */
    }

       mibspiRAM5->tx[49].control &= ^(1 << 12);          /* disable the chip select hold */

    and the start buffer in TGCTRL[5] should be programmed to define the TG4 (5th group) group size.

  • Hi,

    Thanks for your reply. I had got to that conclusion after some playing around (comparing different lengths and generating HalGen code and looking at the changes within the mibspi.c file), and now have a working solution that works well.

    For now, I am only using 1 transfer group that I have maxed the length to 128. This ensure that every mibspiRAM5->tx[index].control has a setup at start. Then I use the following function (remember for now, only sing 1 TG (QSPI_TRANSFER_OUTPUT_GROUP = 0)):

    void QSPI_TransferSetup(uint16_t u16Size, QSPI_TRANSFER_GROUP_ENUM TransferGroup)
    {
        uint16_t    i = 0;

        transferGroupSize[TransferGroup] = (uint32_t)u16Size;
        QSPI_PORT->TGCTRL[QSPI_TRANSFER_OUTPUT_GROUP] &= 0x7FFF0000;

        if (QSPI_TRANSFER_OUTPUT_GROUP == TransferGroup)
        {
            QSPI_PORT->TGCTRL[QSPI_TRANSFER_INPUT_GROUP] &= 0x7FFF0000;
            QSPI_PORT->TGCTRL[QSPI_TRANSFER_INPUT_GROUP] |= (uint32_t)u16Size <<  8U;
        }
        else
        {
            if (QSPI_TRANSFER_INPUT_GROUP == TransferGroup)
            {
                QSPI_PORT->TGCTRL[QSPI_TRANSFER_LAST_GROUP] &= 0x7FFF0000;
                QSPI_PORT->TGCTRL[QSPI_TRANSFER_LAST_GROUP] |= (uint32_t)u16Size <<  8U;
            }
        }

        QSPI_PORT->LTGPEND = (uint32_t)(u16Size - 1) <<  8U;

        while (i < u16Size)
        {
            QSPI_PORT_RAM->tx[i].control |= (uint16)((uint16)1U << 12U); // Ensure CS asserted
            i++;
        }
        // This line desserts the CS at the end of the TG sent
        QSPI_PORT_RAM->tx[u16Size - 1].control &= ~(uint16)((uint16)1U << 12U);
    }

    Thanks for the help.

    Andy