fatal error: lfs.h: No such file or directory

Greetings,

We are planning to integrate the use of the internal storage of our nRF52840 MCU using LittleFS so we tried starting out by just opening the sample zephyr/samples/subsys/fs/littlefs and after adding the nrf52840dk_nrf52840 board in the build configuration and building the project the build was not successful and the following error was shown at the output terminal:

[79/173] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj 
C:\ncs\toolchains\v2.1.0\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52840_XXAA -DUSE_PARTITION_MANAGER=0 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.1.0/zephyr/include/zephyr -IC:/ncs/v2.1.0/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.1.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.1.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.1.0/nrf/include -IC:/ncs/v2.1.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.1.0/modules/hal/nordic/nrfx -IC:/ncs/v2.1.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.1.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.1.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v2.1.0/modules/debug/segger/SEGGER -IC:/ncs/v2.1.0/modules/debug/segger/Config -IC:/ncs/v2.1.0/zephyr/modules/segger/. -isystem C:/ncs/v2.1.0/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include -isystem c:/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed -isystem C:/ncs/v2.1.0/nrfxlib/crypto/nrf_cc310_platform/include -Os -imacros C:/ncs/feel_v2_fw/littlefs/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.1.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/ncs/feel_v2_fw/littlefs=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.1.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.1.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
In file included from c:\ncs\feel_v2_fw\littlefs\src\main.c:15:
C:\ncs\v2.1.0\zephyr\include\zephyr\fs\littlefs.h:14:10: fatal error: lfs.h: No such file or directory
   14 | #include <lfs.h>
      |          ^~~~~~~
compilation terminated.

What could be causing this? We just build a sample as it was in the SDK (no changes just created a new application with the sample as the 'Application template', selected the nrf52840dk_nrf52840 board in the build configuration and pressed build).

Thank you!

Best regards,

Stavros

Parents
  • Hi, 

    Updating the CMakeLists.txt of your app to include modules/fs/littlefs and zephyr/subsys/fs as the example should fix the issue. 

    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(littlefs)
    
    FILE(GLOB app_sources src/*.c)
    # NORDIC SDK APP START
    target_sources(app PRIVATE src/main.c)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/../modules/fs/littlefs)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/fs)
    
    # NORDIC SDK APP END
    target_sources(app PRIVATE ${app_sources})

    Regards,
    Amanda H.

  • Hi,

    Thank you for your imediate response!

    As I mentioned in my first message we are using the example/sample   in zephyr/samples/subsys/fs/littlefs right now ( not our app ). The CMakeLists.txt file in the sample/example (ncs 2.1.0) I have is as shown below.

    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(littlefs)
    
    FILE(GLOB app_sources src/*.c)
    target_sources(app PRIVATE ${app_sources})

    I downloaded and installed the SDK using your guide and nRF Connect application, how is it possible that I have a different sample than you?

    I added the two lines missing (apparently) from my example and the build fails again showing the error below:

    FAILED: CMakeFiles/app.dir/src/main.c.obj 
    C:\ncs\toolchains\v2.1.0\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52840_XXAA -DUSE_PARTITION_MANAGER=0 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.1.0/modules/fs/littlefs -IC:/ncs/v2.1.0/zephyr/subsys/fs -IC:/ncs/v2.1.0/zephyr/include/zephyr -IC:/ncs/v2.1.0/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.1.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.1.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.1.0/nrf/include -IC:/ncs/v2.1.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.1.0/modules/hal/nordic/nrfx -IC:/ncs/v2.1.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.1.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.1.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v2.1.0/modules/debug/segger/SEGGER -IC:/ncs/v2.1.0/modules/debug/segger/Config -IC:/ncs/v2.1.0/zephyr/modules/segger/. -isystem C:/ncs/v2.1.0/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include -isystem c:/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed -isystem C:/ncs/v2.1.0/nrfxlib/crypto/nrf_cc310_platform/include -Os -imacros C:/ncs/feel_v2_fw/littlefs/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.1.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/ncs/feel_v2_fw/littlefs=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.1.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.1.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
    In file included from c:\ncs\feel_v2_fw\littlefs\src\main.c:15:
    C:\ncs\v2.1.0\zephyr\include\zephyr\fs\littlefs.h:34:29: error: 'CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE' undeclared here (not in a function)
       34 |  uint32_t *lookahead_buffer[CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE / sizeof(uint32_t)];

    What could be causing this? We are simply using the example as is in the SDK(no modifications) what could be causing these errors when building an example?

    Thank you

    Regards

    Stavros

  • Hi, 

    clockis said:
    As I mentioned in my first message we are using the example/sample   in zephyr/samples/subsys/fs/littlefs right now ( not our app ).

    I know, but it is duplicated into the folder out of NCS. So I would say it's your app because some source files have different relative paths than the samples in the NCS. 

    From the error, it seems it cannot find lfs.h which locates under modules/fs/littlefs and Kconfig.littlefs for CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE under zephyr\subsys\fs. Therefore, it needs to include them in the CMakeList. 

    -Amanda H.

  • Hi Amanda,

    Thank you for your quick response!

    I understand what you are saying but when including files, from the SDK using the <> brackets instead of the " " , the system should look outside the relative path of the application and search the files in the specified directories outside the application (I am assuming this points to the SDK). I am mentioning this as I have used many other modules from the SDK for our custom app FW (for our product) such as the SMP server, MCUBoot, GPIO, I2C, SPI and lots of others which are included in the same way (using the <> include brackets) and I never had to include their paths in the CMakeLists.txt file I just used #include in the code thats why this seems unexpected to me especially for working with a sample.

    I have also worked with multiple other samples the same way (peripheral_uart, smp_server etc.) using the same method as I did with the littlefs sample (Create a new application > Application template > Select the sample) and none of them needed to be modified in this way to include the relative paths.

    Is this sample different from others and other modules of th SDK in some way that requires these kind of modifications? I am asking this because this is confusing to me and I want to understand it so I can fix and avoid similar issues in the future.

    Anyways, I tested your suggestion and still get a build error.

    CMakeLists.txt

    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(littlefs)
    
    FILE(GLOB app_sources src/*.c)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE src/main.c)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/../modules/fs/littlefs)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/fs)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/zephyr/subsys/fs)
    
    # NORDIC SDK APP END
    
    target_sources(app PRIVATE ${app_sources})

    I also tried this

    CMakeLists.txt

    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(littlefs)
    
    FILE(GLOB app_sources src/*.c)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE src/main.c)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/../modules/fs/littlefs)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/fs)
    
    # NORDIC SDK APP END
    
    target_sources(app PRIVATE ${app_sources})

    and still got the same output shown below

    Build Output:

    In file included from c:\ncs\feel_v2_fw\littlefs\src\main.c:15:
    C:\ncs\v2.1.0\zephyr\include\zephyr\fs\littlefs.h:34:29: error: 'CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE' undeclared here (not in a function)
       34 |  uint32_t *lookahead_buffer[CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE / sizeof(uint32_t)];

    Thank you very much in advance for the support!

    Best regards,

    Stavros

  • Hi, 

    I usually put the app folder under C:\ncs\v2.1.0\ to contain the different samples. Then, importing those samples by adding an existing application to avoid the path issue.  

    Could you try to Clean Build Configuration and build again?

      

    -Amanda H.

  • Hi Amanda,

    After enabling the configuration options and adding the relevant devicetree node to our custom application the LittleFS is working properly with successfull write/reads and file creation. 

    Unfortunately I am not sure why the sample wasnt working as they reside in the exact same directory (C:/ncs/<custom_fw_directory>/) so I can not provide a solution to the previous issue at this moment.

    Thank you for your patience and support !

    BR

    Stavros

Reply
  • Hi Amanda,

    After enabling the configuration options and adding the relevant devicetree node to our custom application the LittleFS is working properly with successfull write/reads and file creation. 

    Unfortunately I am not sure why the sample wasnt working as they reside in the exact same directory (C:/ncs/<custom_fw_directory>/) so I can not provide a solution to the previous issue at this moment.

    Thank you for your patience and support !

    BR

    Stavros

Children
Related