Basic questions on USB (MC9S08JM)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Basic questions on USB (MC9S08JM)

Jump to solution
1,812 Views
leesp
Contributor I

I am learning the implementation of USB on MC9S08JM. I have a few questions:

 

- What is meant by a USB transaction? For example in a Control Transfer, does it mean the completion of each phase (Setup phase, Data phase, Handshake phase), or the completion of all 3 phases?

 

- The TOKDNE interrupt is triggered after each phase, or after the 3 phases has completed?

 

- If TOKDNE interrupt is triggered after each phase - that means for the entire Control Transfer, 3 interrupts will be triggered. How does the CPU handle each interrupt?

Labels (1)
0 Kudos
Reply
1 Solution
681 Views
Tsuneo
Contributor IV

> - What is meant by a USB transaction? For example in a Control Transfer, does it mean the completion of each phase (Setup phase, Data phase, Handshake phase), or the completion of all 3 phases?

You are mixing up Packet with Transaction.
The hierarchy of USB communication consists of three layers,
Packet - Transaction - Transfer

Setup, Data, Handshake phases are the term applied to a Packet sequence, which makes up a Transaction. These Packets in a Transaction are tightly bound in sequence and timing. And then, Transfer consists of one or more Transactions.

Control Transfer includes SETUP, DATA, STATUS stages. SETUP stage is single SETUP Transaction. DATA and STATUS stages are made up by one or more Transactions (include NAKed Transaction).

Refer this web page for the details.

USB Made Simple - Part 3
http://www.usbmadesimple.co.uk/ums_3.htm

Packets are handled by USB hardware (SIE: Serial Interface Engine) of MCU automatically, without any intervention of firmware. It's because the required response time is too short to be fully processed by firmware (inter-packet delay / bus turn-around time, 7.5 bit time max).

SIE notifies to firmware at the timing when a Transaction completes successfully by ACK, over a register flag / hardware interrupt. Usually, firmware sets up SIE so that NAKed and error Transactions are not reported, unless in debug.

In short, SIE processes from Packet to Transaction. Firmware writes down the processes from Transaction to Transfer, and upper protocol over Transfer. For firmware, a Transaction is the minimum unit of USB communication.

A Transaction carries zero or more data.
SETUP Transaction always brings 8 bytes SETUP data from host to firmware.
DATA stage of Control Transfer include one or more Transactions. When the data size is greater than bMaxPacketSize0 on the Device Descriptor, the data is split into multiple Transactions. Firmware should respond to each Transaction on DATA stage.
In the view from firmware, STATUS stage is a single no data (ZLP: Zero-Length Packet) Transaction. But on the SIE side, it may include NAKed Transaction(s) before ZLP.

To cancel the request carried by a Control Transfer, a Transaction in DATA or STATUS stage may be STALLed.


> - The TOKDNE interrupt is triggered after each phase, or after the 3 phases has completed?

Neither.
TOKDNE is set by SIE when a Transaction completes with ACK on one of EP (EndPoint).

When it is a SETUP Transaction of SETUP stage,
- STAT register points the default Endpoint (EP0) OUT
- TSUSPEND bit on CTL register is also set by the SIE.

When it is a Transaction of DATA or STATUS stage,
- STAT register points EP0 OUT or EP0 IN
- TSUSPEND bit is not set.

When it is a Transaction of EP other than EP0
- STAT register points target EP OUT or IN
- TSUSPEND bit is not set.

Control Transfer is usually managed in a state machine (or a couple of flags).
It's because
- Control Transfer consists of two or more Transactions. The number and direction of Transactions depends on the request carried by the Control Transfer.
- The interval between Transactions may vary from 100us to 1ms or so. Until your firmware receives next Transaction on EP0, your firmware does other process of your own.


I recommend you to read a decent USB stack code fully with this new background, before trying to write it by yourself from scratch.

Anyway, understanding of Packet - Transaction - Transfer hierarchy, and implementation of Control Transfer management are serious hurdles on the USB stack coding for beginners. I hope this post help you.

Tsuneo

View solution in original post

1 Reply
682 Views
Tsuneo
Contributor IV

> - What is meant by a USB transaction? For example in a Control Transfer, does it mean the completion of each phase (Setup phase, Data phase, Handshake phase), or the completion of all 3 phases?

You are mixing up Packet with Transaction.
The hierarchy of USB communication consists of three layers,
Packet - Transaction - Transfer

Setup, Data, Handshake phases are the term applied to a Packet sequence, which makes up a Transaction. These Packets in a Transaction are tightly bound in sequence and timing. And then, Transfer consists of one or more Transactions.

Control Transfer includes SETUP, DATA, STATUS stages. SETUP stage is single SETUP Transaction. DATA and STATUS stages are made up by one or more Transactions (include NAKed Transaction).

Refer this web page for the details.

USB Made Simple - Part 3
http://www.usbmadesimple.co.uk/ums_3.htm

Packets are handled by USB hardware (SIE: Serial Interface Engine) of MCU automatically, without any intervention of firmware. It's because the required response time is too short to be fully processed by firmware (inter-packet delay / bus turn-around time, 7.5 bit time max).

SIE notifies to firmware at the timing when a Transaction completes successfully by ACK, over a register flag / hardware interrupt. Usually, firmware sets up SIE so that NAKed and error Transactions are not reported, unless in debug.

In short, SIE processes from Packet to Transaction. Firmware writes down the processes from Transaction to Transfer, and upper protocol over Transfer. For firmware, a Transaction is the minimum unit of USB communication.

A Transaction carries zero or more data.
SETUP Transaction always brings 8 bytes SETUP data from host to firmware.
DATA stage of Control Transfer include one or more Transactions. When the data size is greater than bMaxPacketSize0 on the Device Descriptor, the data is split into multiple Transactions. Firmware should respond to each Transaction on DATA stage.
In the view from firmware, STATUS stage is a single no data (ZLP: Zero-Length Packet) Transaction. But on the SIE side, it may include NAKed Transaction(s) before ZLP.

To cancel the request carried by a Control Transfer, a Transaction in DATA or STATUS stage may be STALLed.


> - The TOKDNE interrupt is triggered after each phase, or after the 3 phases has completed?

Neither.
TOKDNE is set by SIE when a Transaction completes with ACK on one of EP (EndPoint).

When it is a SETUP Transaction of SETUP stage,
- STAT register points the default Endpoint (EP0) OUT
- TSUSPEND bit on CTL register is also set by the SIE.

When it is a Transaction of DATA or STATUS stage,
- STAT register points EP0 OUT or EP0 IN
- TSUSPEND bit is not set.

When it is a Transaction of EP other than EP0
- STAT register points target EP OUT or IN
- TSUSPEND bit is not set.

Control Transfer is usually managed in a state machine (or a couple of flags).
It's because
- Control Transfer consists of two or more Transactions. The number and direction of Transactions depends on the request carried by the Control Transfer.
- The interval between Transactions may vary from 100us to 1ms or so. Until your firmware receives next Transaction on EP0, your firmware does other process of your own.


I recommend you to read a decent USB stack code fully with this new background, before trying to write it by yourself from scratch.

Anyway, understanding of Packet - Transaction - Transfer hierarchy, and implementation of Control Transfer management are serious hurdles on the USB stack coding for beginners. I hope this post help you.

Tsuneo