cancel
Showing results for 
Search instead for 
Did you mean: 

CDC_Transmit_FS is not happening from inside the CDC_Receive_FS function

P D
Associate
Posted on November 03, 2017 at 10:59

Hi there,

I am trying to Transmit data over USB CDC after receiving a command, So I need call cdc transmit function inside cdc rx function in which I am comparing the received data. 

But i am able to use only 1 cdc_tx function. when I am calling more than 1 tx function it is not functioning..

Following are the cdc tx and rx functions that I am using:-

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)

{

uint8_t result = USBD_OK;

/* USER CODE BEGIN 7 */

USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;

if(USB_CONNECTED)

{

while(hcdc->TxState != 0);

}

/*if (hcdc->TxState != 0){

return USBD_BUSY;

}*/

USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);

result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);

/* USER CODE END 7 */

return result;

}

static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)

{

/* USER CODE BEGIN 6 */

USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);

//printf('\n\r%d\n\r',*Buf);

if(Buf[0]=='i')

{

CDC_Transmit_FS((uint8_t *)'\n\r Hello\n\r',strlen((const char *)

'\n\r 

Hello

\n\r'

));

CDC_Transmit_FS((uint8_t *)'\n\r

Hello\n\r',strlen((const char *)

'\n\r 

Hello

\n\r'

));

}

USBD_CDC_ReceivePacket(&hUsbDeviceFS);

return (USBD_OK);

/* USER CODE END 6 */

}

I am using STM32F2 nucleo board

CubeMX v 4.22.0

2 REPLIES 2
Ant M
Associate II
Posted on November 03, 2017 at 11:35

As far as I'm aware, 

USBD_CDC_SetRxBuffer is within an ISR, so I'm not sure that calling 

CDC_Transmit_FS from there is OK to do.

Better would be to put the data into a buffer and then signal to your application, which can then call CDC_Transmit_FS if required.

Ant

Posted on November 03, 2017 at 11:52

Hello!

I am calling more than 1 tx function it is not functioning..

This is not abnormal. This is the way that works. Don't forget , CDC_Receive_FS is an ISR (handler mode)

Outside CDC_Receive_FS you can call the CDC_Transmit_FS function as many times you want.

Regards

vf