Programmable USB Hub using MTM-IO-Serial Development Boards

2015 October 14
s62 product photo

Using BrainStem Python for Turning USB Device On And Off 

Simple task automation for repetitive actions can be powerful aids in product development. Automatically connecting and disconnect devices from a USB bus is commonly done in manufacturing test and software regression test systems. The MTM platform can quickly create a programmatically controlled USB hub to simulate downstream device connections. This example shows a simplified approach using a MTM-IO-Serial module through the BrainStem Python interface to turn on then off a USB device.

MTM-IO-Serial modules with firmware version 2.1.4 utlize the cmdMUX entities to manipulate the USB data and VBUS on each downstream USB channel. Each downstream USB channel has the data and VBUS lines grouped in ordered pairs. For example, cmdMUX channel 0 manipulates USB channel 0's data signals (D+ and D-) and cmdMUX channel 1 manipulates USB channel 0's power (Vbus or 5V) line. With the USB data and power lines independently controlled, an MTM-IO-Serial based test system can simulate connections to host devices capable of charging or ones which only provide USB data connections.

cmdMUX to usb downstream

Example Python code showing how to turn on/off a downstream USB channel is show below. 

# import the BrainStem Python modules
from brainstem import discover
from brainstem.link import Spec
from brainstem.stem import MTMIOSerial
from brainstem.defs import model_info
from time import sleep

# parameter definitions
muxUSB = 1
UsbCh0Data = 0
UsbCh0Power = 1

# Create an MTM-IO-Serial object
# Connect to the first one discovered
stem = MTMIOSerial()
spec = discover.find_first_module(Spec.USB)

try:
    print "Connecting to module SN: 0x%08X" % spec.serial_number
    stem.connect_from_spec(spec)

    print "Enabling USB Ch0 data and power"
    stem.mux[muxUSB].setChannelEnable(UsbCh0Data)
    stem.mux[muxUSB].setChannelEnable(UsbCh0Power)
    sleep(5.0)
    print "Disabling USB Ch0 data and power"
    stem.mux[muxUSB].setChannelDisable(UsbCh0Data)
    stem.mux[muxUSB].setChannelDisable(UsbCh1Data)

finally:
    stem.disconnect()

 


Ideal for Board-Level Testing

The USBHub2x4 can be used in a similar manner using the cmdUSB API. However, the MTM-IO-Serial module has additional features which make it ideal for board level testing: high speed UARTs, general purpose digital inputs and outputs, adjustable voltage rails, always-connected USB downstream daisy-chain ports. These features are useful in applications where firmware needs to be loaded over a UART before regression testing or when testing is done on a large array of devices.