Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/storage/filesystem/littlefs/LittleFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<POLY_32BIT_ANSI, 32, CrcMode::TABLE> ct(initial_xor, 0x0, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions features/storage/filesystem/littlefs/littlefs/lfs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down