cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC receving more than one char

bmak
Senior

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 ��

12 REPLIES 12

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 *).

If you feel a post has answered your question, please click "Accept as Solution".

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.

we dont need to firmware by ourselves, lets talk
Pavel A.
Evangelist III

Try to send a file (xmodem, ymodem, etc) from Teraterm or other such app. Then you will see multi-byte receives.