I got the Zephyr littlefs sample on the nRF5340 DK to build, but never gets to main().

I attempted to port the littlefs sample to the nRF5340 Developer Kit. I've gotten it to build but when I flash it there is no log output. When I try to debug it the startup process looks normal but I never hit a breakpoint I set in main().

After searching, I found this post ( littlefs sample on nrf5340dk not running) and tried building and running the modified example "littlefs2" from that thread. Same result: it never seems to get to main().

I succeeded in getting the flash_jesd216 built and running correctly on the nRF5340 DK, as well as my own app to write to the external flash and do a read back to verify. So I know the hardware and my development environment are basically good.

I'm using nRF Connect SDK v2.1.0 installed from the Toolchain Manager (v1.2.0). I'm running Ubuntu 20.04.5 LTS. I have nRF5340 DK hardware rev 2.0.0. I've attached zip archives of both of my attempts at getting this working.

7142.littlefs2.zip1581.littlefs.zip

  • Hello Mark,

    Thank you for contacting DevZone at NordicSemi.

    Your query is regarding running a littlefs sample on nRF5340-DK.

    I started with littlefs (/zephyr/samples/subsys/fs/littlefs) sample project, and the build was successful as yours. Then I connected output terminal with the COM port. I flashed the application on the nRF5340-DK. I was not able to see the output on terminal and looked like nothing has happened. Actually, I was connected to the wrong COM port. I changed my COM port and reset the device. I was able to see the output and the complete execution of the main().

    I am on Windows 10 platform using NCS v2.1.0.

    I am attaching terminal output here:

    Connected via Serial Port with settings COM13 115200 8n1 rtscts:off
    
    *** Booting Zephyr OS build v3.1.99-ncs1-rc1  ***
    Sample program to r/w files on littlefs
    Area 6 at 0xfa000 on flash-controller@39000 for 24576 bytes
    I: LittleFS version 2.4, disk version 2.0
    I: FS at flash-controller@39000:0xfa000 is 6 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1077: Corrupted dir pair at {0x0, 0x1}
    W: can't mount (LFS -84); formatting
    I: /lfs mounted
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 4
    
    Listing dir /lfs ...
    /lfs/boot_count read count:0 (bytes: 0)
    /lfs/boot_count write new boot count 1: [wr:1]
    I: Test file: /lfs/pattern.bin not found, create one!
    ------ FILE: /lfs/pattern.bin ------
    01 55 55 55 55 55 55 55 02 55 55 55 55 55 55 55
    03 55 55 55 55 55 55 55 04 55 55 55 55 55 55 55
    05 55 55 55 55 55 55 55 06 55 55 55 55 55 55 55
    07 55 55 55 55 55 55 55 08 55 55 55 55 55 55 55
    09 55 55 55 55 55 55 55 0a 55 55 55 55 55 55 55
    0b 55 55 55 55 55 55 55 0c 55 55 55 55 55 55 55
    0d 55 55 55 55 55 55 55 0e 55 55 55 55 55 55 55
    0f 55 55 55 55 55 55 55 10 55 55 55 55 55 55 55
    11 55 55 55 55 55 55 55 12 55 55 55 55 55 55 55
    13 55 55 55 55 55 55 55 14 55 55 55 55 55 55 55
    15 55 55 55 55 55 55 55 16 55 55 55 55 55 55 55
    17 55 55 55 55 55 55 55 18 55 55 55 55 55 55 55
    19 55 55 55 55 55 55 55 1a 55 55 55 55 55 55 55
    1b 55 55 55 55 55 55 55 1c 55 55 55 55 55 55 55
    1d 55 55 55 55 55 55 55 1e 55 55 55 55 55 55 55
    1f 55 55 55 55 55 55 55 20 55 55 55 55 55 55 55
    21 55 55 55 55 55 55 55 22 55 55 55 55 55 55 55
    23 55 55 55 55 55 55 55 24 55 55 55 55 55 55 55
    25 55 55 55 55 55 55 55 26 55 55 55 55 55 55 55
    27 55 55 55 55 55 55 55 28 55 55 55 55 55 55 55
    29 55 55 55 55 55 55 55 2a 55 55 55 55 55 55 55
    2b 55 55 55 55 55 55 55 2c 55 55 55 55 55 55 55
    2d 55 55 55 55 55 55 55 2e 55 55 55 55 55 55 55
    2f 55 55 55 55 55 55 55 30 55 55 55 55 55 55 55
    31 55 55 55 55 55 55 55 32 55 55 55 55 55 55 55
    33 55 55 55 55 55 55 55 34 55 55 55 55 55 55 55
    35 55 55 55 55 55 55 55 36 55 55 55 55 55 55 55
    37 55 55 55 55 55 55 55 38 55 55 55 55 55 55 55
    39 55 55 55 55 55 55 55 3a 55 55 55 55 55 55 55
    3b 55 55 55 55 55 55 55 3c 55 55 55 55 55 55 55
    3d 55 55 55 55 55 55 55 3e 55 55 55 55 55 55 55
    3f 55 55 55 55 55 55 55 40 55 55 55 55 55 55 55
    
    41 55 55 55 55 55 55 55 42 55 55 55 55 55 55 55
    43 55 55 55 55 55 55 55 44 55 55 55 55 55 55 55
    45 55 aa
    I: /lfs unmounted
    /lfs unmount: 0

    And the complete application folder (in zip format) for reference.

    1462.littlefs.zip

    Regards,

    Naeem

  • Hi Naeem,

    I've examined the zip archive attached to your response. You do not appear to be using a device tree overlay for the nRF5340dk. This makes me think you built your littlefs to use the SoC's internal flash for the littlefs filesystem storage, as I believe that's where the littlefs storage is located without an overlay.

    I should have clarified that my goal is to put the littlefs storage on the external flash connected over the QSPI. If you look in the 1581.littlefs.zip archives I attached to my OP I have created an overlay that deletes the node defining the littlefs partition in internal flash storage, and defined one for the QSPI flash storage. I copied this from the overlay for the nRF52840dk in the "boards" sub directory.

    Also, in my testing I programmed a different, functional example to flash and saw log output over my serial connection, then programmed my littlefs project and saw no output, without disconnecting the serial port. I also tried connecting both serial ports and pressing the reset button.

  • Hi Mark,

    As per your provided information, I have now included the overlay file. I can still build, flash and see complete output. Snapshot from VS Code showing output, the overlay file in the app directory and the compiled DTS is attached. 

    *Just a small note, I was not able to extract your complete zip directory as it was complaining about "too long" names. Nonetheless, our project structure is same: starting from little-fs sample and then updating DTS through overlay.

    VS Code Snapshot

    Naeem

  • Hi Naeem,

    I'm back from a 10-day vacation and just getting back to this. Can you attach an archive of your project with the overlay file for the littlefs using the QSPI flash? Alternatively, I could try to archive a clean of my second example as the "file names too long" probably applies to generated files.

    FWIW since I couldn't get the littlefs library that's "built in" to Zephyr to work I tried incorporating littlefs source code from its original git repository as application code. I did get that to work.

    Mark

  • Hi Mark,

    mperry_at_scram said:
    Can you attach an archive of your project with the overlay file for the littlefs using the QSPI flash?

    Yes, sure. Please find attached.

    mperry_at_scram said:
    I could try to archive a clean of my second example as the "file names too long" probably applies to generated files.

    This was solved by placing the downloaded zip file in the c:/ and then extracting it (otherwise it was very long path, containing c:/user/username/downloads/). Moreover, files in the build folder can have long names depending how you named your build folder.

    Nonetheless, I was able to extract your project and compare with mine. Interestingly the projects were similar, and now I know why you were not able to see the output. I am able to correctly build, flash and see output from your project.

    The problem (in fact not the problem, but confusion / mistake) lies in the build process. I have seen that you built the project for "nrf5340dk_nrf5340_cpuapp_ns", which means that your application is built for non-secure domain, and a trusted firmware (TF-M) will be included that will provide security by separation. 

    You can read more about Trusted-Firmware here. If you are interested to build for NS domain, you can look at samples which include TF-M.

    At this time, to build, flash and see the output, you may use "nrf5340dk_nrf5340_cpuapp" as your build target, and it will be done.

    0535.littlefs_my.zip

    Hope it helps. With regards,

    Naeem

Related