Skip to content

Commit afc3306

Browse files
committed
littlefs: Adopted MBED_ASSERT and littlefs.enable_assert
Much like the logging functions, assertions can be enabled, disabled and forced with the littlefs.enable_assert config option. Integrates with the new LFS_ASSERT macro.
1 parent 453a1b6 commit afc3306

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

features/filesystem/littlefs/littlefs/lfs_util.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@
3737
// macros must not have side-effects as the macros can be removed for a smaller
3838
// code footprint
3939

40-
// Logging functions
4140
#ifdef __MBED__
4241
#include "mbed_debug.h"
42+
#include "mbed_assert.h"
4343
#else
44-
#define MBED_LFS_ENABLE_INFO false
45-
#define MBED_LFS_ENABLE_DEBUG true
46-
#define MBED_LFS_ENABLE_WARN true
47-
#define MBED_LFS_ENABLE_ERROR true
44+
#define MBED_LFS_ENABLE_INFO false
45+
#define MBED_LFS_ENABLE_DEBUG true
46+
#define MBED_LFS_ENABLE_WARN true
47+
#define MBED_LFS_ENABLE_ERROR true
48+
#define MBED_LFS_ENABLE_ASSERT true
4849
#endif
4950

51+
// Logging functions
5052
#if !defined(LFS_NO_INFO) && MBED_LFS_ENABLE_INFO
5153
#define LFS_INFO(fmt, ...) printf("lfs info:%d: " fmt "\n", __LINE__, __VA_ARGS__)
5254
#elif !defined(LFS_NO_INFO) && !defined(MBED_LFS_ENABLE_INFO)
@@ -80,8 +82,10 @@
8082
#endif
8183

8284
// Runtime assertions
83-
#ifndef LFS_NO_ASSERT
85+
#if !defined(LFS_NO_ASSERT) && MBED_LFS_ENABLE_ASSERT
8486
#define LFS_ASSERT(test) assert(test)
87+
#elif !defined(LFS_NO_ASSERT) && !defined(MBED_LFS_ENABLE_ASSERT)
88+
#define LFS_ASSERT(test) MBED_ASSERT(test)
8589
#else
8690
#define LFS_ASSERT(test)
8791
#endif

features/filesystem/littlefs/mbed_lib.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
"macro_name": "MBED_LFS_ENABLE_ERROR",
4141
"value": null,
4242
"help": "Enables error logging, true = enabled, false = disabled, null = disabled only in release builds"
43+
},
44+
"enable_assert": {
45+
"macro_name": "MBED_LFS_ENABLE_ASSERT",
46+
"value": null,
47+
"help": "Enables asserts, true = enabled, false = disabled, null = disabled only in release builds"
4348
}
4449
}
4550
}

0 commit comments

Comments
 (0)