refactor: SD card SPI HAL (#3957)
* refactor: SD card SPI driver * Removed SPI and DMA StdPeriph drivers * Allow for disabling SPI DMA support * Disable SPI sdcard CRC support * Fix 2MHz timer on NV14 * Shared VS1053b driver * Fix: SPI2 uses PCLK1 * feat: new generic diskio API * More generic SD_CARD_PRESENT() * Fixes * Flush incoming block on token mismatch * Scratch buffer test * Incredible hack to re-sync sd card * fix: SDIO driver
This commit is contained in:
+11
-7
@@ -23,7 +23,6 @@
|
||||
#include <FreeRTOS/include/stream_buffer.h>
|
||||
|
||||
#include "opentx.h"
|
||||
#include "diskio.h"
|
||||
#include "timers_driver.h"
|
||||
#include "watchdog_driver.h"
|
||||
|
||||
@@ -33,6 +32,8 @@
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/module_port.h"
|
||||
#include "hal/fatfs_diskio.h"
|
||||
#include "hal/storage.h"
|
||||
|
||||
#include "tasks.h"
|
||||
#include "tasks/mixer_task.h"
|
||||
@@ -347,8 +348,9 @@ int cliReadSD(const char ** argv)
|
||||
uint32_t bytesRead = numberOfSectors * 512;
|
||||
tmr10ms_t start = get_tmr10ms();
|
||||
|
||||
auto drv = storageGetDefaultDriver();
|
||||
while (numberOfSectors > 0) {
|
||||
DRESULT res = __disk_read(0, buffer, startSector, bufferSectors);
|
||||
DRESULT res = drv->read(0, buffer, startSector, bufferSectors);
|
||||
if (res != RES_OK) {
|
||||
cliSerialPrint("disk_read error: %d, sector: %d(%d)", res, startSector, numberOfSectors);
|
||||
}
|
||||
@@ -385,10 +387,11 @@ int cliReadSD(const char ** argv)
|
||||
int cliTestSD(const char ** argv)
|
||||
{
|
||||
// Do the read test on the SD card and report back the result
|
||||
auto drv = storageGetDefaultDriver();
|
||||
|
||||
// get sector count
|
||||
uint32_t sectorCount;
|
||||
if (disk_ioctl(0, GET_SECTOR_COUNT, §orCount) != RES_OK) {
|
||||
if (drv->ioctl(0, GET_SECTOR_COUNT, §orCount) != RES_OK) {
|
||||
cliSerialPrint("Error: can't read sector count");
|
||||
return 0;
|
||||
}
|
||||
@@ -401,8 +404,9 @@ int cliTestSD(const char ** argv)
|
||||
cliSerialPrint("Not enough memory");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (uint32_t s = sectorCount - 16; s<sectorCount; ++s) {
|
||||
DRESULT res = __disk_read(0, buffer, s, 1);
|
||||
DRESULT res = drv->read(0, buffer, s, 1);
|
||||
if (res != RES_OK) {
|
||||
cliSerialPrint("sector %d read FAILED, err: %d", s, res);
|
||||
}
|
||||
@@ -421,8 +425,8 @@ int cliTestSD(const char ** argv)
|
||||
}
|
||||
|
||||
cliSerialPrint("Starting multiple sector read test, reading two sectors at the time");
|
||||
for (uint32_t s = sectorCount - 16; s<sectorCount; s+=2) {
|
||||
DRESULT res = __disk_read(0, buffer, s, 2);
|
||||
for (uint32_t s = sectorCount - 16; s < sectorCount; s += 2) {
|
||||
DRESULT res = drv->read(0, buffer, s, 2);
|
||||
if (res != RES_OK) {
|
||||
cliSerialPrint("sector %d-%d read FAILED, err: %d", s, s+1, res);
|
||||
}
|
||||
@@ -441,7 +445,7 @@ int cliTestSD(const char ** argv)
|
||||
}
|
||||
|
||||
cliSerialPrint("Starting multiple sector read test, reading 16 sectors at the time");
|
||||
DRESULT res = __disk_read(0, buffer, sectorCount-16, 16);
|
||||
DRESULT res = drv->read(0, buffer, sectorCount - 16, 16);
|
||||
if (res != RES_OK) {
|
||||
cliSerialPrint("sector %d-%d read FAILED, err: %d", sectorCount-16, sectorCount-1, res);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user