libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
USB

libopencm3 LM4F Universal Serial Bus controller More...

Collaboration diagram for USB:

Macros

#define MAX_FIFO_RAM   (4 * 1024)
 

Functions

void usb_enable_interrupts (enum usb_interrupt ints, enum usb_ep_interrupt rx_ints, enum usb_ep_interrupt tx_ints)
 Enable Specific USB Interrupts. More...
 
void usb_disable_interrupts (enum usb_interrupt ints, enum usb_ep_interrupt rx_ints, enum usb_ep_interrupt tx_ints)
 Disable Specific USB Interrupts. More...
 

Variables

const struct _usbd_driver lm4f_usb_driver
 

Detailed Description

libopencm3 LM4F Universal Serial Bus controller

Author
© 2013 Alexandru Gagniuc mr.nu.nosp@m.ke.m.nosp@m.e@gma.nosp@m.il.c.nosp@m.om

The LM4F USB driver is integrated with the libopencm3 USB stack. You should use the generic stack.

To use this driver, tell the linker to look for it:

const usbd_driver lm4f_usb_driver
Definition: usb_lm4f.c:113
struct _usbd_driver usbd_driver
Definition: usbd.h:52

And pass this driver as an argument when initializing the USB stack:

usbd_device *usbd_dev;
usbd_dev = usbd_init(&lm4f_usb_driver, ...);
struct _usbd_device usbd_device
Definition: usbd.h:53
usbd_device * usbd_init(const usbd_driver *driver, const struct usb_device_descriptor *dev, const struct usb_config_descriptor *conf, const char *const *strings, int num_strings, uint8_t *control_buffer, uint16_t control_buffer_size)
Main initialization entry point.
Definition: usb.c:42

Polling or interrupt-driven?

The LM4F USB driver will work fine regardless of whether it is called from an interrupt service routine, or from the main program loop.

Polling USB from the main loop requires calling usbd_poll() from the main program loop. For example:

// Main program loop
while(1) {
usbd_poll(usb_dev);
do_other_stuff();
...
void usbd_poll(usbd_device *usbd_dev)
Definition: usb.c:126

Running usbd_poll() from an interrupt has the advantage that it is only called when needed, saving CPU cycles for the main program.

RESET, DISCON, RESUME, and SUSPEND interrupts must be enabled, along with the interrupts for any endpoint that is used. The EP0_TX interrupt must be enabled for the control endpoint to function correctly. For example, if EP1IN and EP2OUT are used, then the EP0_TX, EP1_TX, and EP2_RX interrupts should be enabled:

// Enable USB interrupts for EP0, EP1IN, and EP2OUT
// Route the interrupts through the NVIC
#define NVIC_USB0_IRQ
Definition: lm3s/nvic.h:60
void nvic_enable_irq(uint8_t irqn)
NVIC Enable Interrupt.
Definition: nvic.c:57
void usb_enable_interrupts(enum usb_interrupt ints, enum usb_ep_interrupt rx_ints, enum usb_ep_interrupt tx_ints)
Enable Specific USB Interrupts.
Definition: usb_lm4f.c:132
@ USB_INT_RESUME
Definition: usb.h:392
@ USB_INT_SUSPEND
Definition: usb.h:393
@ USB_INT_RESET
Definition: usb.h:391
@ USB_INT_DISCON
Definition: usb.h:389
@ USB_EP2_INT
Definition: usb.h:399
@ USB_EP1_INT
Definition: usb.h:398
@ USB_EP0_INT
Definition: usb.h:397

The USB ISR only has to call usbd_poll().

void usb0_isr(void)
{
usbd_poll(usb_dev);
}
void usb0_isr(void)

Macro Definition Documentation

◆ MAX_FIFO_RAM

#define MAX_FIFO_RAM   (4 * 1024)

Definition at line 111 of file usb_lm4f.c.

Function Documentation

◆ usb_disable_interrupts()

void usb_disable_interrupts ( enum usb_interrupt  ints,
enum usb_ep_interrupt  rx_ints,
enum usb_ep_interrupt  tx_ints 
)

Disable Specific USB Interrupts.

Disable any combination of interrupts. Interrupts may be OR'ed together to enable them with one call. For example, to disable both the RESUME and RESET interrupts, pass (USB_INT_RESUME | USB_INT_RESET)

Note that the NVIC must be enabled and properly configured for the interrupt to be routed to the CPU.

Parameters
[in]intsInterrupts which to disable. Any combination of interrupts may be specified by OR'ing then together
[in]rx_intsEndpoints for which to stop generating an interrupt when a packet packet is received.
[in]tx_intsEndpoints for which to stop generating an interrupt when a packet packet is finished transmitting.

Definition at line 158 of file usb_lm4f.c.

References USB_IE, USB_RXIE, and USB_TXIE.

◆ usb_enable_interrupts()

void usb_enable_interrupts ( enum usb_interrupt  ints,
enum usb_ep_interrupt  rx_ints,
enum usb_ep_interrupt  tx_ints 
)

Enable Specific USB Interrupts.

Enable any combination of interrupts. Interrupts may be OR'ed together to enable them with one call. For example, to enable both the RESUME and RESET interrupts, pass (USB_INT_RESUME | USB_INT_RESET)

Note that the NVIC must be enabled and properly configured for the interrupt to be routed to the CPU.

Parameters
[in]intsInterrupts which to enable. Any combination of interrupts may be specified by OR'ing then together
[in]rx_intsEndpoints for which to generate an interrupt when a packet packet is received.
[in]tx_intsEndpoints for which to generate an interrupt when a packet packet is finished transmitting.

Definition at line 132 of file usb_lm4f.c.

References USB_IE, USB_RXIE, and USB_TXIE.

Variable Documentation

◆ lm4f_usb_driver

const struct _usbd_driver lm4f_usb_driver

Definition at line 113 of file usb_lm4f.c.