AnsweredAssumed Answered

STM32F103 : Receive Issue via USB COM port on Windows VISTA/7/8

Question asked by surleau.frederic on May 18, 2017

Attached :

  • C2_USB_TEST.ioc
  • main.c
  • stm32f1xx_it.c

 

MCU : STM32F103CBT6
STM32CubeMX : 4.21.0
Firmware Package for Family STM32F1 : 1.4.0
System Workbench for STM32 - OpenOCD (for Windows 32bits) Version: 1.14.0.201705091103

 

Modifications in main.c :
  /* USER CODE BEGIN 0 */
  #define RAM_BOOT_LOADER_SIGNATURE_VALUE     0xDEADBEEF
  #define RAM_BOOT_LOADER_SIGNATURE_ADDRESS     0x20004FF0
  void Go_To_ST_Loader()
  {
      *((unsigned long *)RAM_BOOT_LOADER_SIGNATURE_ADDRESS) = RAM_BOOT_LOADER_SIGNATURE_VALUE; // 20KB STM32F103
      HAL_NVIC_SystemReset();
  }
  //----------------------------------------------------------------------------

 

  char usb_buffer[64];
  char usb_flag;
  /* USER CODE END 0 */

 


  /* USER CODE BEGIN 1 */
  int l;
  char x[64];
  int i = 0;
  /* USER CODE END 1 */

 

  /* USER CODE BEGIN 2 */
  // Activate USB device detection (1.5khoms)
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_SET);
  /* USER CODE END 2 */

 

  /* USER CODE BEGIN 3 */
      if( usb_flag )
      {
          sprintf( x, "usb:'%.*s'\r\n", usb_flag, usb_buffer );
          usb_flag = 0;
          if( ! memcmp( usb_buffer, "loader", 6 ) )
          {
              Go_To_ST_Loader();
          }
          CDC_Transmit_FS( x, l );
      }
      else
      {
          HAL_Delay(1000);
          l = sprintf( x, "cpt = %d\r\n", i++ );
          CDC_Transmit_FS( x, l );
      }

 

  }
  /* USER CODE END 3 */

 


Modifications in usbd_cdc_if.c :
  static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
  {
    /* USER CODE BEGIN 6 */
      extern char usb_buffer[64];
      extern char usb_flag;
      if(*Len)
      {
          usb_flag = *Len;
          memcpy( usb_buffer, Buf, usb_flag );
      }
    USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
    USBD_CDC_ReceivePacket(&hUsbDeviceFS);
    return (USBD_OK);
    /* USER CODE END 6 */
  }

 

Windows 10 Microsoft driver 10.0.14393
  => Device detected as : Périphérique série USB (COMn)
  Results : Usb communication OK in both directions.

 

Same Windows 10 as previous but with ST "Virtual comport driver" 1.4.0
  => Device detected as : STMicroelectronics Virtual COM Port (COMn)
  Results : Usb communication OK in both directions.

 

Windows 7 Pro-64   with ST "Virtual comport driver" 1.4.0
Windows 8.1-64    with ST "Virtual comport driver" 1.4.0
Windows Vista-32  with ST "Virtual comport driver" 1.4.0
  => Device detected as : STMicroelectronics Virtual COM Port (COMn)
  Results : Usb communication only in one direction PC to Device.

I know communication is good in the direction PC to device, because when I send "loader" to virtual COM port, the device switches to STLoader.

 

How can I fix this problem ?

 

Fred.

Outcomes