Skip to content

Commit df3ba3f

Browse files
committed
Adds skeleton for littlefs
1 parent 2e59b8c commit df3ba3f

22 files changed

+244
-3
lines changed

CMake/Modules/FindSTM32F4_CubePackage.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(STM32F4_CubePackage_SRCS
1111

1212
# add HAL files here as required
1313

14-
# SPIFFS
14+
# SPIFFS & littlefs
1515
stm32f4xx_hal_dma.c
1616
stm32f4xx_hal_qspi.c
1717
)

CMake/Modules/FindSTM32F7_CubePackage.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(STM32F7_CubePackage_SRCS
1111

1212
# add HAL files here as required
1313

14-
# SPIFFS
14+
# SPIFFS & littlefs
1515
stm32f7xx_hal_dma.c
1616
stm32f7xx_hal_qspi.c
1717
)

CMake/Modules/FindSTM32H7_CubePackage.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(STM32H7_CubePackage_SRCS
1111

1212
# add HAL files here as required
1313

14-
# SPIFFS
14+
# SPIFFS & littlefs
1515
stm32h7xx_hal_qspi.c
1616
)
1717

CMake/Modules/Findlittlefs.cmake

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Copyright (c) 2019 The nanoFramework project contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
7+
# List of the required littlefs include files.
8+
list(APPEND LITTLEFS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/littlefs_Source)
9+
list(APPEND LITTLEFS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/littlefs_Source/bd)
10+
list(APPEND LITTLEFS_INCLUDE_DIRS ${TARGET_BASE_LOCATION})
11+
12+
set(LITTLEFS_SRCS
13+
14+
# littlefs
15+
lfs.c
16+
lfs_util.c
17+
18+
lfs_filebd.c
19+
lfs_rambd.c
20+
lfs_testbd.c
21+
)
22+
23+
foreach(SRC_FILE ${LITTLEFS_SRCS})
24+
set(LITTLEFS_SRC_FILE SRC_FILE -NOTFOUND)
25+
find_file(LITTLEFS_SRC_FILE ${SRC_FILE}
26+
PATHS
27+
${PROJECT_BINARY_DIR}/littlefs_Source
28+
29+
CMAKE_FIND_ROOT_PATH_BOTH
30+
)
31+
# message("${SRC_FILE} >> ${LITTLEFS_SRC_FILE}") # debug helper
32+
list(APPEND FATFS_SOURCES ${LITTLEFS_SRC_FILE})
33+
endforeach()
34+
35+
include(FindPackageHandleStandardArgs)
36+
37+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LITTLEFS DEFAULT_MSG LITTLEFS_INCLUDE_DIRS LITTLEFS_SOURCES)

CMake/littlefs.CMakeLists.cmake.in

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) 2020 The nanoFramework project contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
cmake_minimum_required(VERSION 3.15)
7+
8+
project(littlefs-download NONE)
9+
10+
include(ExternalProject)
11+
12+
# download littlefs source from official GitHub repo
13+
ExternalProject_Add(
14+
LITTLEFS
15+
PREFIX LITTLEFS
16+
SOURCE_DIR ${CMAKE_BINARY_DIR}/littlefs_Source
17+
GIT_REPOSITORY https://github.com/ARMmbed/littlefs
18+
GIT_TAG "v2.2.1" # target latest release
19+
GIT_SHALLOW 1 # download only the tip of the branch, not the complete history
20+
TIMEOUT 10
21+
LOG_DOWNLOAD 1
22+
# Disable all other steps
23+
INSTALL_COMMAND ""
24+
CONFIGURE_COMMAND ""
25+
BUILD_COMMAND ""
26+
)

CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,31 @@ endif()
357357

358358
#################################################################
359359

360+
#################################################################
361+
# enables support for littlefs file system
362+
# (default is OFF so littlefs is NOT supported)
363+
option(NF_FEATURE_USE_LITTLEFS "option to enable support for littlefs file system")
364+
365+
if(NF_FEATURE_USE_LITTLEFS)
366+
367+
# this feature currently is supported only on ChibiOS and ESP32
368+
if(NOT RTOS_CHIBIOS_CHECK)
369+
message(FATAL_ERROR "Support for littlefs is only available for ChibiOS Cortex-M and ESP32 targets.")
370+
endif()
371+
372+
# force inclusion of Windows.Storage API
373+
set(API_Windows.Storage ON CACHE INTERNAL "Forcing Windows.Storage API option to ON")
374+
375+
set(NF_FEATURE_USE_LITTLEFS_OPTION TRUE CACHE INTERNAL "Set nF littlefs feature TRUE")
376+
377+
message(STATUS "Support for littlefs is included")
378+
else()
379+
set(NF_FEATURE_USE_LITTLEFS_OPTION FALSE CACHE INTERNAL "Set nF littlefs feature FALSE")
380+
message(STATUS "Support for littlefs IS NOT included")
381+
endif()
382+
383+
#################################################################
384+
360385
if(RTOS_CHIBIOS_CHECK)
361386

362387
#################################################################

CMakeSettings.SAMPLE.json

+5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@
253253
"value": "False",
254254
"type": "BOOL"
255255
},
256+
{
257+
"name": "NF_FEATURE_USE_LITTLEFS",
258+
"value": "False",
259+
"type": "BOOL"
260+
},
256261
{
257262
"name": "NF_FEATURE_HAS_SDCARD",
258263
"value": "True",

CMakeSettings.json

+5
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@
456456
"value": "False",
457457
"type": "BOOL"
458458
},
459+
{
460+
"name": "NF_FEATURE_USE_LITTLEFS",
461+
"value": "False",
462+
"type": "BOOL"
463+
},
459464
{
460465
"name": "NF_FEATURE_HAS_SDCARD",
461466
"value": "True",

cmake-variants.TEMPLATE.json

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"TI_BOARD" : "<valid-TI-board-name-from-boards-collection>",
5252
"TI_SL_CC32xx_SDK_SOURCE" : "<path-to-local-TI-SimpleLink-CC32xx-SDK-source-mind-the-forward-slash>",
5353
"SPIFFS_SOURCE" : "<path-to-local-SPIFFS-source-mind-the-forward-slash>",
54+
"LITTLEFS_SOURCE" : "<path-to-local-littlefs-source-mind-the-forward-slash>",
5455
"SWO_OUTPUT" : "OFF-default-ON-to-enable-ARM-CortexM-Single-Wire-Output",
5556
"FATFS_VERSION": "<valid-fatfs-version-if-empty-use-default-set-cmake>",
5657
"NF_BUILD_RTM" : "OFF-default-ON-to-enable-RTM-build",
@@ -69,6 +70,7 @@
6970
"NF_FEATURE_HAS_SDCARD" : "OFF-default-ON-to-enable-support-for-SDCard-storage-device",
7071
"NF_FEATURE_HAS_USB_MSD" : "OFF-default-ON-to-enable-support-for-USB-Mass-storage-device",
7172
"NF_FEATURE_USE_SPIFFS" : "OFF-default-ON-to-enable-support-for-SPI-flash-file-system",
73+
"NF_FEATURE_USE_LITTLEFS" : "OFF-default-ON-to-enable-support-for-little-file-system",
7274
"NF_PLATFORM_NO_CLR_TRACE" : "OFF-default-ON-to-disable-all-trace-on-CLR",
7375
"NF_CLR_NO_IL_INLINE" : "OFF-default-ON-to-disable-CLR-IL-inlining",
7476
"NF_INTEROP_ASSEMBLIES" : [ "Assembly1-Namespace", "Assembly2-Namespace" ],

targets/CMSIS-OS/ChibiOS/CMakeLists.txt

+100
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,106 @@ if(NF_FEATURE_USE_SPIFFS)
596596

597597
endif()
598598

599+
600+
# if support for littlefs is enabled add it to the build
601+
if(NF_FEATURE_USE_LITTLEFS)
602+
603+
# check if LITTLEFS_SOURCE was specified or if it's empty (default is empty)
604+
set(NO_LITTLEFS_SOURCE TRUE)
605+
606+
if(LITTLEFS_SOURCE)
607+
if(NOT "${LITTLEFS_SOURCE}" STREQUAL "")
608+
set(NO_LITTLEFS_SOURCE FALSE)
609+
endif()
610+
endif()
611+
612+
if(NO_LITTLEFS_SOURCE)
613+
# no littlefs source specified, download it from it's repo
614+
615+
# check for Git (needed here for advanced warning to user if it's not installed)
616+
find_package(Git)
617+
618+
# check if Git was found, if not report to user and abort
619+
if(NOT GIT_EXECUTABLE)
620+
message(FATAL_ERROR "error: could not find Git, make sure you have it installed.")
621+
endif()
622+
623+
# need to setup a separate CMake project to download the code from the GitHub repository
624+
# otherwise it won't be available before the actual build step
625+
configure_file("${PROJECT_SOURCE_DIR}/CMake/littlefs.CMakeLists.cmake.in"
626+
"${CMAKE_BINARY_DIR}/littlefs_Download/CMakeLists.txt")
627+
628+
# setup CMake project for littlefs download
629+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
630+
RESULT_VARIABLE result
631+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/littlefs_Download")
632+
633+
# run build on littlefs download CMake project to perform the download
634+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
635+
RESULT_VARIABLE result
636+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/littlefs_Download")
637+
638+
# add littlefs as external project
639+
ExternalProject_Add(
640+
LITTLEFS
641+
PREFIX LITTLEFS
642+
SOURCE_DIR ${CMAKE_BINARY_DIR}/littlefs_Source
643+
GIT_REPOSITORY https://github.com/ARMmbed/littlefs
644+
GIT_TAG "v2.2.1" # target latest release
645+
GIT_SHALLOW 1 # download only the tip of the branch, not the complete history
646+
TIMEOUT 10
647+
LOG_DOWNLOAD 1
648+
649+
# Disable all other steps
650+
CONFIGURE_COMMAND ""
651+
BUILD_COMMAND ""
652+
INSTALL_COMMAND ""
653+
)
654+
655+
else()
656+
# littlefs source was specified
657+
658+
# sanity check is source path exists
659+
if(EXISTS "${LITTLEFS_SOURCE}/")
660+
661+
# check if we already have the sources, no need to copy again
662+
if(NOT EXISTS "${CMAKE_BINARY_DIR}/littlefs_Source")
663+
message(STATUS "littlefs source from: ${LITTLEFS_SOURCE}")
664+
file(COPY "${LITTLEFS_SOURCE}/" DESTINATION "${CMAKE_BINARY_DIR}/littlefs_Source")
665+
else()
666+
message(STATUS "Using local cache of littlefs source from ${LITTLEFS_SOURCE}")
667+
endif()
668+
669+
set(LITTLEFS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/littlefs_Source)
670+
set(LITTLEFS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/littlefs_Source/bd)
671+
else()
672+
message(FATAL_ERROR "Couldn't find littlefs source at ${LITTLEFS_SOURCE}/")
673+
endif()
674+
675+
# add littlefs as external project
676+
ExternalProject_Add(
677+
LITTLEFS
678+
PREFIX LITTLEFS
679+
SOURCE_DIR ${CMAKE_BINARY_DIR}/littlefs_Source
680+
681+
# Disable all other steps
682+
CONFIGURE_COMMAND ""
683+
BUILD_COMMAND ""
684+
INSTALL_COMMAND ""
685+
)
686+
687+
endif()
688+
689+
# get source dir for littlefs CMake project
690+
ExternalProject_Get_Property(LITTLEFS SOURCE_DIR)
691+
692+
set(LITTLEFS_LIBRARIES "${CMAKE_SHARED_LIBRARY_PREFIX}LITTLEFS${CMAKE_SHARED_LIBRARY_SUFFIX}")
693+
include_directories(${LITTLEFS_INCLUDE_DIRS})
694+
695+
add_subdirectory(littlefs)
696+
697+
endif()
698+
599699
# add target ChibiOS dirs
600700
add_subdirectory(Include)
601701
add_subdirectory(common)

targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_storage_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111

1212
// includes SPIFFS in storage
1313
#define USE_SPIFFS_FOR_STORAGE FALSE
14+
15+
// includes littlefs in storage
16+
#define USE_LITTLEFS_FOR_STORAGE FALSE

targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111

1212
// includes SPIFFS in storage
1313
#define USE_SPIFFS_FOR_STORAGE FALSE
14+
15+
// includes littlefs in storage
16+
#define USE_LITTLEFS_FOR_STORAGE FALSE

targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ if(NF_FEATURE_USE_SPIFFS)
6262
find_package(SPIFFS REQUIRED)
6363
endif()
6464

65+
# littlefs
66+
if(NF_FEATURE_USE_LITTLEFS)
67+
find_package(STM32F7_CubePackage REQUIRED)
68+
find_package(LITTLEFS REQUIRED)
69+
endif()
70+
6571
#######################################
6672

6773
add_subdirectory("common")
@@ -139,6 +145,9 @@ add_executable(
139145
# sources for SPIFFS
140146
${SPIFFS_SOURCES}
141147

148+
# sources for littlefs
149+
${LITTLEFS_SOURCES}
150+
142151
# sources for nanoFramework APIs
143152
${TARGET_NANO_APIS_SOURCES}
144153
)
@@ -219,6 +228,9 @@ target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC
219228

220229
# includes for SPIFFS
221230
${SPIFFS_INCLUDE_DIRS}
231+
232+
# includes for littlefs
233+
${LITTLEFS_INCLUDE_DIRS}
222234
)
223235

224236
# set compiler options

targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/littlefs_config.h

Whitespace-only changes.

targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_littlefs.c

Whitespace-only changes.

targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_littlefs.h

Whitespace-only changes.

targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111

1212
// includes SPIFFS in storage
1313
#define USE_SPIFFS_FOR_STORAGE FALSE
14+
15+
// includes littlefs in storage
16+
#define USE_LITTLEFS_FOR_STORAGE FALSE

targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#if (USE_SPIFFS_FOR_STORAGE == TRUE)
1919
#include <hal_spiffs.h>
2020
#endif
21+
#if (USE_LITTLEFS_FOR_STORAGE == TRUE)
22+
#include <hal_littlefs.h>
23+
#endif
2124

2225
// defining these types here to make it shorter and improve code readability
2326
typedef Library_win_storage_native_Windows_Storage_StorageFolder StorageFolder;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (c) 2019 The nanoFramework project contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
# include littlefs sources, if feature is enabled
7+
if(NF_FEATURE_USE_LITTLEFS)
8+
list(APPEND TARGET_CHIBIOS_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/hal_littlefs.c")
9+
list(APPEND TARGET_CHIBIOS_COMMON_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
10+
endif()
11+
12+
# make var global
13+
set(TARGET_CHIBIOS_COMMON_SOURCES ${TARGET_CHIBIOS_COMMON_SOURCES} CACHE INTERNAL "make global")
14+
set(TARGET_CHIBIOS_COMMON_INCLUDE_DIRS ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS} CACHE INTERNAL "make global")

targets/CMSIS-OS/ChibiOS/nanoCLR/littlefs/hal_littlefs.c

Whitespace-only changes.

targets/CMSIS-OS/ChibiOS/nanoCLR/littlefs/hal_littlefs.h

Whitespace-only changes.

targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// enable SPIFFS
1515
#define NF_FEATURE_USE_SPIFFS @NF_FEATURE_USE_SPIFFS_OPTION@
1616

17+
// enable littlefs
18+
#define NF_FEATURE_USE_LITTLEFS @NF_FEATURE_USE_LITTLEFS_OPTION@
19+
1720
// set preference to enable (or not) the RTC subsystem
1821
#define HAL_USE_RTC @HAL_USE_RTC_OPTION@
1922

0 commit comments

Comments
 (0)