The firmware performs error checking on the command fields of the USB SETUP Token Command Register. If it encounters an incorrect field, the MCU instructs the Endpoint 0 hardware block to send the STALL command on the USB bus:
1. Clear USB SETUP Counter Register
2. Set ER bit in the USB Control Register
The structure of the MCU firmware for handling either the standard USB commands (refer to USB Specification, Revision 1.1, Chapter 9) or the two vendor-specific commands maps to one of the following categories:
• OUT type commands with no data stage (USB Specification, Revision 1.1, Chapter 9)
• IN type commands with a single data stage (USB Specification, Revision 1.1, Chapter 9)
• IN type commands with variable-length data stages (USB Specification, Revision 1.1, Chapter 9)
• IN or OUT type commands with a single data stage that are non-Chapter 9 specific.
• MCU Firmware Download to RAM
As noted, the first three types are specific to the standard USB requests outlined in Chapter 9 of the USB specification. Type 4 is for any vendor-specific command or USB class-specific request and is used to access device hardware either local to the USB block (MCU register space) or chip-wide (DSP register space via the PDC bus). Type 5 is specific to downloading MCU firmware to PM RAM.
Commands of this type usually involve writes to certain registers or changes to hardware states without the need of additional data stages in the transaction. Once the appropriate task is completed, the MCU performs the following housekeeping steps:
1. Clears the USB Setup Counter Register
2. Clears its internal ‘command_complete’ status variable
3. Clears the high byte of USB Control Register
MCU returns to its idle loop to await the next interrupt from the Endpoint 0 hardware block. Examples in the MCU firmware that support USB commands of this type:
Set Feature, Clear Feature, Set Address
1. Read the USB Setup Token Command Register to check for command byte integrity. If any errors, instruct the Endpoint 0 hardware block to issue STALL command:
a. Clear the USB SETUP Counter Register
b. Set the ER bit in the USB Control Register
c. Return to the MCU idle loop
2. Load the appropriate data to be transmitted into the USB Setup Token Data Register.
3. Load the USB Setup Counter Register with the number of bytes to be transmitted.
4. Set the internal ‘command_complete’ status variable.
5. Clear the high byte of the USB Control Register
The MCU returns to its idle loop to await the next interrupt from the Endpoint 0 hardware block.
Examples in the MCU firmware that support USB commands of this type:
Get Status, Get Configuration
1. Read the upper byte of the USB Control Register to determine if this is the first time entering this code segment. Initial entry is indicated by bits ISE, IIN, IOU, and BY set to a 1.
2. If initial entry, read the USB Setup Token Command Register to check for command byte integrity. If any errors, instruct the Endpoint 0 hardware block to issue STALL command:
a. Clear the USB SETUP Counter Register
b. Set the ER bit in the USB Control Register
c. Return to the MCU idle loop
3. If no errors, read USB Setup Token Command Register bytes 6 and 7 to determine the number of bytes to transfer.
4. Begin a data transfer code segment. Re-entry into this segment repeats until all the data is sent. Proper code structure is:
a. Load the appropriate data to be transmitted into the USB Setup Token Data Register
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.