Component: USB Slave (Comms: USB)

From Flowcode Help
Jump to navigationJump to search
Author Matrix Ltd.
Version 1.3
Category Comms: USB


USB Slave component

Component to create and communicate using a generic USB communications profile. Has the ability to allow the device to be a slave to the PC. Compatible with simulation and USB enabled microcontroller devices (PIC/dsPIC).

Component Pack

COMMSC

Detailed description

No detailed description exists yet for this component

Examples

The PIC based ECIOs or MIAC are good targets for USB as they do not have any additional configuration setting that need to be setup to allow the firmware to run correctly. For other targets you will have to setup the configuration correctly for your hardware to allow the USB to run correctly.


Basic Embedded Example

Here is an example file which waits for incoming data and then when valid data is received it displays this as a binary value onto the PortB pins before echoing back the data. FC6 Icon.png USB Slave Simple Receive


USB Drivers

The example requires a device driver to function correctly. The driver can be generated by selecting the USB Slave component on the System panel, Looking down the list of properties in the properties window, selecting the Generate Driver property and switching the setting to Yes. This will place the driver .inf file into the same directory as the Flowcode fcfx project file is located.

Here is a signed version of the USB Slave device driver using the default VID/PID properties. The .inf driver file generated by Flowcode also requires some associated files which are not auto generated, these files can also be downloaded here.

ZIP Icon.png USB Slave Driver


The final driver files can be assembled by extracting the contents of the zip archive into a folder on your computer and adding the .inf file created by your Flowcode project. Running the correct executable for your PC type should then auto install the driver for you.

When the driver is installed correctly you will get your device showing up in the Windows device manager like this.

SlaveDevManager.jpg


Basic Simulations Example

Here is an example file which is designed to run in simulation to communicate with the connected embedded device. The instance property will have to match the USB instance for the embedded device to allow the communications to work correctly. FC6 Icon.png USB Slave Simulation The USB Slave instance is selected by selecting the USB slave component on the panel and setting the instance property.

USBSlaveInstance.jpg


When editing the USB Slave examples the slave service macro needs to match the setting in the USB Slave properties as shown below.


Slave Macro Setup

SlaveMacroSetup.jpg


Slave Properties

SlaveProps.jpg


Example console showing the data passed between the simulation and the embedded hardware.

SlaveComms.jpg


The MIAC USB Slave and ECIO USB Slave Components are written based on the USB Slave component so these give a good example of what is possible using the component.

Downloadable macro reference

Fc9-comp-macro.png SendString
Adds a string of bytes onto the end of the outgoing data buffer. 
Fc9-string-icon.png - STRING Data
Data String To Send 
Fc9-u8-icon.png - BYTE Length
Max number of bytes to try and add to the outgoing buffer. 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png GetString
Retreives a string of data from the incoming data buffer starting from location 0 and incrementing up to the NumBytes parameter. 
Fc9-u8-icon.png - BYTE NumBytes
Specifies the maximum number of bytes to try and read. 
Fc9-string-icon.png - STRING Return


Fc9-comp-macro.png RunSlaveService
Stalls the microcontroller and waits for an incoming message from the USB, when a message is received the macro defined in the USB Slave properties is automatically run. While the macro is running you can choose to send data back to the PC if you wish. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png SendByte
Adds the byte onto the end of the outgoing data buffer. 
Fc9-u8-icon.png - BYTE Data
Data byte to transmit to the host 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png SendByteArray
Adds an array of bytes onto the end of the outgoing data buffer. 
[[File:]] - Data
Data Bytes To Send 
Fc9-u8-icon.png - BYTE Length
Max number of bytes to try and add to the outgoing buffer. 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png CheckRx
Called to check if there is any incoming data waiting to be received. Returns the number of incoming data bytes. Only needed when not running the slave service. 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png GetByte
Retreives the byte at location Idx from the incoming data buffer. 
Fc9-u8-icon.png - BYTE Idx
Specifies the location in the incoming buffer 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png StopSlaveService
Allows the microcontroller to leave the stalled slave mode and resume its normal independant functionality. Must be called from within the slave service routine to work correctly. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png Initialise
Starts up the USB communications and attempts to enumerate. Returns 0 for a successful startup or 255 for a enumeration timeout. 
Fc9-u8-icon.png - BYTE Return



Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png USB Properties
Fc9-type-21-icon.png Vendor ID
USB VID 
Fc9-type-21-icon.png Product ID
USB PID 
Fc9-type-10-icon.png Device Name
USB Device Name 
Fc9-type-10-icon.png Manufacturer
USB Manufacturer 
Fc9-type-14-icon.png Major Version
USB Major Version Number 
Fc9-type-14-icon.png Minor Version
USB Minor Version Number 
Fc9-type-7-icon.png Enumeration Timeout
Specifies if the enumeration (Initialise function) can timeout if taking too long. 
Fc9-type-16-icon.png Country Code
Country code used by some regional based USB devices 
Fc9-type-14-icon.png Maximum Current (mA)
Maximum amount of current the USB host will provide before shutting down the USB channel. 
Fc9-conn-icon.png Slave Macro Properties
Fc9-type-10-icon.png Slave Macro
Flowcode macro to call while the slave service is enabled 
Fc9-type-16-icon.png Macro Parameters
Defines the parameters for the slave service macro allowing data from the host to be automatically passed into the macro. 
Fc9-conn-icon.png USB Driver
Fc9-type-10-icon.png Driver Directory
Directory to save the generated device driver .inf file 
Fc9-type-10-icon.png Driver Filename
Filename assigned to the USB device driver .inf file when generated. 
Fc9-type-7-icon.png Generate Driver
Generates a driver file when set to Yes, Automatically jumps back to No when complete. 
Fc9-conn-icon.png Simulation
Fc9-type-16-icon.png Instance
Hardware instance to communicate with any connected USB slave devices. 
Fc9-type-21-icon.png Timeout (ms)
Simulation host to slave communications timeout in milliseconds 
Fc9-type-10-icon.png Label
Text displayed on the I/O flasher comms component.