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

drivers: add support for MTDs emulated in RAM #19443

Merged
merged 10 commits into from
Apr 12, 2023
Prev Previous commit
Next Next commit
tests/usbus_msc: use emulated MTD as test mockup
  • Loading branch information
gschorcht committed Apr 12, 2023
commit 4bb283cb4b3779784485487595cd84e9f093fb98
7 changes: 6 additions & 1 deletion tests/usbus_msc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions tests/usbus_msc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions tests/usbus_msc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down