1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/boards/common
bors[bot] e51d8285f3
Merge #19037
19037: sys/usb, pkg/tinyusb: move USB board reset from highlevel STDIO to CDC ACM r=dylad a=gschorcht

### Contribution description

The USB board reset function `usb_board_reset_coding_cb` can be used on any CDC-ACM interface, even if the CDC ACM interface is not used as high-level STDIO. Therefore, this PR provides the following changes:

- The call of the board reset function `usb_board_reset_coding_cb` from USBUS stack has been moved from the STDIO CDC ACM implementation to the CDC ACM implementation and is thus a feature of any USBUS CDC ACM interface which does not necessarily have to be used as highlevel STDIO.

- The call of the board reset function `usb_board_reset_coding_cb` from tinyUSB stack been moved from module `tinyusb_stdio_cdc_acm` to module `tinyusb_contrib` and is compiled in if the `tinyusb_class_cdc` module is used together the `tinyusb_device` module. Thus, it is now a feature of the tinyUSB CDC ACM interface, which does not necessarily have to be used as highlevel STDIO.
 
- The `usb_board_reset` module defines the `usb_board_reset_in_bootloader` function as a weak symbol to be used when reset in bootloader if no real implementation of this function is compiled in and the `riotboot_reset` module is not used. It only prints an error message that the reset in bootloader is not supported. This is necessary if the module `usb_board_reset` is used to be able to restart the board with an application via a USB CDC ACM interface, but the board's bootloader does not support the reset in bootloader feature.

- A test application has been added that either uses the highlevel STDIO `stdio_acm_cdc` or creates a CDC-ACM interface to enable board resets via USB. If the `usbus_dfu` module is used, it also initializes the DFU interface to be able to work together with the `riotboot_dfu` bootloader.

### Testing procedure

1. Use a board with a bootloader that supports the reset in bootloader via USB, but don't use the highlevel STDIO to check that it works with `usbus_cdc_acm`, for example:
   ```python
   USEMODULE=stdio_uart BOARD=arduino-mkr1000 make -C tests/usb_board_reset flash
   ```
   After reset in application with command
   ```python
   stty -F /dev/ttyACM0 raw ispeed 600 ospeed 600 cs8 -cstopb ignpar eol 255 eof 255
   ```
   command `dmesg` should give an output like the following with RIOT's test VID/PID:
   ```python
   dmesg
   [1745182.057403] usb 1-4.1.2: new full-speed USB device number 69 using xhci_hcd
   [1745182.160386] usb 1-4.1.2: New USB device found, idVendor=1209, idProduct=7d01, bcdDevice= 1.00
   [1745182.160390] usb 1-4.1.2: New USB device strings: Mfr=3, Product=2, SerialNumber=4
   [1745182.160392] usb 1-4.1.2: Product: arduino-mkr1000
   [1745182.160393] usb 1-4.1.2: Manufacturer: RIOT-os.org
   [1745182.160395] usb 1-4.1.2: SerialNumber: 6B6C2CA5229020D8
   [1745182.170982] cdc_acm 1-4.1.2:1.0: ttyACM0: USB ACM device
   ```
   After reset in bootloader with command
   ```python
   stty -F /dev/ttyACM0 raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255
   ```
   command `dmesg` should give an output like the following with vendor VID/PID:
   ```python
   [1746220.443792] usb 1-4.1.2: new full-speed USB device number 70 using xhci_hcd
   [1746220.544705] usb 1-4.1.2: New USB device found, idVendor=2341, idProduct=024e, bcdDevice= 2.00
   [1746220.544708] usb 1-4.1.2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
   [1746220.553471] cdc_acm 1-4.1.2:1.0: ttyACM0: USB ACM device
   ```
   
2. Test the same as in 1., but this time use the highlevel STDIO to check that there is no regression and it still works with `stdio_cdc_acm`, for example:
   ```python
   BOARD=arduino-mkr1000 make -C tests/usb_board_reset flash
   ```
   
3. Use a board that supports `riotboot_dfu` but doesn't use the highlevel STDIO and flash the `riotboot_dfu` bootloader, for example:
   ```python
   BOARD=stm32f429i-disc1 make -C bootloaders/riotboot_dfu flash term
   ```
   Once the bootloader is flashed, command `dfu-util --list` should give something like the following:
   ```python
   Found DFU: [1209:7d02] ver=0100, devnum=14, cfg=1, intf=0, path="1-2", alt=1, name="RIOT-OS Slot 1", serial="6591620BCB270283"
   Found DFU: [1209:7d02] ver=0100, devnum=14, cfg=1, intf=0, path="1-2", alt=0, name="RIOT-OS Slot 0", serial="6591620BCB270283"
   ```
   If the output gives only
   ```python
   Found Runtime: [1209:7d00] ver=0100, devnum=123, cfg=1, intf=0, path="1-2", alt=0, name="RIOT-OS bootloader", serial="6591620BCB270283"
   ```
   an application is already running in DFU Runtime mode. Use `dfu-util -e` to restart it in bootloader DFU mode.
   Then flash the test application, for example:
   ```python
   FEATURES_REQUIRED=riotboot USEMODULE='usbus_dfu riotboot_reset' \
   BOARD=stm32f429i-disc1 make -C tests/usbus_board_reset PROGRAMMER=dfu-util riotboot/flash-slot0
   ```
   Once the test application is flashed, command `dfu-util --list` should give:
   ```python
   Found Runtime: [1209:7d00] ver=0100, devnum=123, cfg=1, intf=0, path="1-2", alt=0, name="RIOT-OS bootloader", serial="6591620BCB270283"
   ```
   Now, use command
   ```python
   stty -F /dev/ttyACM1 raw ispeed 600 ospeed 600 cs8 -cstopb ignpar eol 255 eof 255
   ``` 
   to restart the board in application. Command `dfu-util --list` should give again the following:
   ```python
   Found Runtime: [1209:7d00] ver=0100, devnum=123, cfg=1, intf=0, path="1-2", alt=0, name="RIOT-OS bootloader", serial="6591620BCB270283"
   ```
   That is, the application is running in DFU Runtime mode. Then use command
   ```python
   stty -F /dev/ttyACM1 raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255
   ```
   to restart the board in bootloader DFU mode. Command  `dfu-util --list` should now give the following:
   ```python
   Found DFU: [1209:7d02] ver=0100, devnum=50, cfg=1, intf=0, path="1-2", alt=1, name="RIOT-OS Slot 1", serial="7D156425A950A8EB"
   Found DFU: [1209:7d02] ver=0100, devnum=50, cfg=1, intf=0, path="1-2", alt=0, name="RIOT-OS Slot 0", serial="7D156425A950A8EB"
   ```
   That is, the bootloader is in DFU mode and another application can be flash.
   
4. After a hard reset of the board under 3., try the commands `reboot` and `bootloader`. 

5. To check the same for tinyUSB, use the existing tinyUSB application with a CDC ACM interface and add module `usb_board_reset`, for example:
   ```python
   USEMODULE=usb_board_reset BOARD=stm32f429i-disc1 make -C tests/pkg_tinyusb_cdc_msc flash term
   ```
   After flashing, it should be possible to restart the application with command:
   ```python
   stty -F /dev/ttyACM1 raw ispeed 600 ospeed 600 cs8 -cstopb ignpar eol 255 eof 255
   ```
   When using command
   ```python
   stty -F /dev/ttyACM1 raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255
   ```
   the following error message should be shown in terminal
   ```python
   [cdc-acm] reset in bootloader is not supported
   ```
   
### Issues/PRs references


Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
2023-01-03 19:36:16 +00:00
..
arduino-atmega doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
arduino-due boards: drop board_init() from board.h 2022-02-25 15:08:58 +01:00
arduino-mkr boards: convert sam0 boards to new adc_conf_chan_t 2022-09-27 22:43:31 +02:00
arduino-zero boards/arduino-zero: move tinusb_device feature 2022-12-07 13:56:24 +01:00
atmega doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
atxmega boards: drop empty custom board_init & empty board.c 2022-02-22 18:27:37 +01:00
blxxxpill boards/{bluepill*,blackpill*}: rename and improve doc 2023-01-02 16:23:10 +01:00
cc26xx_cc13xx Merge pull request #18168 from maribu/boards/common/programmer 2022-06-08 10:15:17 +02:00
cc2538 boards/cc2538: set cc2538-bsl as supported programmer 2021-02-24 13:28:53 +01:00
e104-bt50xxa-tb boards: add some missing whitespaces for static tests 2022-09-14 15:11:14 +02:00
esp32 boards/common/esp32: remove SPIFFS defines with default values 2022-08-05 22:26:44 +02:00
esp32c3 boards/common: add common board definition for ESP32-C3 2022-08-05 22:26:22 +02:00
esp32s2 boards/common/esp32{s2,s3}: update USB OTG configuration 2022-10-06 06:26:22 +02:00
esp32s3 boards/common/esp32{s2,s3}: update USB OTG configuration 2022-10-06 06:26:22 +02:00
esp8266 boards: drop board_init() from board.h 2022-02-25 15:08:58 +01:00
frdm boards/frdm: set openocd as only supported programmer 2021-02-24 13:29:16 +01:00
init boards: drop empty custom board_init & empty board.c 2022-02-22 18:27:37 +01:00
iotlab boards: Remove PLL overrides in kconfig 2022-11-03 13:38:09 +01:00
kw41z drivers/kw41zrf: model Kconfig 2022-07-28 09:32:24 +02:00
makefiles sys/usb/usbus: enable USBUS stdio_cdc_acm only if tinyUSB is not used 2022-12-03 12:52:45 +01:00
microbit boards/common/microbit: fix doxygen grouping 2021-12-23 11:07:58 +01:00
msb-430 cpu/msp430: add Kconfig 2021-12-02 16:33:19 +01:00
msba2 boards: set supported programmers 2021-02-24 13:30:34 +01:00
nrf51 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
nrf52 boards/common/nrf52: fix timer config 2022-11-22 13:20:53 +01:00
nrf52xxxdk boards: drop empty custom board_init & empty board.c 2022-02-22 18:27:37 +01:00
nucleo boards/common/nucleo: provide TTY_BOARD_FILTER 2022-06-03 19:59:31 +02:00
nucleo32 boards/common/stm32: clean up LED definitions 2022-08-08 23:35:06 +02:00
nucleo64 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
nucleo144 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
particle-mesh treewide: fix typos found by recent codespell 2022-11-24 14:53:48 +01:00
qn908x boards/common/qn908x: perfom checksum on shadow copy 2022-03-07 10:28:13 +01:00
remote boards select cc2538 Kconfig feature 2022-07-28 09:32:25 +02:00
samdx1-arduino-bootloader boards/common/samdx1-arduino-bootloader: use any CDC ACM interface 2023-01-03 10:05:54 +01:00
saml1x boards: convert sam0 boards to new adc_conf_chan_t 2022-09-27 22:43:31 +02:00
silabs boards/common/silabs: add common USB OTG FS config 2022-12-07 16:34:34 +01:00
slwstk6000b cpu/efm32: provide periph_uart_modecfg feature for every board 2022-11-21 23:20:19 +01:00
sodaq boards: drop board_init() from board.h 2022-02-25 15:08:58 +01:00
stm32 boards/common/stm32: add common configuration for internal USB HS PHY 2022-10-16 11:35:42 +02:00
weact-f4x1cx boards/common/weact-f4x1cx: remove tinyUSB feature 2022-12-04 16:23:02 +01:00
doc.txt boards/stm32f103c8: add docu on flashing with DFU 2018-08-15 15:00:13 +02:00