1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/usbus_board_reset: test application

The test application either uses the USBUS highlevel STDIO module `stdio_acm_cdc` or it creates a CDC ACM interface to enable board reset via USBUS CDC ACM. If the `usbus_dfu` module is used together with the `riotboot_dfu` bootloader, it also initializes the USBUS DFU Runtime interface.
This commit is contained in:
Gunar Schorcht 2022-12-11 13:41:03 +01:00
parent c0d027156a
commit 709667a58b
4 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,17 @@
include ../Makefile.tests_common
FEATURES_REQUIRED += periph_usbdev
USEMODULE += app_metadata
USEMODULE += ps
USEMODULE += shell
USEMODULE += shell_cmds_default
USEMODULE += usb_board_reset
USEMODULE += usbus_cdc_acm
DISABLE_MODULE += auto_init_usbus
USB_VID ?= $(USB_VID_TESTING)
USB_PID ?= $(USB_PID_TESTING)
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,48 @@
# Overview
This test represents a simple shell application that can be used to test
the USB board reset function (module `usb_board_reset`) via the USB CDC ACM
interface.
It can be used to reset the board to restart either the application or the
bootloader if supported using the `usb_board_reset` module.
The test application requires that the board provides USB peripherals
(feature `periph_usbdev`).
# Usage
Once the test application is flashed, the board should be detected. The output
of command
```
dmesg
```
should look like the following and should show the USB DC ACM interface:
```
[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
```
*Note*: The interface `ttyACM0` could be different depending on which other
USB CDC ACM devices are already in use.
For boards that use the USB CDC ACM interface as STDIO (module `stdio_cdc_acm`),
this interface is used for the test application. Otherwise the test application
creates a simple USB CDC ACM interface without any functionality except the
USB board reset function.
When the USB CDC ACM interface is initialized, the `stty` command can be used
to reset the board, for example:
```
stty -F /dev/ttyACM0 raw ispeed 600 ospeed 600 cs8 -cstopb ignpar eol 255 eof 255
```
should reset the board and restart the application, while
```
stty -F /dev/ttyACM0 raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255
```
should reset the board and start the bootloader. The latter requires that the
bootloader supports this.

View File

@ -0,0 +1,9 @@
CONFIG_MODULE_APP_METADATA=y
CONFIG_MODULE_PS=y
CONFIG_MODULE_SHELL=y
CONFIG_MODULE_SHELL_CMDS_DEFAULT=y
CONFIG_MODULE_USB_BOARD_RESET=y
CONFIG_MODULE_USBUS=y
CONFIG_MODULE_USBUS_CDC_ACM=y
CONFIG_MODULE_AUTO_INIT_USBUS=n

View File

@ -0,0 +1,65 @@
/*
* Copyright (C) 2022 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @file
* @brief Simple shell application to test the USB board reset function
*
* @author Gunar Schorcht <gunar@schorcht.net>
*
*/
#include <stdio.h>
#include <string.h>
#include "shell.h"
#include "usb/usbus.h"
#include "usb/usbus/cdc/acm.h"
#ifdef MODULE_USBUS_DFU
#include "usb/usbus/dfu.h"
static usbus_dfu_device_t _dfu;
#endif
static char line_buf[SHELL_DEFAULT_BUFSIZE];
static usbus_t _usbus;
static char _stack[USBUS_STACKSIZE];
static void _init(void)
{
usbus_init(&_usbus, usbdev_get_ctx(0));
#ifdef MODULE_STDIO_CDC_ACM
/* if stdio_cdc_acm is used, initialize it */
void usb_cdc_acm_stdio_init(usbus_t *_usbus);
usb_cdc_acm_stdio_init(&_usbus);
#else
/* otherwise create a device CDC ACM and initialize it */
static usbus_cdcacm_device_t _cdcacm;
/* buffer is required in usbus_cdc_acm_init, use only a single character */
static uint8_t _cdcacm_buf;
usbus_cdc_acm_init(&_usbus, &_cdcacm, NULL, NULL, &_cdcacm_buf, 1);
#endif
#ifdef MODULE_USBUS_DFU
usbus_dfu_init(&_usbus, &_dfu, USB_DFU_PROTOCOL_RUNTIME_MODE);
#endif
usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &_usbus);
}
int main(void)
{
_init();
shell_run(NULL, line_buf, ARRAY_SIZE(line_buf));
return 0;
}