Freescale Semiconductor Microcontrollers User Manual

Page 321

Advertising
background image

HC08 Full Chip Simulation

Configuration Procedure

321

Microcontrollers Debugger Manual

In the FLASH, the descriptor tables are created, which describe the type of USB device,
the configuration, the interface, HID specific information, the endpoints, and reporting
information. All information needed in these descriptors, can be found in the Freescale
documentation describing USB module specifications for the microprocessor that you are
using.

After the descriptors comes the actual code, where numerous procedures are described,
meant to handle different tasks. The first is the initialization procedure, which sets up the
registers for the USB peripheral for the intended operation. The USB peripheral is also
enabled at the end of the routine. The next several procedures are specifically for USB
operation, such as: forcing a device stall, sending the device descriptors to the host,
handling SETUP packets, handling IN packets, and processing OUT packets. After this
comes the start of the application in the MAIN_INIT procedure, where we call the
initialization routines and wait for an interrupt to occur. There are two interrupt service
routines for the USB peripheral in this code: one for endpoint events that occur, and the
other for USB system events such as setups, stalls, and resets. Note that this application is
totally interrupt driven, where the code is driven by any events that take place in the USB
peripheral.

The end of the code shows the interrupt vectors for the microcontroller, where the USB
interrupts and the RESET vector are included. All other vectors are pointed to a dummy
interrupt service routine that simply just returns from the interrupt.

Once the mentioned above assembly code is compiled as a part of the Freescale project,
one can step through in the Full Chip Simulation mode. The execution starts automatically
at the reset location within the code. We are now ready to start debugging the code.

First, we need to step through the beginning of the code in the simulator in order to allow
the code to initialize the microcontroller and the USB peripheral and get ready to start
receiving USB packets from the host. So, the user needs to step through the beginning of
the code until they get to the main loop with the ’t’ command.

At this point we are ready for USB packets to come into the device. There are four specific
commands in the FCS for simulating external input/output as well as reset and clear
functionality of the USB peripheral: USBRESET, USBIN, USBOUT, and USBCLR (for
more detailed information, refer to the USB commands section). The USBRESET
command causes a USB reset, which is identical to a host trying to reset a slave USB
device once it connects to the bus. The USBIN command allows a user to specify packets
coming into the USB peripheral. The USBOUT command allows a user to see the packets
that were sent out from the USB peripheral. The USBCLR command allows the user to
clear all input and output buffers of USB packets. The first command to use for testing the
USB peripheral is the USBRESET command, which places the USB peripheral in the
RESET state. After the USBRESET command, step through the code with a t command to
enter the system interrupt service routine. Enter the t command a few more times to exit
the ISR and return to the main loop.

Advertising