cancel
Showing results for 
Search instead for 
Did you mean: 

Data transfer halted in USB CDC

emmanuel
Associate II
Posted on January 15, 2015 at 16:32

Hi everybody,

I modified USB CDC standalone project from STM32Cube_FW_F4 v1.3.0 to send data through IN endpoint.

The first 12 Kib of data can be sent without any problem. The next packet of data is sent but the interrupt does not trigger at the end of the transmission. No more data can be sent.

The modifications of this example are :

1) Bug correction according to https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM32Java%2fReal%20bug%20in%20the%20USB%20CDC&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=198

2) The CDC_SendData has been added to usbd_cdc_interface.C file :

void CDC_SendData(uint8_t * data, uint32_t size)

{

    /* Add data to buffer */

    if ((UserTxBufPtrIn+size) < APP_RX_DATA_SIZE)

    {

        memcpy(&UserTxBuffer[UserTxBufPtrIn], data, size);

        UserTxBufPtrIn += size;

    }

    else

    {

        memcpy(&UserTxBuffer[UserTxBufPtrIn], data, APP_RX_DATA_SIZE - UserTxBufPtrIn);

        memcpy(UserTxBuffer, &data[APP_RX_DATA_SIZE - UserTxBufPtrIn],

               size - APP_RX_DATA_SIZE + UserTxBufPtrIn);

        UserTxBufPtrIn = size - APP_RX_DATA_SIZE + UserTxBufPtrIn;

    }

}

3) The Toggle_Leds function (in main.c file) has been modified:

static void Toggle_Leds(void)

{

  static uint32_t ticks, k = 0;

  static uint8_t data[64];

 

  if(ticks++ == 0xff)

  {

    BSP_LED_Toggle(LED1);

    BSP_LED_Toggle(LED2);

    BSP_LED_Toggle(LED3);

    BSP_LED_Toggle(LED4);

    ticks = 0;

  }

  memset(&data, k, sizeof(data));

  data[sizeof(data)-2] = 0x13;

  data[sizeof(data)-1] = 0x10;

 

  CDC_SendData(data, sizeof(data));

  k = (k+1) % 128;

          

  HAL_Delay(10);

}

The code is running on the STM3240G-Eval board.

Does anyone have an idea to solve this problem?

Thanks in advance

#stm32f4-usb-cdc-tranfer-halted
3 REPLIES 3
emmanuel
Associate II
Posted on January 19, 2015 at 10:56

Hello,

It was the link I pointed to in my first point ( 1) ). It does not solve the problem.

emmanuel
Associate II
Posted on April 03, 2015 at 14:10

Hi all,

I tested this problem on

STM32Cube_FW_F4_V1.5.0. The problem is still there.

To reproduce the bug, it's just enough to modify the

HAL_TIM_PeriodElapsedCallback

function as followed:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

  uint32_t buffptr;

  uint32_t buffsize;

 

 

/*******************************************************************************/

  /* Added : Testing code added to show the bug */

  {

      static unsigned int cpt = 0;

      // Wait for end of enumeration

      if (cpt >= 200)

      {

          UserTxBufPtrOut = APP_RX_DATA_SIZE - 32;

          memcpy(&UserTxBuffer[UserTxBufPtrOut], &cpt, 4);

      }

      cpt++;

  }

  /*******************************************************************************/

 

  if(UserTxBufPtrOut != UserTxBufPtrIn)

  {

    if(UserTxBufPtrOut > UserTxBufPtrIn) /* Rollback */

    {

      buffsize = APP_RX_DATA_SIZE - UserTxBufPtrOut;

    }

    else

    {

      buffsize = UserTxBufPtrIn - UserTxBufPtrOut;

    }

    

    buffptr = UserTxBufPtrOut;

    

    USBD_CDC_SetTxBuffer(&USBD_Device, (uint8_t*)&UserTxBuffer[buffptr], buffsize);

    

    if(USBD_CDC_TransmitPacket(&USBD_Device) == USBD_OK)

    {

      UserTxBufPtrOut += buffsize;

      if (UserTxBufPtrOut == APP_RX_DATA_SIZE)

      {

        UserTxBufPtrOut = 0;

      }

    }

  }

}

If somebody can help, it would be great