This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Not able to send more than 68 or 70 bytes on USB with STM32F103ZFT6

Hello,

I am working with STM32F103ZFT6. I am working on a project where I have to respond to the Commands from Computer by sending a series of data bytes back to Computer from Micro-controller.

I have the Libraries and application software to do this job. But I have a recent requirement in which I have to send more than 75 bytes at one shot.

Earlier the data bytes were less than 60, so I was able to send without any problem.

The Functions which I am using to Load the data and send the data are as below.

1) UserToPMABufferCopy(uint8_tUSB_Tx_Buffer, ENDP1_TXADDR, uint16_tBuf_Count);
2) SetEPTxCount(ENDP1,uint16_tBuf_Count);
3) SetEPTxValid(ENDP1);

uint8_tUSB_Tx_Buffer - data bytes are in this buffer
uint16_tBuf_Count - No of data bytes to be transfered.

These three functions are the library Functions.

This is strange that I am able to transfer less than 65 bytes easily. When I intend to traansfer more than 75 bytes. the connection from PC to Micro-controller is lost automatically and I have to do the connection and check. This is failing every time.

Can anyone please let me know the problem.

And also i dont have the proper datasheet for learning the USB details of STM32 like its registers, commands, etc..

Please help m e.. Its urgent..

Rgds
Shankar

  • Assuming you work with USB HID, your report size must be 64 bytes.

  • So go to the ST site and download it!

    Note that ST's "data sheets" just contain physical parameters; it's the "Reference Manual" that you need for function & register details.

  • Hi Shankar,

    On the device side, the 75 bytes packet is split into two transactions, 64 and 11 bytes.
    Your firmware sends these transactions one by one, with the library routines you've shown on your post.
    On the host side, PC host controller (hardware) binds the transactions into single transfer.
    Your PC application reads entire 75 bytes data in single "read" call.

    I believe you are working on ST's USB stack
    STM32F10x and STM32L1xx USB full-speed device library v3.4.0
    www.st.com/.../stm32_usb-fs-device_lib.zip

    Here is a snippet to send long data.
    block_transfer() starts lengthy transfer. It puts the first transaction.
    In the callback of endpoint interrupt, the rest of data is sent, one transaction by one.

    usb_prop.c
    
    #define MAX_PACKET_SIZE_EP1IN  64
    
    uint16_t * USB_Tx_ptr;
    uint16_t   USB_Tx_length = 0;
    
    void send_a_transaction( void )
    {
      uint16_t send_len;
    
      if ( USB_Tx_length ) {
        send_len = (USB_Tx_length < MAX_PACKET_SIZE_EP1IN ) ? USB_Tx_length : MAX_PACKET_SIZE_EP1IN;
    
        UserToPMABufferCopy(USB_Tx_ptr, ENDP1_TXADDR, send_len);
        SetEPTxCount(ENDP1, send_len);
        SetEPTxValid(ENDP1);
    
        USB_Tx_ptr    += send_len;
        USB_Tx_length -= send_len;
      }
    }
    
    void block_transfer( uint16_t * buf, uint16_t len )
    {
      if ( len == 0 ) return;
    
      USB_Tx_ptr    = buf;
      USB_Tx_length = len;
    
      send_a_transaction();
    }
    
    usb_conf.h
    
    
    /* CTR service routines */ /* associated to defined endpoints */ /*#define EP1_IN_Callback NOP_Process*/ // <--- comment the target callback to enable it #define EP2_IN_Callback NOP_Process #define EP3_IN_Callback NOP_Process #define EP4_IN_Callback NOP_Process #define EP5_IN_Callback NOP_Process #define EP6_IN_Callback NOP_Process #define EP7_IN_Callback NOP_Process
    usb_endp.c
    
    void EP1_IN_Callback (void)
    {
      send_a_transaction();
    }
    

    Tsuneo

  • Hello Tsuneo,

    Thanks for your solution.. I am impressed to get solution from here.. This is working now, after making the respective changes mentioned by you. Thanks a lot.

    I was not aware of End Point Interrupt in STM32.

    Thanks
    Shankar..