cancel
Showing results for 
Search instead for 
Did you mean: 

Nucelo F207ZG USB CDC Example code

Manikandan K
Associate III
Posted on March 22, 2017 at 08:50

Hi, I'm using Nucleo F207ZG board and i did my testing of GPIO using STM32CubeMx(HAL lib) with Eclipse IDE on Ubuntu 04, Now i want to use the USB as Communication Device Class (CDC) but i'm not familiar with usb so is there any example coding for tranfer the data from/to Nucleo board/PC

Note: this post was migrated and contained many threaded conversations, some content may be missing.
20 REPLIES 20
Posted on May 22, 2017 at 12:29

Hi Pranay Dhuri,

Can you tell me the procedure which you followed ,

I did STM32F207ZG USB Communication with STM32cube and eclipse IDE . So if you share your procedure then it is easy to solve your problem. 

-With Thanks & Regards

K.Manikandan

Posted on May 22, 2017 at 12:35

Refer the Youtube Video :

https://www.youtube.com/watch?v=ttqRsBJQu4E

  and 

https://www.youtube.com/watch?v=Jpul3w10tOU

 

Thanks

Posted on May 22, 2017 at 12:58

Hi, I am using STM32CubeMX for generating code and using SW4STM32 IDE.

I have configured cubeMX for CDC and generated an initialization code.

In that I have called CDC_Receive_FS(),CDC_Transmit_FS() functions as below.

uint8_t HiMsg[]=''Start\r\n'';

CDC_Transmit_FS(HiMsg,strlen(HiMsg));

HAL_Delay(500);

while(1)

{

HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);

L1= strlen(myBuffer);

 status = CDC_Receive_FS(myBuffer, 5);

CDC_Transmit_FS(myBuffer, 7);

HAL_Delay(3000);

}

then I compiled and flashed but that wasn't working.

0690X00000606z6QAA.png
Posted on May 23, 2017 at 07:24

What is the Heap size and Stack size you have ?

You want to increase the Heap size and Stack size.

Posted on May 23, 2017 at 07:55

Yes.I have increased heap and stack sizes..when HCLK is 120 MHz it is not working ,but when I am using HSI for sys and HCLK then it is working

Posted on May 23, 2017 at 08:10

It's also working ....

0690X00000606ddQAA.png0690X000006074xQAA.png
Posted on May 23, 2017 at 08:23

I tried the same but NO it isn't working for me...It doesn't pass SystemClock_Config(),Is there any jumper setting I have to do?

Posted on May 23, 2017 at 12:25

Hi

Pranay Dhuri

,

Can you share your method which is used in CDC_Receive_FS() and  CDC_Transmit_FS() method .

-With Thanks & Regards

K.Manikandan

Posted on May 23, 2017 at 12:42

It same as that of in the video which you shared..

updated below 2 functions in usbd_cdc_if.c

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

{

/* USER CODE BEGIN 6 */

receive_data[_index]=Buf[0];

if(++_index==64)

{

_index=0;

}

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

USBD_CDC_ReceivePacket(&hUsbDeviceFS);

return (USBD_OK);

/* USER CODE END 6 */

}

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)

{

uint8_t result = USBD_OK;

/* USER CODE BEGIN 7 */

memcpy(UserTxBufferFS,Buf,sizeof(uint8_t)*Len);

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

if (hcdc->TxState != 0){

return USBD_BUSY;

}

USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);

result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);

/* USER CODE END 7 */

return result;

}

and called 

CDC_Transmit_FS(mystring,strlen((const char *)mystring)); 

in main()

Posted on May 23, 2017 at 12:52

Ok ,Thank you

Pranay Dhuri .