element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Sustain The World - Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Sustain The World - Design Challenge
  • More
  • Cancel
Sustain The World - Design Challenge
Blog Blog #3 - Setting up Virtual COM Port Support
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dang74
  • Date Created: 1 Sep 2020 1:06 AM Date Created
  • Views 524 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Blog #3 - Setting up Virtual COM Port Support

dang74
dang74
1 Sep 2020

During the project's development stage, times will arise where it's necessary to control the XMC development board with a PC.  For instance the PC host will be used for such tasks as setting time and date, initiating barometric air pressure measurements or retrieving previously logged measurements.  I decided that communication between the host PC and the development board will be carried out by means of Virtual COM port.  Although, physically this is a USB interface, as far as the PC programming model is concerned, this interface is treated as a traditional COM port.  For someone like me that lacks experience developing PC applications and accessing their drivers, the relative simplicity offered by the Virtual COM port approach is a God-send.

 

In DAVE you can add Virtual COM port support to your project by adding the USBD_VCOM APP.  See screen shot below:

 

image

               Figure 1 - Adding USBD_VCOM

 

To receive and transmit characters to and from the Virtual COM port I relied on a handful of ready-made functions.

 

The first of these used was the USB_VCOM_SendString function, and as its name implies it's used to transmit a string out to the Virtual COM port.

In the code below, I use the USB_VCOM_SendString function to transmit the Main Menu string to the host PC.

 

image

          Figure 2 - Sending Main Menu String

 

You'll notice that the USB_VCOM_SendString function call is preceded by a call to the CDC_Device_USBTask function in line 57.

The 'help file' for USBD_VCOM states that is a general management task for a given CDC class interface and is required for the correct operation of the interface.

They also state that it should be called frequently.  In fact the code above doesn't work when the line calling CDC_Device_USBTask is removed.

 

The other ready-made functions that were used are:

 

USBD_VCOM_BytesReceived() which returns the number of bytes received from the host.

USBD_VCOM_ReceiveByte which is used to receive a byte from USB.

USBD_VCOM_SendByte which is used to send a byte to the host.

 

The screen shot below illustrates how these functions were used.

 

image

               Figure 3 - Receiving and Sending Characters from/to Host

 

You will see that at the bottom of the while loop, on line 94, I have another call to CDC_Device_USBTask.

Its position here ensures that it is 'called frequently'.

 

My existing hardware setup is shown in the photo below.  As a special homage to John Woo my development board is 'rocking' two USB connections.

One is used for uploading code.  The other is used for communicating with the host PC.

 

image

          Figure 4 - Rocking 2 USB Connections

 

My host PC is running Hyper Terminal. (Yes I was visited by the Ghost of Operating Systems Past).

 

Anyway, as a parting gift I leave you with an image of Hyper Terminal displaying the main menu.

 

image

          Figure 5 - Flashback from the 1990s

 

Regarding the attachment - I am not a C guru, so be kind.

 

Thanks,

 

Dan

Attachments:
main_WIP.c.zip
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube