Hi guys, I am working on a project that requires me to send data from a host(a terminal) to a device, which is based on an STM32F103. For this, I was planning to use the USB Communications Device Class, which is a virtual COM port.
First of all I should probably say that I am quite the newbie for this kind of thing. Its not that I don't know C, its that I have a really hard time navigating the ton of declarations, includes and whatever else is going on in the many different files that are included in such projects. I don't know the deeper meaning behind the "interplay" between the files. I am also sorry if this question is too implicit, as it probably does require some knowledge about the STM32 project structure, libraries, etc.
Anyway, I have no problem sending data via the function CDC_Transmit_FS(), but I am not really sure about how to receive data. There is a function, CDC_Receive_FS(), but from what I can understand, this function is not supposed to be used for receiving data. From what I understand, it is a callback function that the USB lib runs every time it receives some data. The data is then stored in a UserRxBufferFS array declared in the same usbd_cdc_if.c file. I can verify that the UserRxBufferFS array gets filled with what I write in a terminal on the host.
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
return (USBD_OK);
/* USER CODE END 6 */
}
Now, what I don't understand is how I use the received data in e.g. my main loop. I can't just declare a variable "myvariable=UserRxBufferFS" in my main loop, for instance, as the compiler will then throw an error about the UserFxBufferFS being undeclared.
What I see most people do, is to modify the CDC_Receive_FS() function to work on the received data, but that doesn't sit right with me: It seems to create unnecessary high degrees of complexity to weave files together like this. Basically, in my main.c loop, I'd like to use a switch-case statement to sort through all possible commands sent to the device via the terminal. How could I avoid having to do this inside the CDC_Receive_FS function ?
Thank you for your time