Using the Mass example on my custom board, but first getting it running on the nRF52840dk QSPI flash

Hi,

I've been using the nRF5 SDK (17.1.0) USB Mass storage code for a data logger I have made.  I am using a memory chip larger than 16KB and that code has bugs when you go over that size.  So I'm moving to the nRF Connect SDK on advice I read on different forums.  My first question is, has anyone used this code on a NOR Flash that is 2Gbit in size?  Will it work?

So, I've used the nRF5 SDK for many years and have recently moved over to the nRF Connect SDK.  It's a bit of a learning curve, but it's making sense.  I am missing something, though, when I try to build and run the Mass sample.  I am using the nRF52840dk which has a QSPI NOR flash attached.  Instead of using the adafruit board like in the example, I'd just like to get this running on the nRF52840dk (PCA10056).  

I have copied the Mass folder into a different location where I keep all my examples (and DevAcademy files), so it's out of tree of the SDK.

I opened the existing application.  I created a new build based on the nRF52840dk_nrf52840.  In the build file I optimized for debugging so I could see what was going on.

Then I typed the following into the nRF Terminal:

west build -b nrf52840dk/nrf52840 -- -DCONFIG_APP_MSC_STORAGE_FLASH_FATFS=y

I left out the location of the files since I was in that directory (and the first time I tried it there was an error that it couldn't find the files).  I also changed the board to the nRF52480dk.

Everything build and compiles correctly and I can flash it on to my board.  However, when I then plug it into a windows machine, It says I need to format the device in order to use it.  Ok, that seems normal, but when I try to format it, I says the size is unknown and the sector size is unknown and the format fails.  

Here is the output of the build after typing in the above command:

PS C:\Nordic\ExampleProjects\mass> west build -b nrf52840dk/nrf52840 -- -DCONFIG_APP_MSC_STORAGE_FLASH_FATFS=y
>>
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base (cached)).
-- Application: C:/Nordic/ExampleProjects/mass
-- CMake version: 3.21.0
-- Cache files will be written to: C:/ncs/v2.7.0/zephyr/.cache
-- Zephyr version: 3.6.99 (C:/ncs/v2.7.0/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nrf52840dk, qualifiers: nrf52840
-- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk)
-- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk)
-- Found BOARD.dts: C:/ncs/v2.7.0/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts
-- Found devicetree overlay: C:/Nordic/ExampleProjects/mass/boards/nrf52840dk_nrf52840.overlay
-- Generated zephyr.dts: C:/Nordic/ExampleProjects/mass/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/Nordic/ExampleProjects/mass/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/Nordic/ExampleProjects/mass/build/zephyr/dts.cmake
Parsing C:/Nordic/ExampleProjects/mass/Kconfig
Loaded configuration 'C:/Nordic/ExampleProjects/mass/build/zephyr/.config'
No change to configuration in 'C:/Nordic/ExampleProjects/mass/build/zephyr/.config'
No change to Kconfig header in 'C:/Nordic/ExampleProjects/mass/build/zephyr/include/generated/autoconf.h'
CMake Warning at C:/ncs/v2.7.0/zephyr/subsys/usb/device/CMakeLists.txt:22 (message):
CONFIG_USB_DEVICE_VID has default value 0x2FE3.

This value is only for testing and MUST be configured for USB products.


-- Configuring done
-- Generating done
-- Build files have been written to: C:/Nordic/ExampleProjects/mass/build
←[92m-- west build: building application
[9/9] Linking C executable zephyr\zephyr.elf
Memory region Used Size Region Size %age Used
FLASH: 89260 B 1 MB 8.51%
RAM: 24272 B 256 KB 9.26%
IDT_LIST: 0 GB 32 KB 0.00%
Generating files from C:/Nordic/ExampleProjects/mass/build/zephyr/zephyr.elf for board: nrf52840dk
PS C:\Nordic\ExampleProjects\mass>

Here is the RTT output

SEGGER J-Link V8.10c - Real time terminal output
SEGGER J-Link (unknown) V1.0, SN=1050248664
Process: JLink.exe
*** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
*** Using Zephyr OS v3.6.99-100befc70c74 ***
[00:00:00.427,124] <inf> flashdisk: Initialize device NAND
[00:00:00.427,154] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 131072
[00:00:00.427,368] <inf> main: Ian is Testing.

Area 0 at 0x0 on mx25r6435f@0 for 131072 bytes
[00:00:00.427,490] <inf> flashdisk: Initialize device NAND
[00:00:00.427,520] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 131072
Mount /NAND:: 0
/NAND:: bsize = 512 ; frsize = 1024 ; blocks = 8128 ; bfree = 6082
/NAND: opendir: 0
F 0 000041C6.TXT
F 0 0000167E.TXT
F 0 00002781.TXT
D 0 SYSTEM~1
End of files
[00:00:00.489,135] <inf> main: The device is put in USB mass storage mode.

It looks like the memory chip is found and everything is okay.  I am worried that it says NAND, but I looked up the adafeather board in the example and it also seems to NOR not NAND.

When I plug the board into my computer, I don't see any more messages on the COM or RTT.  

Thank you for you help,

ian

  • Hello ian,

    Could you please try the attached project or hex file and check if you get the same result? This project is based on the Bluetooth LED button sample from SDK v2.9.0, but with BLE DFU (not tested) and FATFS storage on the QSPI flash.

    Demo sample

    peripheral_lbs_master_storage_qspi.zip

    Hex file

    7444.merged.hex

    Hex file can be programmed with nrfjprog or nRF Util

    # Programming with nrfutil device
    $ nrfutil device program --firmware merged.hex --options chip_erase_mode=ERASE_ALL,reset=RESET_SYSTEM,verify=VERIFY_HASH
    # With nrfjprog
    $ nrfjprog --program merged.hex --chiperase --verify --reset

    Best regards,

    Vidar

  • Hi Vidar,

    Thank you for the help.

    I programmed this hex file on to my 52840DK and it behaves exactly the same as the Mass the project I used.  Windows sees it as a drive, but fails when trying to format it.

    Here's the output of the nrfjprog command in case you'd like to see it.

    C:\Nordic\ExampleProjects> nrfjprog --program 7444.merged.hex --chiperase --verify --reset
    [ #################### ] 0.378s | Erase file - Done erasing
    [ #################### ] 1.897s | Program file - Done programming
    [ #################### ] 1.941s | Verify file - Done verifying
    Applying system reset.
    Run.
    [error] [ Client] - Worker process dies while processing command close

    I was wondering if that meant the board/memory chip wasn't working right, so I also tested the usbd_msc example from nRF5 SDK 11 and it worked just fine.  I had to format the drive, but it formatted and I was able to add a file.  

    I also opened the project you sent and was not able to build it.  Here are the errors if you are interested.  

    Thank you,

    ian

  • Hi ian,

    Strange. I have not been able to reproduce this issue here on my Windows or Linux PC. I also had a colleague with a Windows PC try the same hex file I uploaded, but it worked for him as well. I was able to format the drive and store files to it (it was already formatted so I did not have to format it but I did it anyway).

    FCian said:
    I also opened the project you sent and was not able to build it.  Here are the errors if you are interested.  

    Sorry, I realize now that the project will not build out of the box with SDK v2.7.0 (are some minor API changes in main.c). It is probably easier to download SDK v2.9.0 and build against it. I recommend checking the terminal output for actual build errors and warnings. The "Problems" tab has multiple sources and the errors listed are not always relevant to the build. 

    FCian said:
    I was wondering if that meant the board/memory chip wasn't working right, so I also tested the usbd_msc example from nRF5 SDK 11 and it worked just fine. 

    Assume it wasn't SDK 11, but just to make sure, was it SDK v.17.1.0 you tested with? I don't have a good explanation for why it would work with the old sample, but none of the samples in the nRF Connect SDK. Does the DK have a rev. 2 or 3 of the nRF52840?  

    Edit: forgot to add that the FW I posted has logging enabled over UART if you want to check if any errors are reported.

  • Hey Vidar,

    I updated to SDK v2.9.0 and I can build it with no issues.  I tried flashing the DK I have, but still the same issue.  I've tried it on my windows 11 machine, and 2 windows 10 machines.  The behavior is slightly different on windows 10, it says "Please insert a disk into D:", but 11 just says it needs to be formatted and then dies in the format.

    Here's the board I'm using:

    Well, alright, I just plugged it in again to copy the COM output for you and it works.  I get a drive :)  

    The drive is only 0.98MB, though.  Here's the COM output.

    *** Booting MCUboot v2.1.0-dev-12e5ee106034 ***
    *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Image index: 0, Swap type: none
    I: Bootloader chainload address offset: 0xc000
    �*** Booting My Application v2.9.0 - unknown commit ***
    *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    I: Initialize device SD
    I: offset 0, sector size 512, page size 4096, volume size 1048576
    I: Starting Bluetooth Peripheral LBS example 2.9.0
    I: Area 0 at 0x0 on mx25r6435f@0 for 1048576 bytes
    I: Mount /SD:: 0
    I: /SD:: bsize = 512 ; frsize = 512 ; blocks = 2008 ; bfree = 2008
    I: /SD: opendir: 0
    I: End of files
    I: The device is put in USB mass storage mode.
    I: 2 Sectors of 4096 bytes
    I: alloc wra: 0, fd0
    I: data wra: 0, 1c
    I: SoftDevice Controller build revision:
    I: 2d 79 a1 c8 6a 40 b7 3c |-y..j@.<
    I: f6 74 f9 0b 22 d3 c4 80 |.t.."...
    I: 74 72 82 ba |tr..
    I: HW Platform: Nordic Semiconductor (0x0002)
    I: HW Variant: nRF52x (0x0002)
    I: Firmware: Standard Bluetooth controller (0x00) Version 45.41337 Build 3074452168
    I: No ID address. App must call settings_load()
    I: Bluetooth initialized
    I: Identity: C5:EF:BC:01:81:B4 (random)
    I: HCI: version 6.0 (0x0e) revision 0x106b, manufacturer 0x0059
    I: LMP: version 6.0 (0x0e) subver 0x106b
    I: Advertising successfully started

    I'll get familiar with the code, and let you know if it continues working.  

    Any pointers to get it use the full 16 Mbit (2MB) and eventually my full 2Gbit memory chip, that would be great.

    Thank you,

    ian

  • Hey ian,

    Glad to hear that it seems to be working now. In my sample I was only allocation a portion of the flash to the fafs filesystem, see memory layout below. To use the whole chip, you have to relocate the mcuboot secondary slot to the internal flash (used to for staging FW updates during FW updates). This is if you want to support DFU.

    Using the whole external_flash region for fatfs_storage:

    1. Increase the size of the 'fatfs_storage' partition defined in the pm_static.yml file in the project root:

    fatfs_storage:
      address: 0x0
      affiliation:
      - disk
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0x800000
      extra_params:
        disk_cache_size: 0x1000
        disk_name: SD
        disk_read_only: 0x0
        disk_sector_size: 0x200
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: external_flash
      size: 0x800000

    2. In the sysbuild.conf file, comment the "SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y" line.

    3. Do a full rebuild.

    4. You can run "west build -t partition_manager_report" or click the "Memory report" button in the extension to view the new memory layout.

    FCian said:
    Any pointers to get it use the full 16 Mbit (2MB) and eventually my full 2Gbit memory chip, that would be great.

    It should ideally only be a matter of correctly defining the properties for your flash IC in the devicetree similar to how it is done for the macronix Ic on the nRF52840 DK here: 

    https://github.com/zephyrproject-rtos/zephyr/blob/7cef0e361467136064a066de718af12e00a9e7d9/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts#L241 

    For instance, you will need to add the "address-size-32;" property in your node to enable 32-bit addressing needed for larger memory.

Related