en:pfw:usb_cdc_driver_for_rp2040
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:pfw:usb_cdc_driver_for_rp2040 [2025-12-27 13:43] – [Implementation example] willem | en:pfw:usb_cdc_driver_for_rp2040 [2026-01-13 18:16] (current) – [The idea] willem | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| hex | hex | ||
| Function: DEVICE-DECRIPTOR \ 18 bytes | Function: DEVICE-DECRIPTOR \ 18 bytes | ||
| - | 12 c, 01 c, 10 c, 01 c, ( 1.10 ) EF c, 02 c, 01 c, 40 c, 66 c, 66 c, ( 6666 ) | + | The USB CDC device descriptor |
| - | 10 c, 66 c, ( 6610 ) 00 c, 01 c, ( vsn 1.00 ) 00 c, 02 c, 00 c, 01 c, align | + | |
| Function: CONFIGURATION-DESCRIPTOR \ 9 or 75 bytes | Function: CONFIGURATION-DESCRIPTOR \ 9 or 75 bytes | ||
| - | 9 c, 2 c, 4B c, 0 c, 2 c, 1 c, 0 c, 80 c, FA c, \ Maximum power = 500mA | + | The complex USB CDC device |
| - | 8 c, 0B c, 0 c, 2 c, 2 c, 2 c, 1 c, 0 c, \ Interface Association Descriptor - CDC 0 | + | |
| - | 9 c, 4 c, 0 c, 0 c, 1 c, 2 c, 2 c, 1 c, 0 c, \ Interface 1: Control - 1 - 0 - | + | |
| - | 5 c, 24 c, 0 c, 10 c, 1 c, ( CDC vsn 1.10 ) \ CDC Header functional | + | |
| - | 5 c, 24 c, 1 c, 0 c, 1 c, \ CDC Call management functional | + | |
| - | 4 c, 24 c, 2 c, 2 c, \ CDC ACM functional ( two commands ) | + | |
| - | 5 c, 24 c, 6 c, 0 c, 1 c, \ CDC Union functional ( one interface ) | + | |
| - | 7 c, 5 c, 81 c, 3 c, 8 c, 0 c, 10 c, \ Endpoint 1 IN descriptor | + | |
| - | 9 c, 4 c, 1 c, 0 c, 2 c, 0A c, 0 c, 0 c, 0 c, \ Interface 2: DATA | + | |
| - | 7 c, 5 c, 82 c, 2 c, 40 c, 0 c, 0 c, \ Endpoint 2 IN descriptor | + | |
| - | 7 c, 5 c, 3 c, 2 c, 40 c, 0 c, 0 c, align \ Endpoint 3 OUT descriptor | + | |
| - | decimal | + | Function: USB-STATE |
| - | Function: USB-STATE | + | Hold current USB state in first half word: 3 = ready |
| - | \ In second half word are memory for the 900/880 requests | + | In second half word are memory for the 900/880 requests |
| - | 4 c, 3 c, 9 c, 4 c, \ English/ | + | The English/US language ID string |
| - | | + | CDC Line data: 115k2, Stop bits, Parity, Data bits |
| - | hex | + | Function: START-USB |
| - | Function: START-USB | + | Initialise the RP2040 USB hardware, restart the USB hardware, |
| - | | + | erase the USB DPRAM, enable USB controller, set USB address to zero. |
| - | | + | Setup used endpoints and used interrupts & enable full speed USB. |
| - | | + | |
| - | | + | Function: PAD |
| - | | + | Reserve 64 bytes RAM as scratchpad area |
| - | | + | |
| - | | + | Function: EP0 ( -- a ) |
| - | | + | Function: EP1 ( -- a ) |
| - | | + | Function: EP2 ( -- a ) |
| - | | + | Function: EP3 ( -- a ) |
| - | | + | Seven cells data structures to control endpoint-0, 1, 2 & 3 |
| - | | + | The first four cells a variable data |
| - | | + | The three cells thereafter contain USB pointers |
| - | | + | |
| + | Function: @VAL ( -- +n ) | ||
| + | Read the wValue from any eight bytes setup packet | ||
| + | Function: @LEN ( -- +n ) | ||
| + | Read the wLength from any eight bytes setup packet | ||
| + | |||
| + | Function: > | ||
| + | Store the ASCII string to a unicode string tailored for USB | ||
| + | |||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Function: > | ||
| + | Seven functions that calculate the address of each field in the | ||
| + | endpoint data structures | ||
| + | |||
| + | Function: EP-IN ( ep -- org buf pkt ) | ||
| + | Calculate data to send for ' | ||
| + | |||
| + | Function: PREPARE | ||
| + | Prepare data packet from address ' | ||
| + | |||
| + | Function: > | ||
| + | Get next packet size for ' | ||
| + | data to send | ||
| + | |||
| + | Function: | ||
| + | Store next packet to send for ' | ||
| + | |||
| + | Function: PREP-RCV ( ep -- ) | ||
| + | Enable | ||
| + | |||
| + | Function: GONE? ( ep -- f ) | ||
| + | Leave true when the data in ' | ||
| + | |||
| + | Function: USB? | ||
| + | Leave three when the host & device are connected | ||
| + | |||
| + | Function: USB-SEND ( ep -- ) | ||
| + | Transmit the prepared data packet | ||
| + | |||
| + | Function: USB-RCV | ||
| + | Enable the receiving of a data packet | ||
| + | from the stack | ||
| + | |||
| + | Function: BUS=RESET ( -- ) | ||
| + | Handle a USB bus reset, clearing the device address to zero, the USB | ||
| + | state to zero, reinitialise the receiving & transmitting endpoints | ||
| + | |||
| + | Function: SETUP> | ||
| + | Handle the answer data packet ' | ||
| + | When done wait for a ZLP from the host to signal a correct answer | ||
| + | |||
| + | Function: XTABLE | ||
| + | | ||
| + | | ||
| + | Create a table with " | ||
| + | Action: | ||
| + | Execute the action for ' | ||
| + | when the ' | ||
| + | |||
| + | Function: ZLP> | ||
| + | Send a zero length package through | ||
| + | to signal the handling of a request that sends no data back | ||
| + | |||
| + | Define four action | ||
| + | 0302 action xt | ||
| + | 0300 action xt | ||
| + | 0200 action xt | ||
| + | 0100 action xt | ||
| + | Function: HANDLE-SETUP ( req0 .. req3 4 -- ) | ||
| + | |||
| + | 2221 action xt | ||
| + | 21A1 action xt | ||
| + | 2021 action xt | ||
| + | 0900 action xt | ||
| + | 0880 action xt | ||
| + | 0680 action xt | ||
| + | 0500 action xt | ||
| + | Function: HANDLE-REQ) | ||
| + | |||
| + | Function: HANDLE-REQ | ||
| + | Reset setup request interrupt, read bmrequest type and do HANDLE-REQ) | ||
| + | |||
| + | Function: #L ( -- +n ) | ||
| + | Ring buffer | ||
| + | Function: #R ( -- +n ) | ||
| + | this is equal to #L - 1 | ||
| + | |||
| + | Function: #RX ( -- +n ) | ||
| + | Leave number of characters | ||
| + | Function: #TX ( -- +n ) | ||
| + | Leave number of characters in transmit buffer | ||
| + | |||
| + | Function: > | ||
| + | Store character ' | ||
| + | Function: > | ||
| + | Store character ' | ||
| + | |||
| + | Function: RX> | ||
| + | Read character ' | ||
| + | Function: TX> | ||
| + | Read character ' | ||
| + | |||
| + | Function: IFLAG | ||
| + | Reserve one cell space for receive interrupt flag | ||
| + | |||
| + | Function: ENDPOINTS | ||
| + | Handle EP1 & EP3 endpoints, save received data interrupt flag in IFLAG | ||
| + | Release all interrupt flags | ||
| + | |||
| + | Function: REQUESTS | ||
| + | Handle all USB interrupts, that are the USB bus reset, setup requests & endpoints | ||
| + | |||
| + | Function: USB-HANDLER | ||
| + | Handle the receiving of the RX data using iFLAG and use the low level USB | ||
| + | ACK/NAK handshake to move data from an endpoint | ||
| + | Handle the transmitting of TX data, but only when a connection is made. Before filling | ||
| + | the TX endpoint check if the previous data packet was sent too. | ||
| + | |||
| + | Function: USB-KEY? | ||
| + | Leave true flag when there is data in the RX ring buffer, otherwise false | ||
| + | Call the USB-HANDLER once too | ||
| + | |||
| + | Function: USB-KEY | ||
| + | Leave character ' | ||
| + | Call the USB-HANDLER waiting for space in the RX ring buffer | ||
| + | |||
| + | Function: USB-EMIT | ||
| + | Store character ' | ||
| + | Call the USB-HANDLER waiting for space in the TX ring buffer | ||
| + | |||
| + | Function: USB-ON | ||
| + | Initialise the USB DPRAM, call START-USB, clear USB-STATE & IFLAG | ||
| + | finally initialse the KEY?, KEY and EMIT vectors of the used system. | ||
| </ | </ | ||
| - | ===== Implementation | + | ===== Generic Forth implementation |
| <code forth> | <code forth> | ||
| Line 296: | Line 422: | ||
| </ | </ | ||
| + | ===== Implementations ===== | ||
| + | |||
| + | [[https:// | ||
en/pfw/usb_cdc_driver_for_rp2040.1766839382.txt.gz · Last modified: 2025-12-27 13:43 by willem