2021-11-15 09:28 PM
Hello,
I wonder, is it possible to receive more than one char (1 byte) at the time? For now I can only receive one in one message, i can't find the solution to receive more.
Here is my code:
/**usbd_cdc_if.c**/
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);
extern uint8_t received_buffor[64];
extern uint8_t received_flag;
for(int i = 0; i < 64; i++){
received_buffor[i] = 0;
}
strlcpy(received_buffor, Buf, (*Len) + 1);
received_flag = 1;
return (USBD_OK);
/* USER CODE END 6 */
}
/**main.c**/
uint8_t received_buffor[64];
uint8_t send_buffor[64];
uint8_t received_flag = 0;
uint8_t len;
int main(void)
{
while (1)
{
if(received_flag == 1){
received_flag = 0;
len = sprintf(send_buffor, "Received: %s\n\r", received_buffor);
CDC_Transmit_FS(send_buffor, len);
}
}
Thanks in advance :)
Solved! Go to Solution.
2021-11-16 06:13 AM
Both send_buffor and received_buffor are already of type (uint8_t *) and point to the start of the buffer. &send_buffor is of type (uint8_t **) and will throw an error here if the function expects (uint8_t *).
2021-11-16 06:36 AM
i correct my comment then.
I realised the stm32ide compiler eats both &buffor and buffor arguments as (uint8_t*), no error/warning thrown and code works.
2021-11-16 10:12 AM
Try to send a file (xmodem, ymodem, etc) from Teraterm or other such app. Then you will see multi-byte receives.