diff --git a/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp b/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp index 59cbd35762411..df47485a30721 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #if 0 #define debug(fmt, args ...) do {printf("%s:%d: " fmt "\n", __FUNCTION__, __LINE__, ## args); } while(0) @@ -416,7 +417,10 @@ int32_t AP_Filesystem_FATFS::read(int fd, void *buf, uint32_t count) UINT total = 0; do { UINT size = 0; - UINT n = MIN(bytes, MAX_IO_SIZE); + UINT n = bytes; + if (!mem_is_dma_safe(buf, count, true)) { + n = MIN(bytes, MAX_IO_SIZE); + } res = f_read(fh, (void *)buf, n, &size); if (res != FR_OK) { errno = fatfs_to_errno((FRESULT)res); @@ -460,7 +464,10 @@ int32_t AP_Filesystem_FATFS::write(int fd, const void *buf, uint32_t count) UINT total = 0; do { - UINT n = MIN(bytes, MAX_IO_SIZE); + UINT n = bytes; + if (!mem_is_dma_safe(buf, count, true)) { + n = MIN(bytes, MAX_IO_SIZE); + } UINT size = 0; res = f_write(fh, buf, n, &size); if (res == FR_DISK_ERR && RETRY_ALLOWED()) {