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

tests/usbus_msc: use emulated MTD as test mockup

This commit is contained in:
Gunar Schorcht 2023-04-04 23:49:27 +02:00
parent 631df7c69c
commit 4bb283cb4b
3 changed files with 45 additions and 1 deletions

View File

@ -5,7 +5,7 @@ include ../Makefile.tests_common
# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..
# Comment this out to disable code in RIOT that does safety checking
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1
@ -19,6 +19,11 @@ USEMODULE += shell
USEMODULE += usbus_msc
USEMODULE += ztimer_msec
# If your board does not provide a MTD for testing, use the following line
# to emulate an MTD with 64 sectors with 4 pages of 128 bytes each in RAM. You
# can override these parameters by SECTOR_COUNT, PAGES_PER_SECTOR and PAGE_SIZE.
# USEMODULE += mtd_emulated
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

View File

@ -39,6 +39,19 @@ by attaching it to the host with the command:
At this point, the USBUS stack will export the selected MTD devices.
Devices should appears under /dev/sdX entries.
If the board does not provide a MTD device, a MTD device can be emulated in RAM
for testing using module `mtd_emulated`:
```
USEMODULE=mtd_emulated BOARD=... make ...
```
The emulated MTD device has by default 64 sectors with 4 pages of 128 bytes
each, the minimum size to be able to create a partition with FAT file system.
These default parameters can be overridden e.g. by `SECTOR_COUNT`,
`PAGES_PER_SECTOR` and `PAGE_SIZE`:
```
CFLAGS='-DSECTOR_COUNT=128' USEMODULE=mtd_emulated BOARD=... make ...
```
**Notes:** Depending on the MTD device and the USB speed, this operation can take some times.
USB operation can be stopped at any time using:

View File

@ -22,6 +22,32 @@
#include <stdio.h>
#include <string.h>
#include "board.h"
#if defined(MODULE_MTD_EMULATED)
#include "mtd_emulated.h"
/* The following parameters are only suitable for testing the basic functions
* of USB MSC. To create a partition with a FAT file system, at least 64 sectors
* have to be used. */
#ifndef SECTOR_COUNT
#define SECTOR_COUNT 64
#endif
#ifndef PAGES_PER_SECTOR
#define PAGES_PER_SECTOR 4
#endif
#ifndef PAGE_SIZE
#define PAGE_SIZE 128
#endif
MTD_EMULATED_DEV(0, SECTOR_COUNT, PAGES_PER_SECTOR, PAGE_SIZE);
#endif /* MODULE_MTD_EMULATED */
#include "mtd_default.h"
#include "shell.h"
#include "usb/usbus.h"