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.

TMS320F28379D: USB Bootloader with Bulk Out Function

Part Number: TMS320F28379D

Hi Team,

My customer is trying to implement on F28379D. By far, they can successfully achieve the bootloader based on F2837xD_usb_flash_kernels_cpu01.

However, they would like the MCU to send a feedback via EP1 at the end of the code to indicate the success or error of the bootloader.

To achieve the function, they did the following modifications:

1) USB Clock configuration in USB_Init(void)

            DevCfgRegs.DC12.bit.USB_A = 1; //feature enabled: device only

            CpuSysRegs.PCLKCR11.bit.USB_A = 1; //module clock turned on

 

 2) EP1 TxFIFO configuration:

            //Set up endpoint 1 for bulk transfers with a 64-byte FIFO

                USBREG8(USB_O_TXFIFOSZ) = 0x03;
                USBREG16(USB_O_TXFIFOADD) = 0x120;
                USBREG8(USB_O_TXCSRH1) = 0x20;

3)Enable USB EP1 Tx interrupt:

            //USBREG16(USB_O_TXIE) = 0x0001;

              USBREG16(USB_O_TXIE) = 0x0003;

4) USB descriptor configuration:

            const sUsbInterfaceDescriptor loaderInterfaceDescriptor =
            {

                        USB_DTYPE_INTERFACE<<8 | (2*sizeof(sUsbInterfaceDescriptor) - 1),
                        0<<8 | 0,
                        // 0xFF<<8 | 1,
                        0xFF<<8 | 2,
                        0x00<<8 | 0x00,
                        4
            };
            const sUsbEndpointDescriptor loaderEndpointDescriptor =
            {
                        USB_DTYPE_ENDPOINT<<8 | (2*sizeof(sUsbEndpointDescriptor) - 1),
                        {
                                    1, 0, 0,              //Endpoint 1, OUT type
                                    2, 0, 0, 0                       //Bulk mode transfers
                        },
                        64,                                                       //Max packet size in bytes (64 is max for bulk transfers)
                        0
            };

            const sUsbEndpointDescriptor loaderEndpointDescriptor1 =
            {
                        USB_DTYPE_ENDPOINT<<8 | (2*sizeof(sUsbEndpointDescriptor) - 1),
                        {
                                    1, 0, 1,              //Endpoint 1, in type
                                    2, 0, 0, 0                       //Bulk mode transfers

                        },
                        64,                                                       //Max packet size in bytes (64 is max for bulk transfers)
                        0
            };

5) CombineUsbDescriptors(Uint16 *buffer)

            d = 0;
            byteLength = loaderEndpointDescriptor1.bDescriptorType_bLength & 0xFF;
            while (byteLength--)
            {
                     __byte((int *)buffer, b) = __byte((int *)&loaderEndpointDescriptor1, d);
                        b++; d++;
            }

          //Added (loaderEndpointDescriptor1.bDescriptorType_bLength & 0xFF);

         buffer[1] = (loaderConfigDescriptor.bDescriptorType_bLength & 0xFF) +
                                        (loaderInterfaceDescriptor.bDescriptorType_bLength & 0xFF) +
                                        (loaderEndpointDescriptor.bDescriptorType_bLength & 0xFF) +
                                     (loaderEndpointDescriptor1.bDescriptorType_bLength & 0xFF);

6) Transmit function of EP1

       //Transmit data from USB endpoint 1
     void TxDataEp1(const Uint16 *data, Uint16 length8, eDataEnd dataEnd)
            {
                        Uint16 c;
                        // Enables the endpoint1 direction as TX
                        //Write the data to the FIFO
                        for (c = 0; c < length8; c++)
                        {
                                    USBREG8(USB_O_FIFO1) = __byte((int *)data, c);

                        }

                        //Kick off the transmission. If there's no more data, set the end bit.
            USBREG8(USB_O_TXCSRL1) = (dataEnd == USB_END_DATA) ? (USB_TXCSRL1_TXRDY | USB_TXCSRL1_SETUP) : U                        SB_TXCSRL1_TXRDY;

            }

        Function Call:

                Uint16 ui16TxBuffer[5];

                        ui16TxBuffer[0] = 0xA5;
                        ui16TxBuffer[1] = 0x00;
                        ui16TxBuffer[2] = 0x41;
                        ui16TxBuffer[3] = 0x5A;
                        ui16TxBuffer[4] = 0x41;
                        TxDataEp1(ui16TxBuffer, 5, USB_END_DATA);

We have covered all the configuration according to our knowledge. The computer can recognize Bulk in EP1 and Bulk out EP1,but we still cannot receive the data on the host PC.

Could you please help review the code to find out what the problem is? We doubt the problem should be caused by TxDataEp1 function.

Looking forward to your advice.

  • Hi Weiqi,

    The usb flash kernel is already using EP1 for the data transfers between device and host. It appears you have enable TX interrupts properly with the TXIE register.

    The one thing that sticks out right now is that you are writing to the SETUP bit in the USB_O_TXCSRL1 register. That bit is used as the SETUP bit when the C2000 is in host mode. When the C2000 is in device mode (which it is in your case) then that bit means STALL, and the USB "Issues a STALL handshake to an IN token." This may be causing your issue. You should not be setting the STALL bit.

    Just set the TXRDY bit. Hopefully that helps.

    I have some other questions...
    1) Why are you combining descriptors? Is your host PC expecting the proper descriptors. I don't think you need to modify the descriptors. You should not have to modify the descriptors after performing the DFU function using the kernel. Just enable transmit, write the data to the FIFO, and have the host send an IN packet request.

    2) How have you modified your host PC application to request data after the DFU?

    sal
  • Thanks Sal,

    My customer modifier the code according to your instructions.  It turns out the  SETUP bit in USB_O_TXCSRL1 register caused the problem, and it has been fixed.

    It is really important for our customer, and we really appreciate your support.