Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align memory for SDC read on ChibiOS #2889

Closed
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
22 changes: 19 additions & 3 deletions targets/ChibiOS/_FatFS/fatfs_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
/* disk I/O modules and attach it to FatFs module with common interface. */
/*-----------------------------------------------------------------------*/

#include "hal.h"
#include <nanoHAL_v2.h>
#include <hal.h>
#include <cache.h>
#include "ffconf.h"
#include "ff.h" /* Obtains integer types */
#include "diskio.h" /* Declarations of disk functions */
Expand Down Expand Up @@ -109,6 +111,11 @@ DSTATUS disk_status(BYTE pdrv /* Physical drive number (0..) */
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */

#if defined(__GNUC__)
__attribute__((aligned(32)))
#endif
uint8_t sd_readBuffer[MMCSD_BLOCK_SIZE];

DRESULT disk_read(
BYTE pdrv, /* Physical drive number (0..) */
BYTE *buff, /* Data buffer to store read data */
Expand Down Expand Up @@ -142,12 +149,21 @@ DRESULT disk_read(
return RES_OK;
#else
case SDC:

// clear read buffer
memset(sd_readBuffer, 0, MMCSD_BLOCK_SIZE * count);

if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
{
return RES_NOTRDY;
if (sdcRead(&FATFS_HAL_DEVICE, sector, buff, count))
}
if (sdcRead(&FATFS_HAL_DEVICE, sector, sd_readBuffer, count))
{
return RES_ERROR;
}
// invalidate cache over read buffer to ensure that content from DMA is read
cacheBufferInvalidate(buff, MMCSD_BLOCK_SIZE * count);
cacheBufferInvalidate(sd_readBuffer, MMCSD_BLOCK_SIZE * count);
memcpy(buff, sd_readBuffer, MMCSD_BLOCK_SIZE * count);
return RES_OK;
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions targets/ChibiOS/_FatFS/fatfs_syscall.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// clang-format off

// ChibiOs version can be found at:
// ChibiOS version can be found at:
// https://github.com/ArduPilot/ChibiOS.svn/blob/master/os/various/fatfs_bindings/fatfs_syscall.c
// but currently locked to R0.14b.
// This file aligns with compatibility with R0.15+
Expand All @@ -20,7 +20,7 @@
/* Allocate/Free a Memory Block */
/*------------------------------------------------------------------------*/

void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
void *ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
Expand All @@ -31,7 +31,7 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if no


void ff_memfree (
void* mblock /* Pointer to the memory block to free (no effect if null) */
void *mblock /* Pointer to the memory block to free (no effect if null) */
)
{
// NOTE: we no longer choose to use the ChibiOs memory allocation functions.
Expand Down
6 changes: 3 additions & 3 deletions targets/ChibiOS/_include/Target_Windows_Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
// this is also mapped in the FatFS configuration
#if (HAL_USE_SDC == TRUE)

#define SD_CARD_DRIVE_INDEX "0:"
#define SD_CARD_DRIVE_INDEX "0"
#define SD_CARD_DRIVE_INDEX_NUMERIC (0)

#endif

#if (HAL_USE_SDC == TRUE) && defined(HAL_USBH_USE_MSD)

#define USB_MSD_DRIVE_INDEX "1:"
#define USB_MSD_DRIVE_INDEX "1"
#define USB_MSD_DRIVE_INDEX_NUMERIC (1)

#elif (HAL_USE_SDC == FALSE) && defined(HAL_USBH_USE_MSD)

#define USB_MSD_DRIVE_INDEX "0:"
#define USB_MSD_DRIVE_INDEX "0"
#define USB_MSD_DRIVE_INDEX_NUMERIC (0)

#endif
Expand Down