29.01.2015 Views

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

USB on-the-go full-speed (OTG_FS)<br />

RM0008<br />

26.15.4 Host programming model<br />

Channel initialization<br />

The application must initialize one or more channels before it can communicate with<br />

connected devices. To initialize <strong>and</strong> enable a channel, the application must perform the<br />

following steps:<br />

1. Program the GINTMSK register to unmask the following:<br />

2. Channel interrupt<br />

– Non-periodic transmit FIFO empty for OUT transactions (applicable for Slave<br />

mode that operates in pipelined transaction-level with the packet count field<br />

programmed with more than one).<br />

– Non-periodic transmit FIFO half-empty for OUT transactions (applicable for Slave<br />

mode that operates in pipelined transaction-level with the packet count field<br />

programmed with more than one).<br />

3. Program the OTG_FS_HAINTMSK register to unmask the selected channels’<br />

interrupts.<br />

4. Program the OTG_FS_HCINTMSK register to unmask the transaction-related<br />

interrupts of interest given in the host channel interrupt register.<br />

5. Program the selected channel’s OTG_FS_HCTSIZx register with the total transfer size,<br />

in bytes, <strong>and</strong> the expected number of packets, including short packets. The application<br />

must program the PID field with the initial data PID (to be used on the first OUT<br />

transaction or to be expected from the first IN transaction).<br />

6. Program the OTG_FS_HCCHARx register of the selected channel with the device’s<br />

endpoint characteristics, such as type, speed, direction, <strong>and</strong> so forth. (The channel can<br />

be enabled by setting the channel enable bit to 1 only when the application is ready to<br />

transmit or receive any packet).<br />

Halting a channel<br />

The application can disable any channel by programming the OTG_FS_HCCHARx register<br />

with the CHDIS <strong>and</strong> CHENA bits set to 1. This enables the OTG_FS host to flush the posted<br />

requests (if any) <strong>and</strong> generates a channel halted interrupt. The application must wait for the<br />

CHH interrupt in OTG_FS_HCINTx before reallocating the channel for other transactions.<br />

The OTG_FS host does not interrupt the transaction that has already been started on the<br />

USB.<br />

Before disabling a channel, the application must ensure that there is at least one free space<br />

available in the non-periodic request queue (when disabling a non-periodic channel) or the<br />

periodic request queue (when disabling a periodic channel). The application can simply<br />

flush the posted requests when the Request queue is full (before disabling the channel), by<br />

programming the OTG_FS_HCCHARx register with the CHDIS bit set to 1, <strong>and</strong> the CHENA<br />

bit cleared to 0.<br />

The application is expected to disable a channel on any of the following conditions:<br />

1. When an XFRC interrupt in OTG_FS_HCINTx is received during a non-periodic IN<br />

transfer or high-b<strong>and</strong>width interrupt IN transfer (Slave mode only)<br />

2. When an STALL, TXERR, BBERR or DTERR interrupt in OTG_FS_HCINTx is received<br />

for an IN or OUT channel (Slave mode only). For high-b<strong>and</strong>width interrupt INs in Slave<br />

mode, once the application has received a DTERR interrupt it must disable the channel<br />

<strong>and</strong> wait for a channel halted interrupt. The application must be able to receive other<br />

interrupts (DTERR, Nak, Data, TXERR) for the same channel before receiving the halt.<br />

794/995 Doc ID 13902 Rev 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!