Skip to main content
Visitor II
January 26, 2023
Question

Reading data sent from USB_OTG_FS via PuTTY

  • January 26, 2023
  • 3 replies
  • 2707 views

Hi. I hope this is the right place for such a question about USB communication, I am still new to STM32.

I have been trying to send a message from my STM32 board (STM32756-EVAL) without using UART, but the OTG USB. I have been trying to set up my PuTTY to read the data sent from the board, but I am not sure which COM port should be used, or what the connection type should be.

My code is based on my understanding of UART but translated into (what I think is) the USB OTG context. Please let me know if more information is required.

int main(void)
{
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 
 
 /* Configure the system clock */
 SystemClock_Config();
 
/* Configure the peripherals common clocks */
 PeriphCommonClock_Config();
 
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_FMC_Init();
 MX_I2C1_Init();
 MX_LTDC_Init();
 MX_QUADSPI_Init();
 MX_SAI1_Init();
 MX_SAI2_Init();
 MX_SPDIFRX_Init();
 MX_USB_OTG_FS_PCD_Init();
 while (1)
 {
 /* USER CODE END WHILE */
	 HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_10);
	 uint8_t message[] = "Message";
	 HAL_PCD_EP_Transmit(&hpcd_USB_OTG_FS, 0, message, sizeof(message));
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

    This topic has been closed for replies.

    3 replies

    Graduate
    January 26, 2023

    Create a CDC class device using CubeMX. Then implement simple echo by small aditions to usb_cdc_if.c file created in your projects tree under USB_DEVICE. Then investigate further.

    OIp.1Author
    Visitor II
    January 27, 2023

    Thank you very much for your answer. Why would I need to implement these small additions to usb_cdc_if.c, instead of the main file?

    My intention so far with building a simple transmission is to use the newly built "CDC_Transmit_FS" function, and place the function within main.c to send a string that I want sent.

    Is there any official STM32 documentation that would have informed me that setting up USB_FS OTG is not enough for transmission? Or would this have been implicit information?

    ST Employee
    January 26, 2023
    Super User
    January 26, 2023

    Hmmm... after only a very quick look, stdin_usbd_cdc_fs.c looks suspicious (https://github.com/stm32-hotspot/I-CUBE-STDIO/blob/main/Sources/Firmware/Middleware/ST/STDIO/stdin_usbd_cdc_fs.c_ ). Perhaps I'm missing something.

    CDC_Receive_FS() copies however much data there is into the local RxData[] array (without checking that RxData is large enough to hold that data, but perhaps the APP_RX_DATA_SIZE is set to guarantee that). OK so far.

    _read() only ever copies ONE byte from RxData while incrementing its "length" param by the actual number of bytes in RxBuffer (i.e. data_received). This only works when each USB packet contains only one byte. Perhaps OK if someone is typing at a keyboard. But if you have a program writing to the virtual COM port, there can/will be more than one byte in each USB packet.

    ST Employee
    January 26, 2023

    Hi,

    Correct:  RxData[] array (without checking that RxData is large enough to hold that data, but perhaps the APP_RX_DATA_SIZE is set to guarantee that)

    For __read(). we'll have to test.