Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB: refactor to xmit-based API #17064

Merged
merged 10 commits into from
Nov 17, 2021
Merged

USB: refactor to xmit-based API #17064

merged 10 commits into from
Nov 17, 2021

Conversation

bergzand
Copy link
Member

@bergzand bergzand commented Oct 26, 2021

Contribution description

This API change refactors the usbdev API to supply buffers via the
usbdev_ep_xmit function. This changes from the usbdev_ep_ready call to allow
separate buffers per call.

Main advantage is that the usbdev peripherals no longer have to allocate
oversized buffers for the endpoint data, potentially saving multiple KiB
of unused buffer space. These allocations are now the responsibility of
the individual USB interfaces in the firmware

An usbdev_ep_buf_t pseudotype is available and must
be used when defining buffers used for endpoints to adhere to the DMA alignment
restrictions often required with usb peripherals.

Testing procedure

usbdev implementations:

  • stm32
  • nrf52
  • sam0_common

Interfaces implemented:

  • CDC ECM
  • CDC ACM
  • HID

(DFU only uses control requests and didn't need adaptations)

Issues/PRs references

None

@bergzand bergzand requested a review from dylad October 26, 2021 17:51
@bergzand bergzand changed the title Pr/usbdev/xmit USB: refactor to xmit-based API Oct 26, 2021
@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: sys Area: System Area: tests Area: tests and testing framework Area: USB Area: Universal Serial Bus Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Oct 26, 2021
@bergzand bergzand added Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation and removed Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Oct 26, 2021
@bergzand
Copy link
Member Author

CDC-ECM on the three supported device types:

nRF52840dk
koen@morgen ~/dev/RIOT-usbdev2 $ make -C tests/usbus_cdc_ecm/ term BOARD=nrf52840dk
make: Entering directory '/home/koen/dev/RIOT-usbdev2/tests/usbus_cdc_ecm'
/home/koen/dev/RIOT-usbdev2/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-10-26 19:55:54,109 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
> ifconfig 4 add 2001:db8::2/64
2021-10-26 19:56:08,030 # ifconfig 4 add 2001:db8::2/64
2021-10-26 19:56:08,034 # success: added 2001:db8::2/64 to interface 4
> ping6 2001:db8::1
2021-10-26 19:56:25,109 # ping6 2001:db8::1
2021-10-26 19:56:25,116 # 12 bytes from 2001:db8::1: icmp_seq=0 ttl=64 time=1.640 ms
2021-10-26 19:56:26,101 # 12 bytes from 2001:db8::1: icmp_seq=1 ttl=64 time=0.685 ms
2021-10-26 19:56:27,087 # 12 bytes from 2001:db8::1: icmp_seq=2 ttl=64 time=0.635 ms
2021-10-26 19:56:27,087 # 
2021-10-26 19:56:27,090 # --- 2001:db8::1 PING statistics ---
2021-10-26 19:56:27,095 # 3 packets transmitted, 3 packets received, 0% packet loss
2021-10-26 19:56:27,099 # round-trip min/avg/max = 0.635/0.986/1.640 ms
> 
Nucleo-f746zg
koen@morgen ~/dev/RIOT-usbdev2 $ make -C tests/usbus_cdc_ecm/ term BOARD=nucleo-f746zg
make: Entering directory '/home/koen/dev/RIOT-usbdev2/tests/usbus_cdc_ecm'
/home/koen/dev/RIOT-usbdev2/dist/tools/pyterm/pyterm -p "/dev/ttyACM1" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-10-26 19:57:51,424 # Connect to serial port /dev/ttyACM1
Welcome to pyterm!
Type '/exit' to exit.
2021-10-26 19:58:42,021 # NETOPT_RX_END_IRQ not implemented by driver
2021-10-26 19:58:42,028 # main(): This is RIOT! (Version: 2022.01-devel-224-g4ae844-pr/usbdev/xmit)
2021-10-26 19:58:42,032 # Test application for the USBUS CDC ECM interface
2021-10-26 19:58:42,033 # 
2021-10-26 19:58:42,038 # This test pulls in parts of the GNRC network stack, use the
2021-10-26 19:58:42,043 # provided shell commands (i.e. ifconfig, ping6) to interact with
2021-10-26 19:58:42,046 # the CDC ECM based network interface.
2021-10-26 19:58:42,047 # 
2021-10-26 19:58:42,049 # Starting the shell now...
> ifconfig 4 add 2001:db8::2/64
2021-10-26 19:58:54,958 # ifconfig 4 add 2001:db8::2/64
2021-10-26 19:58:54,963 # success: added 2001:db8::2/64 to interface 4
> ping6 2001:db8::1
2021-10-26 19:59:02,221 # ping6 2001:db8::1
2021-10-26 19:59:02,228 # 12 bytes from 2001:db8::1: icmp_seq=0 ttl=64 time=1.285 ms
2021-10-26 19:59:03,227 # 12 bytes from 2001:db8::1: icmp_seq=1 ttl=64 time=0.505 ms
2021-10-26 19:59:04,227 # 12 bytes from 2001:db8::1: icmp_seq=2 ttl=64 time=0.605 ms
2021-10-26 19:59:04,227 # 
2021-10-26 19:59:04,230 # --- 2001:db8::1 PING statistics ---
2021-10-26 19:59:04,235 # 3 packets transmitted, 3 packets received, 0% packet loss
2021-10-26 19:59:04,240 # round-trip min/avg/max = 0.505/0.798/1.285 ms
> 
samr21-xpro
koen@morgen ~/dev/RIOT-usbdev2 $ make -C tests/usbus_cdc_ecm/ term BOARD=samr21-xpro
make: Entering directory '/home/koen/dev/RIOT-usbdev2/tests/usbus_cdc_ecm'
/home/koen/dev/RIOT-usbdev2/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-10-26 20:00:33,448 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2021-10-26 20:01:20,065 # NETOPT_RX_END_IRQ not implemented by driver
2021-10-26 20:01:20,072 # main(): This is RIOT! (Version: 2022.01-devel-224-g4ae844-pr/usbdev/xmit)
2021-10-26 20:01:20,077 # Test application for the USBUS CDC ECM interface
2021-10-26 20:01:20,077 # 
2021-10-26 20:01:20,082 # This test pulls in parts of the GNRC network stack, use the
2021-10-26 20:01:20,087 # provided shell commands (i.e. ifconfig, ping6) to interact with
2021-10-26 20:01:20,091 # the CDC ECM based network interface.
2021-10-26 20:01:20,091 # 
2021-10-26 20:01:20,093 # Starting the shell now...
> ifconfig 4 add 2001:db8::2/64
2021-10-26 20:01:23,758 # ifconfig 4 add 2001:db8::2/64
2021-10-26 20:01:23,763 # success: added 2001:db8::2/64 to interface 4
> ping6 2001:db8::164
2021-10-26 20:01:28,572 # ping6 2001:db8::1
2021-10-26 20:01:28,580 # 12 bytes from 2001:db8::1: icmp_seq=0 ttl=64 time=2.061 ms
2021-10-26 20:01:29,580 # 12 bytes from 2001:db8::1: icmp_seq=1 ttl=64 time=0.852 ms
2021-10-26 20:01:30,581 # 12 bytes from 2001:db8::1: icmp_seq=2 ttl=64 time=0.831 ms
2021-10-26 20:01:30,581 # 
2021-10-26 20:01:30,584 # --- 2001:db8::1 PING statistics ---
2021-10-26 20:01:30,590 # 3 packets transmitted, 3 packets received, 0% packet loss
2021-10-26 20:01:30,594 # round-trip min/avg/max = 0.831/1.248/2.061 ms
>
CDC-ACM on samr21-xpro

lsusb output:

koen@morgen ~/dev/RIOT-usbdev2 $ lsusb -v -d 1209:7d00

Bus 001 Device 121: ID 1209:7d00 Generic USB device
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x1209 Generic
  idProduct          0x7d00 
  bcdDevice            0.00
  iManufacturer           3 RIOT-os.org
  iProduct                2 USB device
  iSerial                 4 BB3072FFBF200CDA
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x004b
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          1 USB config
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass          2 Communications
      bFunctionSubClass       2 Abstract (modem)
      bFunctionProtocol       0 
      iFunction               0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      0 
      iInterface              0 
      CDC Header:
        bcdCDC               1.20
      CDC ACM:
        bmCapabilities       0x02
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      CDC Call Management:
        bmCapabilities       0x00
        bDataInterface          1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             255
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0000
  (Bus Powered)

Actual session:

koen@morgen ~/dev/RIOT-usbdev2 $ make -C examples/default/ BOARD=samr21-xpro PORT=/dev/ttyACM2 term
make: Entering directory '/home/koen/dev/RIOT-usbdev2/examples/default'
/home/koen/dev/RIOT-usbdev2/dist/tools/pyterm/pyterm -p "/dev/ttyACM2" -b "115200"  
python-exec: Invalid impl in /etc/python-exec/python-exec.conf: python3.7
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-10-26 20:04:51,152 # Connect to serial port /dev/ttyACM2
Welcome to pyterm!
Type '/exit' to exit.
2021-10-26 20:04:52,155 # main(): This is RIOT! (Version: 2022.01-devel-224-g4ae844-pr/usbdev/xmit)
2021-10-26 20:04:52,155 # RIOT USB CDC ACM shell test
> ps
2021-10-26 20:04:53,194 # ps
2021-10-26 20:04:53,196 #       pid | name                 | state    Q | pri | stack  ( used) ( free) | base addr  | current     
2021-10-26 20:04:53,197 #         - | isr_stack            | -        - |   - |    512 (  188) (  324) | 0x20000000 | 0x200001c0
2021-10-26 20:04:53,198 #         1 | main                 | running  Q |   7 |   1536 (  788) (  748) | 0x200007f0 | 0x20000adc 
2021-10-26 20:04:53,200 #         2 | usbus                | bl anyfl _ |   1 |   1024 (  588) (  436) | 0x20000284 | 0x20000504 
2021-10-26 20:04:53,201 #           | SUM                  |            |     |   3072 ( 1564) ( 1508)

@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Oct 26, 2021
@bergzand
Copy link
Member Author

HID on samr21-xpro
koen@morgen ~/dev/RIOT-usbdev2 $ make -C tests/usbus_hid/ BOARD=samr21-xpro term
make: Entering directory '/home/koen/dev/RIOT-usbdev2/tests/usbus_hid'
/home/koen/dev/RIOT-usbdev2/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-10-27 11:35:54,181 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2021-10-27 11:35:57,911 # USB_HID rx_cb: Test argument 
2021-10-27 11:35:57,913 # Msg received via USB HID: 
2021-10-27 11:35:57,913 # Test
2021-10-27 11:35:57,914 # 

ep->ep = usbdev_ep;
ep->ep->len = len;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is leftover from debugging and should be removed here. It should be set by the usbdev driver.

@bergzand
Copy link
Member Author

rebased

@bergzand
Copy link
Member Author

I've added assertions to check the supplied buffer alignment. Should make things a bit less error prone and hopefully satisfy @maribu's align-crusade :)

@bergzand bergzand removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 16, 2021
This API change refactors the usbdev API to supply buffers via the
usbdev_ep_xmit function. This changes from the usbdev_ep_ready call to allow
separate buffers per call. An usbdev_ep_buf_t pseudotype is available and must
be used when defining buffers used for endpoints to adhere to the DMA alignment
restrictions often required with usb peripherals.

Main advantage is that the usbdev peripherals no longer have to allocate
oversized buffers for the endpoint data, potentially saving multiple KiB
of unused buffer space. These allocations are now the responsibility of
the individual USB interfaces in the firmware
This API change refactors the usbdev API to supply buffers via the
usbdev_ep_xmit function. This changes from the usbdev_ep_ready call to allow
separate buffers per call. An usbdev_ep_buf_t pseudotype is available and must
be used when defining buffers used for endpoints to adhere to the DMA alignment
restrictions often required with usb peripherals.

Main advantage is that the usbdev peripherals no longer have to allocate
oversized buffers for the endpoint data, potentially saving multiple KiB
of unused buffer space. These allocations are now the responsibility of
the individual USB interfaces in the firmware
@bergzand
Copy link
Member Author

And another rebase because of #17154

@bergzand
Copy link
Member Author

nrf52840dk with tests/cdc_ecm
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:16:46,359 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
ifconfig 4 add 2001:db8::2/64
2021-11-16 14:16:55,969 # ifconfig 4 add 2001:db8::2/64
2021-11-16 14:16:55,973 # success: added 2001:db8::2/64 to interface 4
> ping6 2001:db8::61b2:7a78:e34:2f87
2021-11-16 14:17:03,529 # ping6 2001:db8::61b2:7a78:e34:2f87
2021-11-16 14:17:03,540 # 12 bytes from 2001:db8::61b2:7a78:e34:2f87: icmp_seq=0 ttl=64 time=3.619 ms
2021-11-16 14:17:04,524 # 12 bytes from 2001:db8::61b2:7a78:e34:2f87: icmp_seq=1 ttl=64 time=1.564 ms
2021-11-16 14:17:05,511 # 12 bytes from 2001:db8::61b2:7a78:e34:2f87: icmp_seq=2 ttl=64 time=1.791 ms
2021-11-16 14:17:05,512 # 
2021-11-16 14:17:05,515 # --- 2001:db8::61b2:7a78:e34:2f87 PING statistics ---
2021-11-16 14:17:05,520 # 3 packets transmitted, 3 packets received, 0% packet loss
2021-11-16 14:17:05,524 # round-trip min/avg/max = 1.564/2.324/3.619 ms
nrf52840dk with tests/cdc_acm_stdio
koen@zometeen ~/dev/RIOT-dev $ make -C tests/usbus_cdc_acm_stdio/ BOARD=nrf52840dk list-ttys
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
/sys/bus/usb/devices/1-3: SEGGER J-Link, serial: '000683806234', tty(s): ttyACM0
/sys/bus/usb/devices/1-4: RIOT-os.org USB device, serial: 'AD1B17D1BE432280', tty(s): ttyACM1
make: Leaving directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
koen@zometeen ~/dev/RIOT-dev $  make -C tests/usbus_cdc_acm_stdio/ BOARD=nrf52840dk term PORT=/dev/ttyACM1
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM1" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:19:04,723 # Connect to serial port /dev/ttyACM1
Welcome to pyterm!
Type '/exit' to exit.
ps
2021-11-16 14:19:11,501 # ps
2021-11-16 14:19:11,502 #       pid | name                 | state    Q | pri | stack  ( used) ( free) | base addr  | current     
2021-11-16 14:19:11,503 #         - | isr_stack            | -        - |   - |    512 (  200) (  312) | 0x20000000 | 0x200001c8
2021-11-16 14:19:11,504 #         1 | main                 | running  Q |   7 |   1536 (  880) (  656) | 0x200007ec | 0x20000a7c 
2021-11-16 14:19:11,505 #         2 | usbus                | bl anyfl _ |   1 |   1024 (  544) (  480) | 0x20000280 | 0x20000504 
2021-11-16 14:19:11,506 #           | SUM                  |            |     |   3072 ( 1624) ( 1448)
nrf52840dk with tests/usbus_hid
koen@zometeen ~/dev/RIOT-dev $  make -C tests/usbus_hid/ BOARD=nrf52840dk term
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_hid'
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:20:23,436 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2021-11-16 14:20:59,258 # USB_HID rx_cb: Test argument 
2021-11-16 14:20:59,260 # Msg received via USB HID: 
2021-11-16 14:20:59,262 # Hello World
2021-11-16 14:20:59,262 # 
nucleo-f746zg with tests/usbus_cdc_ecm
koen@zometeen ~/dev/RIOT-dev $  make -C tests/usbus_cdc_ecm/ BOARD=nucleo-f746zg term
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_ecm'
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:36:28,512 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
ifconfig 4 add 2001:db8::2/64
2021-11-16 14:36:36,841 # ifconfig 4 add 2001:db8::2/64
2021-11-16 14:36:36,845 # success: added 2001:db8::2/64 to interface 4
> ping6 2001:db8::bac9:e4a1:f195:418a
2021-11-16 14:36:42,913 # ping6 2001:db8::bac9:e4a1:f195:418a
2021-11-16 14:36:42,923 # 12 bytes from 2001:db8::bac9:e4a1:f195:418a: icmp_seq=0 ttl=64 time=3.066 ms
2021-11-16 14:36:43,921 # 12 bytes from 2001:db8::bac9:e4a1:f195:418a: icmp_seq=1 ttl=64 time=1.193 ms
2021-11-16 14:36:44,921 # 12 bytes from 2001:db8::bac9:e4a1:f195:418a: icmp_seq=2 ttl=64 time=1.160 ms
2021-11-16 14:36:44,922 # 
2021-11-16 14:36:44,926 # --- 2001:db8::bac9:e4a1:f195:418a PING statistics ---
2021-11-16 14:36:44,931 # 3 packets transmitted, 3 packets received, 0% packet loss
2021-11-16 14:36:44,935 # round-trip min/avg/max = 1.160/1.806/3.066 ms
nucleo-f746zg with tests/usbus_cdc_acm_stdio
koen@zometeen ~/dev/RIOT-dev $  make -C tests/usbus_cdc_acm_stdio/ BOARD=nucleo-f746zg list-ttys
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
/sys/bus/usb/devices/1-3: RIOT-os.org USB device, serial: '5B8017AD60B13119', tty(s): ttyACM1
/sys/bus/usb/devices/1-4: STMicroelectronics STM32 STLink, serial: '066BFF343334434257135447', tty(s): ttyACM0
make: Leaving directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
koen@zometeen ~/dev/RIOT-dev $  make -C tests/usbus_cdc_acm_stdio/ BOARD=nucleo-f746zg term PORT=/dev/ttyACM1
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM1" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:38:33,866 # Connect to serial port /dev/ttyACM1
ps
Welcome to pyterm!
Type '/exit' to exit.
2021-11-16 14:38:40,185 # main(): This is RIOT! (Version: 2022.01-devel-555-gb19a2-pr/usbdev/xmit)
ps
2021-11-16 14:38:40,185 # RIOT USB CDC ACM shell test
> ps
2021-11-16 14:38:40,187 # ps
2021-11-16 14:38:40,188 #       pid | name                 | state    Q | pri | stack  ( used) ( free) | base addr  | current     
2021-11-16 14:38:40,188 #         - | isr_stack            | -        - |   - |    512 (  168) (  344) | 0x20000000 | 0x200001c8
2021-11-16 14:38:40,189 #         1 | main                 | running  Q |   7 |   1536 (  876) (  660) | 0x200007f0 | 0x20000a84 
2021-11-16 14:38:40,190 #         2 | usbus                | bl anyfl _ |   1 |   1024 (  548) (  476) | 0x20000284 | 0x20000504 
2021-11-16 14:38:40,190 #           | SUM                  |            |     |   3072 ( 1592) ( 1480)
samr21-xpro with tests/usbus_cdc_ecm
koen@zometeen ~/dev/RIOT-dev $ make -C tests/usbus_cdc_ecm/ BOARD=samr21-xpro term
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_ecm'
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:51:59,869 # Connect to serial port /dev/ttyACM0
^[[AWelcome to pyterm!
Type '/exit' to exit.
ifconfig 4 add 2001:db8::2/64
2021-11-16 14:52:02,605 # ifconfig 4 add 2001:db8::2/64
2021-11-16 14:52:02,609 # success: added 2001:db8::2/64 to interface 4
ping6 2001:db8::2084:5e15:db07:1e49
2021-11-16 14:52:10,749 # ping6 2001:db8::2084:5e15:db07:1e49
2021-11-16 14:52:10,761 # 12 bytes from 2001:db8::2084:5e15:db07:1e49: icmp_seq=0 ttl=64 time=4.664 ms
2021-11-16 14:52:11,758 # 12 bytes from 2001:db8::2084:5e15:db07:1e49: icmp_seq=1 ttl=64 time=1.637 ms
2021-11-16 14:52:12,759 # 12 bytes from 2001:db8::2084:5e15:db07:1e49: icmp_seq=2 ttl=64 time=1.555 ms
2021-11-16 14:52:12,759 # 
2021-11-16 14:52:12,764 # --- 2001:db8::2084:5e15:db07:1e49 PING statistics ---
2021-11-16 14:52:12,769 # 3 packets transmitted, 3 packets received, 0% packet loss
2021-11-16 14:52:12,773 # round-trip min/avg/max = 1.555/2.618/4.664 ms
samr21-xpro with tests/usbus_cdc_acm_stdio
koen@zometeen ~/dev/RIOT-dev $  make -C tests/usbus_cdc_acm_stdio/ BOARD=samr21-xpro list-ttys
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
/sys/bus/usb/devices/1-3: Atmel Corp. EDBG CMSIS-DAP, serial: 'ATML2127031800008360', tty(s): ttyACM0
/sys/bus/usb/devices/1-4: RIOT-os.org USB device, serial: 'BB3072FFBF200CDA', tty(s): ttyACM1
make: Leaving directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
koen@zometeen ~/dev/RIOT-dev $ make -C tests/usbus_cdc_acm_stdio/ BOARD=samr21-xpro term PORT=/dev/ttyACM1
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_cdc_acm_stdio'
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM1" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:41:56,379 # Connect to serial port /dev/ttyACM1
ps
Welcome to pyterm!
Type '/exit' to exit.
ps
2021-11-16 14:42:02,425 # main(): This is RIOT! (Version: 2022.01-devel-555-gb19a2-pr/usbdev/xmit)
2021-11-16 14:42:02,426 # RIOT USB CDC ACM shell test
> 2021-11-16 14:42:02,427 # ps
2021-11-16 14:42:02,427 #       pid | name                 | state    Q | pri | stack  ( used) ( free) | base addr  | current     
2021-11-16 14:42:02,428 #         - | isr_stack            | -        - |   - |    512 (  188) (  324) | 0x20000000 | 0x200001c0
2021-11-16 14:42:02,429 #         1 | main                 | running  Q |   7 |   1536 (  788) (  748) | 0x200007f0 | 0x20000adc 
2021-11-16 14:42:02,430 #         2 | usbus                | bl anyfl _ |   1 |   1024 (  588) (  436) | 0x20000284 | 0x20000504 
2021-11-16 14:42:02,430 #           | SUM                  |            |     |   3072 ( 1564) ( 1508)
samr21-xpro with tests/usbus_hid
koen@zometeen ~/dev/RIOT-dev $ make -C tests/usbus_hid/ BOARD=samr21-xpro term
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus_hid'
/home/koen/dev/RIOT-dev/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-11-16 14:52:50,941 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2021-11-16 14:53:02,961 # USB_HID rx_cb: Test argument 
2021-11-16 14:53:02,964 # Msg received via USB HID: 
2021-11-16 14:53:02,965 # Hello world
2021-11-16 14:53:02,965 # 

Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remark.
Also did you test usbdev_mock ?

@@ -156,20 +145,10 @@ static void _copy_setup(usbdev_ep_t *ep)
if (setup->request == USB_SETUP_REQ_SET_ADDRESS) {
DEBUG("nrfusb: set address call\n");
usbdev->sstate = NRFUSB_SETUP_READY;
#include "architecture.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here ?

No idea, removed.

@bergzand
Copy link
Member Author

Also did you test usbdev_mock ?

Here you go:

koen@zometeen ~/dev/RIOT-dev $ make -C tests/usbus term
make: Entering directory '/home/koen/dev/RIOT-dev/tests/usbus'
/home/koen/dev/RIOT-dev/tests/usbus/bin/native/tests_usbus.elf /dev/ttyACM0 
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

Help: Press s to start test, r to print it is ready
s
START
main(): This is RIOT! (Version: 2022.01-devel-556-ge6d56c-pr/usbdev/xmit)
.
OK (1 tests)

@dylad
Copy link
Member

dylad commented Nov 16, 2021

I am happy with the changes,
@bergzand provided all the tests outputs, I also run a few tests on my side.
Please squash !

@dylad
Copy link
Member

dylad commented Nov 16, 2021

Or wait for #17203 to be merged to squash+rebase ?

@bergzand
Copy link
Member Author

Squashed!

Or wait for #17203 to be merged to squash+rebase ?

I don't expect that they conflict.

@dylad dylad added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 16, 2021
@dylad
Copy link
Member

dylad commented Nov 17, 2021

Then here we go !

@dylad dylad merged commit aa8608e into RIOT-OS:master Nov 17, 2021
@bergzand bergzand deleted the pr/usbdev/xmit branch November 17, 2021 08:21
@fjmolinas fjmolinas added this to the Release 2022.01 milestone Nov 18, 2021
bors bot added a commit that referenced this pull request Feb 27, 2023
17091: USBUS: Add URB support r=benpicco a=bergzand

### Contribution description

This commit adds support for URBs (USB Request/Response Blocks). These
allow for submitting multi-transfer sized buffers with USBUS handling
the individual usbdev xmits. Multiple URBs can be queued at once for a
single endpoint and USBUS will handle them in the order of submission.

OUT endpoint URBs must always consist of a whole number of full-sized
transfers (N x MaxEndpointSize). They will automatically finish after
the endpoint received a transfer less than the endpoint size.

IN endpoints can be arbitrary-sized and do not have to consist of a
whole number of full-sized transmissions. They support a flag to
indicate that the last transfer in the sequence must be less than a full
sized transfer (USBUS_URB_FLAG_AUTO_ZLP) and this adds a zero length
transfer at the end of the transmissions if the last transfer was equal
to the maximum transfer size.

URBs can be cancelled, but if the URB is already being processed it will
be cancelled after the current transmission within the URB is finished.
If it is still in the queue it will immediately be removed from the
queue.

### Testing procedure

- `tests/usbus_cdc_ecm` should still work. Testing one of the usbdev-supported platform should be sufficient here.

### Issues/PRs references

Needs #17064 


18148: sys/flash_utils: helpers to store data in flash r=benpicco a=maribu

### Contribution description

This helpers that allow storing, accessing, and working with data in flash that works for both classical Harvard architectures (which do not map flash also into the address space) as well as modern Harvard architectures and von-Neumann architectures.

With this, `examples/default` again runs on the Arduino Uno / Nano. Since this board is still the "entry kit" for many people to embedded hardware, it would be nice to support it with our default example.

### Testing procedure

`examples/default` should run and work on ATmega boards (especially ATmega328P and ATmega32U4 based boards) as well on all other boards now.

### Issues/PRs references

None

Co-authored-by: Koen Zandberg <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: sys Area: System Area: tests Area: tests and testing framework Area: USB Area: Universal Serial Bus CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants