AnsweredAssumed Answered

Not able to send via USB_CDC more than 8 characters (code from CubeMX)

Question asked by Krajewski.Zdzis_.001 on Jan 13, 2017
Latest reply on Jan 16, 2017 by mao

edit: previously I wrote that problems occurs with freertos, I checked without it and I am having the same problem (ending in dead loop after sending more than 8 characters).

 

Steps to reproduce:

Create project in CubeMX for STM32F4DISCOVERY, enable USB_FS Device only. Configure clock: PLL_N = 72, PLL_Q=3, that gives me 48 MHz for usb, other settings remain unchanged. In configuration I enable CDC device with default parameters. Generate code for SW.

I add some led toggle in order to know it it is running.

/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
  /* init code for USB_DEVICE */
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 5 */
  /* Infinite loop */
  for(;;)
  {
       HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
    osDelay(500);
  }
  /* USER CODE END 5 */
}

In file usbd_cdc_if.c I am setting breakpoint at CDC_Receive_FS function.

When I am sending 8 characters or less it works fine. Program enters function above. When I send more than 8 characters, program is not entering CDC_Receive_FS function

 

>>> import serial
>>> ser = serial.Serial(port='/dev/ttyACM0')
>>> ser.write('12345678')
8
>>> ser.write('123456789')
9
>>> ser.write('12345678')
# python hangs here

 

  1. Sometimes program hangs in this loop:
    /**
    * @brief  This is the code that gets called when the processor receives an
    *         unexpected interrupt.  This simply enters an infinite loop, preserving
    *         the system state for examination by a debugger.
    * @param  None    
    * @retval None      
    */
        .section  .text.Default_Handler,"ax",%progbits
    Default_Handler:
    Infinite_Loop:
      b  Infinite_Loop
      .size  Default_Handler, .-Default_Handler

Outcomes