diff --git a/features/storage/filesystem/littlefs/LittleFileSystem.cpp b/features/storage/filesystem/littlefs/LittleFileSystem.cpp index 6e20476c7b4..bb2fb6fe794 100644 --- a/features/storage/filesystem/littlefs/LittleFileSystem.cpp +++ b/features/storage/filesystem/littlefs/LittleFileSystem.cpp @@ -24,7 +24,7 @@ namespace mbed { extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size) { - uint32_t initial_xor = *crc; + uint32_t initial_xor = lfs_rbit(*crc); // lfs_cache_crc calls lfs_crc for every byte individually, so can't afford // start-up overhead for hardware acceleration. Limit to table-based. MbedCRC ct(initial_xor, 0x0, true, true); diff --git a/features/storage/filesystem/littlefs/TESTS/filesystem/seek/main.cpp b/features/storage/filesystem/littlefs/TESTS/filesystem/seek/main.cpp index b8286dc8463..82dfc327cea 100644 --- a/features/storage/filesystem/littlefs/TESTS/filesystem/seek/main.cpp +++ b/features/storage/filesystem/littlefs/TESTS/filesystem/seek/main.cpp @@ -535,7 +535,7 @@ void test_boundary_seek_and_write() size = strlen("hedgehoghog"); const off_t offsets[] = {512, 1020, 513, 1021, 511, 1019}; - for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) { + for (size_t i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) { off_t off = offsets[i]; memcpy(buffer, "hedgehoghog", size); res = file[0].seek(off, SEEK_SET); diff --git a/features/storage/filesystem/littlefs/littlefs/lfs_util.h b/features/storage/filesystem/littlefs/littlefs/lfs_util.h index 50e25daa7fa..095b15e0111 100644 --- a/features/storage/filesystem/littlefs/littlefs/lfs_util.h +++ b/features/storage/filesystem/littlefs/littlefs/lfs_util.h @@ -47,6 +47,7 @@ extern "C" #ifdef __MBED__ #include "mbed_debug.h" #include "mbed_assert.h" +#include "cmsis_compiler.h" #else #define MBED_LFS_ENABLE_INFO false #define MBED_LFS_ENABLE_DEBUG true @@ -183,6 +184,21 @@ static inline uint32_t lfs_tole32(uint32_t a) { return lfs_fromle32(a); } +// Reverse the bits in a +static inline uint32_t lfs_rbit(uint32_t a) { +#if !defined(LFS_NO_INTRINSICS) && MBED_LFS_INTRINSICS && \ + defined(__MBED__) + return __RBIT(a); +#else + a = ((a & 0xaaaaaaaa) >> 1) | ((a & 0x55555555) << 1); + a = ((a & 0xcccccccc) >> 2) | ((a & 0x33333333) << 2); + a = ((a & 0xf0f0f0f0) >> 4) | ((a & 0x0f0f0f0f) << 4); + a = ((a & 0xff00ff00) >> 8) | ((a & 0x00ff00ff) << 8); + a = (a >> 16) | (a << 16); + return a; +#endif +} + // Calculate CRC-32 with polynomial = 0x04c11db7 void lfs_crc(uint32_t *crc, const void *buffer, size_t size);