Maple Reference Documentation

# Maple Reference Documentation: USB

- Function Reference
- Recommended Reading

The Maple stm32 microprocessor includes a dedicated USB peripheral which can be configured to act as a general USB slave device with transfer rates up to 12mbps (it unfortunately can not be configured as a host or on-the-go device). By default the peripheral is configured for two uses: first to recieve sketch/program uploads from the IDE, and second to emulate a regular serial port for use as a terminal (text read/write).

The emulated terminal is relatively slow and inefficient; it is best for transfering data at regulat serial speeds (kilobaud). Users requiring faster data transfer should consider implementing a different communications protocol; the Maple could be reprogrammed to appear as a mass storage device (thumb drive), human interface device (mouse or keyboard), microphone, or any other USB device.

## Function Reference

`SerialUsb.print(...)`
`SerialUsb.println(...)`
  Writes data into the port buffer to be transmitted as soon as possible. Accepts strings (character arrays). If a raw integer is passed the corresponding ASCII character will be transmitted; to print out a number in human readable form add a second parameter with the base system. Eg, to print out the decimal number '1234' use `print(1234,DEC)`; to print out the binary numner '1001' use `print(9,BIN)`.
`SerialUsb.available()`
`SerialUsb.read()`
  `read()` will return any data that has been recieved over the port and `available()` will tell if any such data acutally exists, and if so how many bytes. If there is no data `read()` will block/fail, so the usual program structure is to poll with `available()` and only `read()` if there's something ready.

## Recommended Reading

- USB in a NutShell overview from Beyond Logic
- Wikipedia article on Universal Serial Bus (USB)
- Linux Kernel documentation for USB ACM and USB Serial
- STMicro documentation for STM32F103RB microcontroller:
  - All
  - Datasheet (pdf)
  - Reference Manual (pdf)

### About this Document

A more recent version of this document may be available from the LeafLabs website. Our documentation is versioned on github; you can track changes to the master branch at this link.

This documentation is released under a Creative Commons Attribution-Share Alike 3.0 license.

Translations are welcomed; give us a ping to make sure we aren't in the process of revising or editing first.