Skip to content

Commit a484a93

Browse files
committed
nRF: disk_read must be 4-byte aligned
.. a requirement that oofatfs needs to be taught to respect. This problem can be demonstrated with the following snippet, except that the related file ("test.bin") must also be contiguous on the filesystem. You can ensure this by reformatting your device's filesystem before testing, then copying any single file bigger than 4kB to test.bin. f = open("test.bin", "rb") f.seek(2048) b = bytearray(2048) v = memoryview(b) f.readinto(v[909:]) Closes: #2332
1 parent 387ab6c commit a484a93

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/oofatfs/ff.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,11 @@ FRESULT f_read (
33823382
if (!sect) ABORT(fs, FR_INT_ERR);
33833383
sect += csect;
33843384
cc = btr / SS(fs); /* When remaining bytes >= sector size, */
3385-
if (cc) { /* Read maximum contiguous sectors directly */
3385+
if (cc
3386+
#if _FS_DISK_READ_ALIGNED
3387+
&& (((int)rbuff & 3) == 0)
3388+
#endif
3389+
) {/* Read maximum contiguous sectors directly */
33863390
if (csect + cc > fs->csize) { /* Clip at cluster boundary */
33873391
cc = fs->csize - csect;
33883392
}

lib/oofatfs/ffconf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@
343343
/ SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
344344
/ included somewhere in the scope of ff.h. */
345345

346+
// Set to nonzero if buffers passed to disk_read have a word alignment
347+
// restriction
348+
#ifndef _FS_DISK_READ_ALIGNED
349+
#define _FS_DISK_READ_ALIGNED 0
350+
#endif
351+
346352
/* #include <windows.h> // O/S definitions */
347353

348354

ports/nrf/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ CFLAGS += -Wno-undef
106106
CFLAGS += -Wno-cast-align
107107

108108
NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET
109+
NRF_DEFINES += -D_FS_DISK_READ_ALIGNED=1
109110
CFLAGS += $(NRF_DEFINES)
110111

111112
CFLAGS += \

0 commit comments

Comments
 (0)