Llosa de Viango Tollos – stmVCom.c

Introduction

Features

Getting started

Download


Libraries

  Tollos libraries

  Device libraries

    boards

    microcontrollers

    peripherals


Background

  Sample application

  Troubleshooting

stmVCom.c – Virtual COM device I/O functions

The vcom functions communicate with the host computer using a USB link.

Note that on Windows a driver may need to be installed for this to work. This should be found automatically; if not, try the stmvirtcom.inf driver.

The primary functions here provide initialization, the usual getc and putc, and stop. Additional exposed functions are the callback function for interfacing with the USB library and ‘USART’ functions which are called when the data terminal is reset or is started.

For reading, up to 35 characters will be buffered here; if the buffer fills (the host sends them faster than the application can read them) then characters will be lost.

Similarly, up to 320 characters will be buffered for output; again, characters will be lost if too many are sent. Neither vcomPutc nor vcomGetc will block. The host application may also discard characters (for example, if the terminal emulator is stopped then restarted, the USB device is not informed of this and characters sent while the terminal is not running are accepted but then lost).
Functions
 EP1_IN_Callback   called by USB library for endpoint 1 (IN)
 EP3_OUT_Callback   called by USB library for endpoint 3 (OUT)
 SOF_Callback   called by USB library on frame start
 USART_Config   called by library when terminal exists
 USART_Config_Default   called by library when device started
 vcomGetcIO   get character
 vcomInitIO   initialize USB port for I/O
 vcomPutcIO   send character to virtal com port
 vcomStopIO   stop the device cleanly

EP1_IN_Callback – called by USB library for endpoint 1 (IN)

void EP1_IN_Callback(void);

Called when inbound transmission is complete.

EP3_OUT_Callback – called by USB library for endpoint 3 (OUT)

void EP3_OUT_Callback(void);

Called when a packet of bytes has been received from the host.

SOF_Callback – called by USB library on frame start

void SOF_Callback(void);

The device is polled by the host every 1ms; this callback is then invoked.

USART_Config – called by library when terminal exists

bool USART_Config(void);

This is called when a ‘real’ host terminal device is attached.

USART_Config_Default – called by library when device started

void USART_Config_Default(void);

This is called when explicit initialization of the Virtual COM port is requested. This implies no terminal yet.

vcomGetcIO – get character

int vcomGetcIO(void);

returns character read from host, or −1 if none there

This function does not block.

vcomInitIO – initialize USB port for I/O

int vcomInitIO(void);

returns 0 if OK, negative if interrupt already in use

This does not switch a software connection as this is device-dependent (port, pin, and direction), so the caller should use bitSet to make the connection before calling this.

vcomPutcIO – send character to virtal com port

int vcomPutcIO(int ch);

ch – character to send

returns 0 if OK, or −1 if vcom has not been initialized, or

−2 if there is a data overrun (bytes have been queued faster

than they could be sent to the host)

This function does not block.

Note that this must not be called from an interrupt handler that has a higher priority than USB.

vcomStopIO – stop the device cleanly

void vcomStopIO(void);

This releases the interrupt handler after stopping the device.

This does not switch a software connection as this is device-dependent (port, pin, and direction), so the caller should use bitSet to make the connection an input after calling this.

Tollos and these web pages were written by Mike Cowlishaw; Please send me any corrections, suggestions, etc.
All content © Mike Cowlishaw, 2010–2012, except where marked otherwise. All rights reserved. The pages here are for non-commercial use only (see the separate licence for Tollos source code). Privacy policy: the Speleotrove website records no personal information and sets no ‘cookies’. However, statistics, etc. might be recorded by the web hosting service.

This page was last updated on 2011-01-09 by c2wiki.