Interconnectivity
Page 12 of 22
Firmware Programming Guide for PDIUSBD12
Philips Semiconductors - Asia Product Innovation Centre
Visit
http://www.flexiusb.com
Next, MCU will need to verify whether the control transfer is a Control Read/Write. This can be achieved
through reading the 8th bit of the bmRequestType from the setup packet. In our case, the control transfer is a
Control Read type, that is, the device will need to send data packet back to the host in the coming data phase.
MCU will need to set a flag to indicate that the USB device is now in the transmit mode, that is, ready to send
its data upon the host's request.
After the Setup stage is finished, the host will execute the data phase. D12 will expect to receive the Control_In
packet. The process is shown in the next flowchart, "Control_In Handler". Again, MCU will first need to clear
the Control_In interrupt Bit on the D12 by reading its Read Last Transaction Register. Then, MCU will proceed
to send the data packet after verifying that D12 is in the appropriate mode, that is, the Transmit mode.
As D12 control endpoint has only 16 bytes FIFO, MCU will have to control the amount of data during the
transmitting phase if the requested length is more than 16 bytes. As indicated on the flowchart, MCU will have
to check its current and remaining size of the data to be sent to the host. If the remaining bytes are greater than
16 bytes, MCU will send the first 16 bytes and then subtract the reference length (requested length) by 16.
When the next Control_In token comes, MCU will determine whether the remaining bytes is zero. If there is no
more data to send, MCU will need to send an empty packet to inform the host that there will be no more data to
be sent over.
If the setup packet is Set_Descriptor() request, then the control transfer in the setup packet will indicate that it is
a Control Write type. After executing the procedure for the Set_Descriptor request, MCU will wait for the data
phase. The host will send a Control_Out token and MCU will have to extract the data from the D12 buffer. The
flow will now be on the right side of the Control_Out Handler flow sequence. MCU will have to first verify
whether D12 is in the USB_Receive mode. Then, MCU will have to verify whether the buffer is full by
checking the Select Control_Out Endpoint and read the data out from the buffer.
The flowchart above shows the Control In handler.
Control In Handler
Clear Control In Interrupt Bit
State USB_TRANSMIT?
Remaining Bytes > EP0
Packet Size?
Yes
Write Control In Buffer with Data Size
of EP0 Packet Size
State <- USB_TRANSMIT
Write Control In Buffer with Data Size
of EP0 Packet Size
State <- USB_IDLE
Remaining Bytes = 0?
Send Empty Packet
State <- USB_IDLE
End of Control In Handler
Yes
No
No
Yes
No