Freescale Semiconductor Microcontrollers User Manual

Page 320

Advertising
background image

HC08 Full Chip Simulation

Configuration Procedure

320

Microcontrollers Debugger Manual

* Vectors - Specifying Reset and USB Interrupt Routines *
**************************************************************
org VectorStart

dw dummy_isr ; TIM1 Overflow Vector
dw dummy_isr ; TIM1 Channel 1 Vector
dw dummy_isr ; TIM1 Channel 0 Vector
dw dummy_isr ; PLL Vector
dw dummy_isr ; IRQ Vector
dw USB_ENDP_ISR ; USB Endpoint Vector
dw USB_SYS_ISR ; USB System Vector
dw dummy_isr ; SWI Vector
dw main_init ; Reset Vector

This code utilizes three endpoints in the USB peripheral: endpoints 0, 1, and 2. As always,
all control transactions occur through endpoint 0. The other endpoints can be set up for
data transfer in the input or output direction, depending on whether data needs to be sent
or received to/from the host. Here, endpoint 1 is setup as an input pipe and endpoint 2 is
setup as an output pipe. The host becomes aware of whether an endpoint is an input or
output through the descriptor tables that are exchanged at the beginning of device
discovery.

It is necessary for the host and the slave to keep retention of the USB state of the device.
There are multiple states for the USB device. The module starts in the POWERED state.
When a USB reset is detected, the module is placed into the DEFAULT state. When the
device receives a SET_ADDRESS standard device request with a valid address, the
device is placed into the ADDRESSED state. Finally, when a SET_CONFIGURATION
standard device request is sent, the device is placed into the CONFIGURED state.

After the device is configured, endpoint 1 is enabled for interrupt transfers from the host.
Endpoint 1 is only capable of sending information out from it. Therefore, only IN packets
are accepted at the endpoint. The report descriptor sets up the endpoint to transfer only 1
byte of data. So when an IN packet comes from the host, the device sends out the data read
from the Port B input pins. Note that the internal pull-ups are enabled for PORTB in the
code (PULLCR), so the default input value sent through endpoint 1 is $FF.

After the device is configured, endpoint 2 is enabled for bulk transfers. Endpoint 2 is only
capable of reading information into it. Therefore, only OUT packets are accepted at the
endpoint. The report descriptor sets up the endpoint to read, at most, 8 bytes of data. So
when an OUT packet comes from the PC, the device reads the data from the packet into a
local buffer.

So, how is the code laid out in order to handle this? The beginning of the code shows
symbol defines for addresses within memory for RAM, Flash, interrupt vectors, and
buffers for USB endpoints. Also included are the register file definitions, which give the
addresses of peripheral registers on the microcontroller. Following this comes the variable
declarations for control packets, pointers, and received data.

Advertising