From 5ea2eaa76500a98445e71f4211b08f27fa9fa3da Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 22 Jun 2020 06:18:03 -0500 Subject: [PATCH] samples: usb: mass: do application configuration before usb starts USB access to the flash device is not synchronized with the application, so if the application needs to create a new file system USB may read configuration state that is incorrect. Wait until the the application is done with the flash before starting USB. Signed-off-by: Peter Bigot --- samples/subsys/usb/mass/src/main.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/samples/subsys/usb/mass/src/main.c b/samples/subsys/usb/mass/src/main.c index eec6920fcad..305ed55b4d2 100644 --- a/samples/subsys/usb/mass/src/main.c +++ b/samples/subsys/usb/mass/src/main.c @@ -45,18 +45,8 @@ static struct fs_mount_t fs_mnt = { #endif /* file system */ #endif /* CONFIG_DISK_ACCESS_FLASH */ -void main(void) +static void setup_disk(void) { - int ret; - - ret = usb_enable(NULL); - if (ret != 0) { - LOG_ERR("Failed to enable USB"); - return; - } - - LOG_INF("The device is put in USB mass storage mode.\n"); - #if CONFIG_DISK_ACCESS_FLASH struct fs_mount_t *mp = &fs_mnt; unsigned int id = (uintptr_t)mp->storage_dev; @@ -125,3 +115,18 @@ out: flash_area_close(pfa); #endif } + +void main(void) +{ + int ret; + + setup_disk(); + + ret = usb_enable(NULL); + if (ret != 0) { + LOG_ERR("Failed to enable USB"); + return; + } + + LOG_INF("The device is put in USB mass storage mode.\n"); +}