USB MSC storage init ERROR using LittleFS on External Flash

Hello, I am trying to save some sensor data based on my current state of the device. I want to log IMU data and timestamp into my external flash (MX25R64) with littlefs file system. I have successfully mounted the file system on my thingy53 and I can see the successful log as follows:

[00:00:00.051,208] <inf> littlefs: LittleFS version 2.8, disk version 2.1
[00:00:00.052,642] <inf> littlefs: FS at mx25r6435f@0:0x120000 is 1760 0x1000-byte blocks with 512 cycle
[00:00:00.052,673] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
[00:00:00.089,935] <inf> THINGY: LittleFS mounted on /lfs1
[00:00:00.113,616] <inf> THINGY: /lfs1: bsize = 16 ; frsize = 4096 ; blocks = 1760 ; bfree = 1738
But before these logs, I can see an error message:
[00:00:00.045,867] <err> usb_msc: Storage init ERROR !!!! - Aborting USB init
right after zephyr starts. I have been trying to debug and search this issue online but find very limited solution.

In my prj.conf, I have the following configurations: 

# Enable GPIO
CONFIG_GPIO=y

# Enable I2C
CONFIG_I2C=y
# Enable SPI
CONFIG_SPI=y

# Disable TFM for logging 
CONFIG_TFM_SECURE_UART=n
CONFIG_TFM_LOG_LEVEL_SILENCE=y

# Enable log and use it via Jlink RTT rather than CDC ACM 
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y    
CONFIG_LOG_BACKEND_UART=n
CONFIG_RTT_CONSOLE=y    
CONFIG_STDOUT_CONSOLE=y  # For using printk
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096  
CONFIG_LOG_BUFFER_SIZE=8192

# Enable Bluetooth LE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="BORUS"
CONFIG_BT_BROADCASTER=y
CONFIG_BT_OBSERVER=y

# Increase stack size for the main thread
CONFIG_MAIN_STACK_SIZE=10240

# Enale floating point unit for float point calculation 
CONFIG_FPU=y
CONFIG_CBPRINTF_FP_SUPPORT=y

# Enable debugging 
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_DEBUG_OPTIMIZATIONS=y

# Enable multithread
CONFIG_MULTITHREADING=y

# Enable battery voltage monitoring
CONFIG_SENSOR=y
CONFIG_PWM=y
CONFIG_ADC=y
CONFIG_VOLTAGE_DIVIDER=y
CONFIG_NRFX_SAADC=y

# Configure USB device
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="BORUS"
CONFIG_USB_DEVICE_PID=0x0001
CONFIG_USB_DEVICE_VID=0x0001
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

# Configure USB device to appear as DFU class
# Configure DFU autoupdate and reset
CONFIG_USB_DFU_CLASS=y
CONFIG_USB_DFU_ENABLE_UPLOAD=y
CONFIG_USB_DFU_PERMANENT_DOWNLOAD=y
CONFIG_USB_DFU_REBOOT=y
CONFIG_IMG_MANAGER=y
CONFIG_STREAM_FLASH=y

# Configure file system 
CONFIG_FLASH_MAP=y
CONFIG_FLASH=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# Configure mass storage
CONFIG_USB_MASS_STORAGE=y
CONFIG_DISK_ACCESS=y
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y


And in my main.c file, I simply added this line 
USBD_DEFINE_MSC_LUN(NAND, "Zephyr", "BORUS", "0.00"); 
By commenting out this line and the mass storage related configurations, this error disappered. Can someone point out where the issue could be. I am developing with Thingy53 using nrf connect and toolchain v2.7.0. 

Parents
  • This is solved by adding the disk drivers configurations in prj.conf file first:

    CONFIG_DISK_LOG_LEVEL_DBG=y
    CONFIG_DISK_DRIVERS=y
    CONFIG_DISK_DRIVER_FLASH=y
    CONFIG_MASS_STORAGE_DISK_NAME="NAND"
    Then because partition manager is used, instead of defining disk partition in a DTS overlay file, one needs to define such a partition in a pm_static.yml file under the project directory lie this:
    littlefs_storage:
      region: external_flash
      address: 0x120000
      size: 0x6e0000
      label: "lfs_storage"
      affiliation:
      - disk
      extra_params:
        disk_cache_size: 0x1000
        disk_name: NAND
        disk_read_only: 0x0
        disk_sector_size: 0x200
    , which is basically the hex representation of the sample's node values. The error will disappear after build. Make sure the disk_name entry property is the same as the configuration's setting. 

Reply
  • This is solved by adding the disk drivers configurations in prj.conf file first:

    CONFIG_DISK_LOG_LEVEL_DBG=y
    CONFIG_DISK_DRIVERS=y
    CONFIG_DISK_DRIVER_FLASH=y
    CONFIG_MASS_STORAGE_DISK_NAME="NAND"
    Then because partition manager is used, instead of defining disk partition in a DTS overlay file, one needs to define such a partition in a pm_static.yml file under the project directory lie this:
    littlefs_storage:
      region: external_flash
      address: 0x120000
      size: 0x6e0000
      label: "lfs_storage"
      affiliation:
      - disk
      extra_params:
        disk_cache_size: 0x1000
        disk_name: NAND
        disk_read_only: 0x0
        disk_sector_size: 0x200
    , which is basically the hex representation of the sample's node values. The error will disappear after build. Make sure the disk_name entry property is the same as the configuration's setting. 

Children
No Data
Related