en:pfw:usb_cdc_driver_for_rp2040
**This is an old revision of the document!**
Table of Contents
USB CDC driver for RP2040
The idea
This is a compact and universal MSP430 USB CDC driver. Every effort has been made to make it portable.
What we need to do in short
- Initialising the USB hardware on the RP2040.
- Receiving and responding to setup packets from the host (PC). This determines which driver the OS will load.
- If the host is satisfied with the setup, then sending and receiving data packets may start.
Pseudo code
hex
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 )
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
9 c, 2 c, 4B c, 0 c, 2 c, 1 c, 0 c, 80 c, FA c, \ Maximum power = 500mA
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 0 , \ Hold current USB state in first half word: 3 = ready
\ In second half word are memory for the 900/880 requests
4 c, 3 c, 9 c, 4 c, \ English/US = language ID
115200 , 0 c, 0 c, 8 c, align \ Line data: 115k2, Stop bits, Parity, Data bits
hex
Function: START-USB ( -- ) \ Initialise the RP2040 USB hardware
1000000 4000C000 \ Bit-24 mask & Reset register
2dup **bis 2dup **bic \ Restart USB
begin 2dup 8 + bit** until \ Wait until USB is ready
2drop 50100000 1000 false fill \ Erase USB ram
00000009 50110074 ! \ USB_USB_MUXING Softcon, to PHY
0000000C 50110078 ! \ USB_USB_PWR VBUS overide & detect enable
00000001 50110040 ! \ USB_MAIN_CTRl Enable controller
20000000 5011004C ! \ USB_SIE_CONTROL Enable End Point 0 interrupt
false 50110000 ! \ Respond to address 0 on initial setup
00011010 50110090 ! \ USB_INTE Enable 3 interrupts
AC000180 50100008 ! \ init COMM endpoint in buffer 1
A8000200 50100010 ! \ init SEND endpoint in buffer 2
A8000280 5010001C ! \ init RECV endpoint out buffer 3
00010000 5011204C ! ; \ USB_SIE_CONTROL Enable pull up
Implementation example
en/pfw/usb_cdc_driver_for_rp2040.1766837011.txt.gz · Last modified: 2025-12-27 13:03 by willem