Author Topic: STM32F4 Disco VCP USB example  (Read 12011 times)

0 Members and 1 Guest are viewing this topic.

Offline Harvs

  • Super Contributor
  • ***
  • Posts: 1141
  • Country: au
STM32F4 Disco VCP USB example
« on: October 18, 2013, 11:33:17 am »
For anyone wanting to get a virtual comm port up an running on the Disco board I've attached an example.  You'll need the ST USB library "STM32_USB-Host-Device_Lib_V2.1.0" and the standard peripheral libraries.  I've just provided a screenshot from keil of the files included in the project since I know most don't use Keil, therefore attaching the project would be pointless.

This is nothing more than the ST VCP to UART bridge example with the UART stuff removed, the pin and clock configurations sorted out for the disco board, and the hundreds and hundreds (maybe thousands?) of lines of extra stuff for all their other boards and auto documentation removed.  Seriously their example is like wading through a sea to find the relevant code.

You've got two functions of significance in the usbd_cdc_vcp.c file.
uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)
uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)

They're pretty obvious, you need to implement whatever you want to add data to the IN buffer, and process data from the OUT buffer.

In this example I've got a counter in the main function which adds an ascii string of the current count every overflow, and a case statement turning a led on and off in the Rx section.

Hopefully this may save you some time...

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo