Skip to content
Permalink
Browse files

usb: samples: mass: add configuration and fs for FLASH

Adds required Kconfig options for flash driver.
Adds FatFS filesystem for flash disk.
Fixes #14459.

Note: As USB MSC does not support multiple disks (see #14937),
only one (flash by default, modify CONFIG_MASS_STORAGE_DISK_NAME
to "RAM" for RAM disk) will appear to host.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
  • Loading branch information...
masz-nordic authored and carlescufi committed Mar 28, 2019
1 parent 851fa12 commit be1ec7822c150b8f8e68582ad284faff4ba8043d
@@ -3,10 +3,24 @@ CONFIG_GPIO=y
CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr MSC sample"
CONFIG_USB_MASS_STORAGE=y
CONFIG_LOG=y

CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
CONFIG_DISK_LOG_LEVEL_ERR=y

CONFIG_DISK_ACCESS_RAM=y
CONFIG_MASS_STORAGE_DISK_NAME="RAM"

CONFIG_MASS_STORAGE_DISK_NAME="NAND"
CONFIG_DISK_ACCESS_FLASH=y
CONFIG_DISK_FLASH_DEV_NAME="NRF_FLASH_DRV_NAME"
CONFIG_DISK_FLASH_START=0xf8000
CONFIG_DISK_FLASH_MAX_RW_SIZE=4096
CONFIG_DISK_FLASH_ERASE_ALIGNMENT=0x1000
CONFIG_DISK_ERASE_BLOCK_SIZE=0x1000
CONFIG_DISK_VOLUME_SIZE=0x10000
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
@@ -24,3 +24,13 @@ tests:
type: one_line
regex:
- "The device is put in USB mass storage mode."
test_mass_nrf52840_pca10056:
extra_configs:
- CONFIG_LOG_DEFAULT_LEVEL=3
platform_whitelist: nrf52840_pca10056
tags: msd usb
harness: console
harness_config:
type: one_line
regex:
- "The device is put in USB mass storage mode."
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -10,11 +11,33 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(main);

#if CONFIG_DISK_ACCESS_FLASH && CONFIG_FAT_FILESYSTEM_ELM
#include <fs.h>
#include <ff.h>

static FATFS fat_fs;
#define FATFS_MNTP "/NAND:"

static struct fs_mount_t fatfs_mnt = {
.type = FS_FATFS,
.mnt_point = FATFS_MNTP,
.fs_data = &fat_fs,
};
#endif

void main(void)
{
/* Nothing to be done other than the selecting appropriate build
* config options. Everything is driven from the USB host side.
*/
LOG_INF("The device is put in USB mass storage mode.\n");

#if CONFIG_DISK_ACCESS_FLASH && CONFIG_FAT_FILESYSTEM_ELM
int res = fs_mount(&fatfs_mnt);

if (res < 0) {
LOG_ERR("Mount failed.");
}
#endif
}

0 comments on commit be1ec78

Please sign in to comment.
You can’t perform that action at this time.