[X9E] Massstorage OK?
This commit is contained in:
@@ -22,9 +22,9 @@
|
|||||||
#define _DISK_CACHE_H_
|
#define _DISK_CACHE_H_
|
||||||
|
|
||||||
#include "diskio.h"
|
#include "diskio.h"
|
||||||
|
#include "sdio_sd.h"
|
||||||
|
|
||||||
// tunable parameters
|
// tunable parameters
|
||||||
#define BLOCK_SIZE 512 // sector Size in Bytes
|
|
||||||
#define DISK_CACHE_BLOCKS_NUM 8 // no cache blocks
|
#define DISK_CACHE_BLOCKS_NUM 8 // no cache blocks
|
||||||
#define DISK_CACHE_BLOCK_SECTORS 16 // no sectors
|
#define DISK_CACHE_BLOCK_SECTORS 16 // no sectors
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ enum MassstorageLuns {
|
|||||||
STORAGE_LUN_NBR
|
STORAGE_LUN_NBR
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BLOCKSIZE 512
|
|
||||||
|
|
||||||
/* USB Mass storage Standard Inquiry Data */
|
/* USB Mass storage Standard Inquiry Data */
|
||||||
const unsigned char STORAGE_Inquirydata[] = {//36
|
const unsigned char STORAGE_Inquirydata[] = {//36
|
||||||
|
|
||||||
@@ -147,8 +145,8 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
|
|||||||
{
|
{
|
||||||
#if defined(EEPROM) && defined(BOOT)
|
#if defined(EEPROM) && defined(BOOT)
|
||||||
if (lun == STORAGE_EEPROM_LUN) {
|
if (lun == STORAGE_EEPROM_LUN) {
|
||||||
*block_size = BLOCKSIZE;
|
*block_size = BLOCK_SIZE;
|
||||||
*block_num = 3 + EESIZE/BLOCKSIZE + FLASHSIZE/BLOCKSIZE;
|
*block_num = 3 + EESIZE/BLOCK_SIZE + FLASHSIZE/BLOCK_SIZE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -156,7 +154,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
|
|||||||
if (!SD_CARD_PRESENT())
|
if (!SD_CARD_PRESENT())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*block_size = BLOCKSIZE;
|
*block_size = BLOCK_SIZE;
|
||||||
|
|
||||||
static DWORD sector_count = 0;
|
static DWORD sector_count = 0;
|
||||||
if (sector_count == 0) {
|
if (sector_count == 0) {
|
||||||
@@ -273,7 +271,7 @@ int8_t STORAGE_GetMaxLun (void)
|
|||||||
/**
|
/**
|
||||||
* FAT12 boot sector partition.
|
* FAT12 boot sector partition.
|
||||||
*/
|
*/
|
||||||
const char g_FATboot[BLOCKSIZE] =
|
const char g_FATboot[BLOCK_SIZE] =
|
||||||
{
|
{
|
||||||
0xeb, 0x3c, 0x90, // Jump instruction.
|
0xeb, 0x3c, 0x90, // Jump instruction.
|
||||||
0x39, 0x58, 0x20, 0x54, 0x45, 0x41, 0x4D, 0x00, // OEM Name
|
0x39, 0x58, 0x20, 0x54, 0x45, 0x41, 0x4D, 0x00, // OEM Name
|
||||||
@@ -283,7 +281,7 @@ const char g_FATboot[BLOCKSIZE] =
|
|||||||
|
|
||||||
0x01, // Number of FATs
|
0x01, // Number of FATs
|
||||||
0x10, 0x00, // Number of root directory entries
|
0x10, 0x00, // Number of root directory entries
|
||||||
3+(EESIZE/BLOCKSIZE), (FLASHSIZE/BLOCKSIZE)>>8, // Total sectors
|
3+(EESIZE/BLOCK_SIZE), (FLASHSIZE/BLOCK_SIZE)>>8, // Total sectors
|
||||||
0xf8, // Media descriptor
|
0xf8, // Media descriptor
|
||||||
0x01, 0x00, // Sectors per FAT table
|
0x01, 0x00, // Sectors per FAT table
|
||||||
0x20, 0x00, // Sectors per track
|
0x20, 0x00, // Sectors per track
|
||||||
@@ -332,7 +330,7 @@ const char g_FATboot[BLOCKSIZE] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined(REV4a)
|
#if defined(REV4a)
|
||||||
const char g_FAT[BLOCKSIZE] =
|
const char g_FAT[BLOCK_SIZE] =
|
||||||
{
|
{
|
||||||
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B,
|
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B,
|
||||||
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0xF0, 0xFF, 0x13, 0x40, 0x01, 0x15, 0x60,
|
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0xF0, 0xFF, 0x13, 0x40, 0x01, 0x15, 0x60,
|
||||||
@@ -368,7 +366,7 @@ const char g_FAT[BLOCKSIZE] =
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
const char g_FAT[BLOCKSIZE] =
|
const char g_FAT[BLOCK_SIZE] =
|
||||||
{
|
{
|
||||||
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xF0, 0xFF, 0x0B,
|
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xF0, 0xFF, 0x0B,
|
||||||
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60,
|
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60,
|
||||||
@@ -477,7 +475,7 @@ const FATDirEntry_t g_DIRroot[16] =
|
|||||||
0x0000,
|
0x0000,
|
||||||
0xA302,
|
0xA302,
|
||||||
0x3D55,
|
0x3D55,
|
||||||
0x0002 + (EESIZE/BLOCKSIZE)/8,
|
0x0002 + (EESIZE/BLOCK_SIZE)/8,
|
||||||
FLASHSIZE
|
FLASHSIZE
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -682,26 +680,26 @@ int32_t fat12Read(uint8_t * buffer, uint16_t sector, uint16_t count)
|
|||||||
{
|
{
|
||||||
while(count) {
|
while(count) {
|
||||||
if (sector == 0) {
|
if (sector == 0) {
|
||||||
memcpy(buffer, g_FATboot, BLOCKSIZE ) ;
|
memcpy(buffer, g_FATboot, BLOCK_SIZE ) ;
|
||||||
}
|
}
|
||||||
else if (sector == 1/*Reserved sector count*/) {
|
else if (sector == 1/*Reserved sector count*/) {
|
||||||
// FAT table.
|
// FAT table.
|
||||||
memcpy(buffer, g_FAT, BLOCKSIZE);
|
memcpy(buffer, g_FAT, BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
else if (sector == 2) {
|
else if (sector == 2) {
|
||||||
memcpy(buffer, g_DIRroot, BLOCKSIZE ) ;
|
memcpy(buffer, g_DIRroot, BLOCK_SIZE ) ;
|
||||||
}
|
}
|
||||||
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
|
else if (sector < 3 + (EESIZE/BLOCK_SIZE)) {
|
||||||
eepromReadBlock(buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE);
|
eepromReadBlock(buffer, (sector-3)*BLOCK_SIZE, BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) {
|
else if (sector < 3 + (EESIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
|
||||||
uint32_t address;
|
uint32_t address;
|
||||||
address = sector - 3 - (EESIZE/BLOCKSIZE);
|
address = sector - 3 - (EESIZE/BLOCK_SIZE);
|
||||||
address *= BLOCKSIZE;
|
address *= BLOCK_SIZE;
|
||||||
address += FIRMWARE_ADDRESS;
|
address += FIRMWARE_ADDRESS;
|
||||||
memcpy(buffer, (uint8_t *)address, BLOCKSIZE);
|
memcpy(buffer, (uint8_t *)address, BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
buffer += BLOCKSIZE ;
|
buffer += BLOCK_SIZE ;
|
||||||
sector++ ;
|
sector++ ;
|
||||||
count-- ;
|
count-- ;
|
||||||
}
|
}
|
||||||
@@ -723,7 +721,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
|
|||||||
if (sector < 3) {
|
if (sector < 3) {
|
||||||
// reserved, read-only
|
// reserved, read-only
|
||||||
}
|
}
|
||||||
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
|
else if (sector < 3 + (EESIZE/BLOCK_SIZE)) {
|
||||||
// eeprom
|
// eeprom
|
||||||
while (count) {
|
while (count) {
|
||||||
if (operation == FATWRITE_NONE && isEepromStart(buffer)) {
|
if (operation == FATWRITE_NONE && isEepromStart(buffer)) {
|
||||||
@@ -731,25 +729,25 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
|
|||||||
operation = FATWRITE_EEPROM;
|
operation = FATWRITE_EEPROM;
|
||||||
}
|
}
|
||||||
if (operation == FATWRITE_EEPROM) {
|
if (operation == FATWRITE_EEPROM) {
|
||||||
eepromWriteBlock((uint8_t *)buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE);
|
eepromWriteBlock((uint8_t *)buffer, (sector-3)*BLOCK_SIZE, BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
buffer += BLOCKSIZE;
|
buffer += BLOCK_SIZE;
|
||||||
sector++;
|
sector++;
|
||||||
count--;
|
count--;
|
||||||
if (sector-3 >= (EESIZE/BLOCKSIZE)) {
|
if (sector-3 >= (EESIZE/BLOCK_SIZE)) {
|
||||||
TRACE("EEPROM end written at sector %d", sector-1);
|
TRACE("EEPROM end written at sector %d", sector-1);
|
||||||
operation = FATWRITE_NONE;
|
operation = FATWRITE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) {
|
else if (sector < 3 + (EESIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
|
||||||
// firmware
|
// firmware
|
||||||
uint32_t address;
|
uint32_t address;
|
||||||
address = sector - 3 - (EESIZE/BLOCKSIZE);
|
address = sector - 3 - (EESIZE/BLOCK_SIZE);
|
||||||
address *= BLOCKSIZE;
|
address *= BLOCK_SIZE;
|
||||||
address += FIRMWARE_ADDRESS;
|
address += FIRMWARE_ADDRESS;
|
||||||
while (count) {
|
while (count) {
|
||||||
for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) {
|
for (uint32_t i=0; i<BLOCK_SIZE/FLASH_PAGESIZE; i++) {
|
||||||
if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) {
|
if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) {
|
||||||
if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE && isFirmwareStart(buffer)) {
|
if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE && isFirmwareStart(buffer)) {
|
||||||
TRACE("FIRMWARE start found in sector %d", sector);
|
TRACE("FIRMWARE start found in sector %d", sector);
|
||||||
@@ -764,7 +762,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
|
|||||||
}
|
}
|
||||||
sector++;
|
sector++;
|
||||||
count--;
|
count--;
|
||||||
if (sector-3-(EESIZE/BLOCKSIZE) >= (FLASHSIZE/BLOCKSIZE)) {
|
if (sector-3-(EESIZE/BLOCK_SIZE) >= (FLASHSIZE/BLOCK_SIZE)) {
|
||||||
TRACE("FIRMWARE end written at sector %d", sector-1);
|
TRACE("FIRMWARE end written at sector %d", sector-1);
|
||||||
operation = FATWRITE_NONE;
|
operation = FATWRITE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "sdio_sd.h"
|
#include "sdio_sd.h"
|
||||||
|
|
||||||
#define BLOCK_SIZE 512 /* Block Size in Bytes */
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* Lock / unlock functions */
|
/* Lock / unlock functions */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
@@ -134,9 +132,9 @@ DRESULT __disk_read (
|
|||||||
return RES_NOTRDY;
|
return RES_NOTRDY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((DWORD)buff < 0x20000000 /*|| (DWORD)buff >= 0x20030000*/ || ((DWORD)buff & 3)) {
|
if ((DWORD)buff < 0x20000000 || ((DWORD)buff & 3)) {
|
||||||
TRACE("disk_read bad alignment (%p)", buff);
|
TRACE("disk_read bad alignment (%p)", buff);
|
||||||
while(count--) {
|
while (count--) {
|
||||||
res = disk_read(drv, (BYTE *)scratch, sector++, 1);
|
res = disk_read(drv, (BYTE *)scratch, sector++, 1);
|
||||||
|
|
||||||
if (res != RES_OK) {
|
if (res != RES_OK) {
|
||||||
@@ -211,7 +209,7 @@ DRESULT __disk_write (
|
|||||||
if (SD_Detect() != SD_PRESENT)
|
if (SD_Detect() != SD_PRESENT)
|
||||||
return(RES_NOTRDY);
|
return(RES_NOTRDY);
|
||||||
|
|
||||||
if ((DWORD)buff < 0x20000000 /*|| (DWORD)buff >= 0x20030000*/ || ((DWORD)buff & 3)) {
|
if ((DWORD)buff < 0x20000000 || ((DWORD)buff & 3)) {
|
||||||
TRACE("disk_write bad alignment (%p)", buff);
|
TRACE("disk_write bad alignment (%p)", buff);
|
||||||
while(count--) {
|
while(count--) {
|
||||||
memcpy(scratch, buff, BLOCK_SIZE);
|
memcpy(scratch, buff, BLOCK_SIZE);
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
|
#define BLOCK_SIZE 512 /* Block Size in Bytes */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
/// Number of SD Slots
|
/// Number of SD Slots
|
||||||
#define NUM_SD_SLOTS 1
|
#define NUM_SD_SLOTS 1
|
||||||
#define SD_BLOCK_SIZE 512
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/// Checks if the device is write protected.
|
/// Checks if the device is write protected.
|
||||||
@@ -224,7 +223,7 @@ unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
|
|||||||
media->handler = 0;
|
media->handler = 0;
|
||||||
media->flush = 0;
|
media->flush = 0;
|
||||||
|
|
||||||
media->blockSize = SD_BLOCK_SIZE;
|
media->blockSize = BLOCK_SIZE;
|
||||||
media->baseAddress = 0;
|
media->baseAddress = 0;
|
||||||
|
|
||||||
media->size = SD_GET_BLOCKNR();
|
media->size = SD_GET_BLOCKNR();
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) OpenTX
|
* Copyright (C) OpenTX
|
||||||
*
|
*
|
||||||
* Based on code named
|
* Based on code named
|
||||||
* th9x - http://code.google.com/p/th9x
|
* th9x - http://code.google.com/p/th9x
|
||||||
* er9x - http://code.google.com/p/er9x
|
* er9x - http://code.google.com/p/er9x
|
||||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
*
|
*
|
||||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
* published by the Free Software Foundation.
|
* published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO merge this file with board_sky9x.h
|
// TODO merge this file with board_sky9x.h
|
||||||
|
|
||||||
#ifndef _BOARD_H_
|
#ifndef _BOARD_H_
|
||||||
#define _BOARD_H_
|
#define _BOARD_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -484,7 +484,9 @@
|
|||||||
///// MCI Card Detect pin.
|
///// MCI Card Detect pin.
|
||||||
#define BOARD_SD_PIN_CD PIN_MCI_CD
|
#define BOARD_SD_PIN_CD PIN_MCI_CD
|
||||||
|
|
||||||
#define SD_CARD_PRESENT() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 )
|
#define BLOCK_SIZE 512
|
||||||
|
#define MSD_BUFFER_SIZE (12*BLOCK_SIZE) // Size of the MSD IO buffer in bytes (6K, more the better)
|
||||||
|
#define SD_CARD_PRESENT() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 )
|
||||||
|
|
||||||
// States for initialising card
|
// States for initialising card
|
||||||
#define SD_ST_ERR -1
|
#define SD_ST_ERR -1
|
||||||
@@ -634,4 +636,4 @@ struct t_serial_tx
|
|||||||
volatile uint16_t ready ;
|
volatile uint16_t ready ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _BOARD_H_
|
#endif // _BOARD_H_
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) OpenTX
|
* Copyright (C) OpenTX
|
||||||
*
|
*
|
||||||
* Based on code named
|
* Based on code named
|
||||||
* th9x - http://code.google.com/p/th9x
|
* th9x - http://code.google.com/p/th9x
|
||||||
* er9x - http://code.google.com/p/er9x
|
* er9x - http://code.google.com/p/er9x
|
||||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
*
|
*
|
||||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
* published by the Free Software Foundation.
|
* published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
#ifndef SIMU
|
#ifndef SIMU
|
||||||
|
|
||||||
@@ -27,12 +27,6 @@ extern "C" {
|
|||||||
extern unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID);
|
extern unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Size of one block in bytes. */
|
|
||||||
#define BLOCK_SIZE 512
|
|
||||||
|
|
||||||
/** Size of the MSD IO buffer in bytes (6K, more the better). */
|
|
||||||
#define MSD_BUFFER_SIZE (12*BLOCK_SIZE)
|
|
||||||
|
|
||||||
/** LUN read/write buffer. */
|
/** LUN read/write buffer. */
|
||||||
unsigned char msdBuffer[MSD_BUFFER_SIZE];
|
unsigned char msdBuffer[MSD_BUFFER_SIZE];
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||||
|
#include "board_lowlevel.h"
|
||||||
#include "../../../usb/device/core/USBD.h"
|
#include "../../../usb/device/core/USBD.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Default LUN block size in bytes
|
/// Default LUN block size in bytes
|
||||||
#define DEFAULT_LUN_BLOCK_SIZE 512
|
#define DEFAULT_LUN_BLOCK_SIZE BLOCK_SIZE
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Internal variables
|
// Internal variables
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ void delay_ms(uint32_t ms);
|
|||||||
void getCPUUniqueID(char * s);
|
void getCPUUniqueID(char * s);
|
||||||
|
|
||||||
// SD driver
|
// SD driver
|
||||||
|
#define BLOCK_SIZE 512 /* Block Size in Bytes */
|
||||||
#if !defined(SIMU) || defined(SIMU_DISKIO)
|
#if !defined(SIMU) || defined(SIMU_DISKIO)
|
||||||
uint32_t sdIsHC(void);
|
uint32_t sdIsHC(void);
|
||||||
uint32_t sdGetSpeed(void);
|
uint32_t sdGetSpeed(void);
|
||||||
@@ -164,8 +165,8 @@ void getCPUUniqueID(char * s);
|
|||||||
#define SD_GET_SPEED() (sdGetSpeed())
|
#define SD_GET_SPEED() (sdGetSpeed())
|
||||||
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
|
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
|
||||||
#else
|
#else
|
||||||
#define SD_IS_HC() (0)
|
#define SD_IS_HC() (0)
|
||||||
#define SD_GET_SPEED() (0)
|
#define SD_GET_SPEED() (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SIMU)
|
#if defined(SIMU)
|
||||||
|
|||||||
@@ -628,12 +628,35 @@ DSTATUS disk_status (
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(STM32F4) && !defined(BOOT)
|
||||||
|
DWORD scratch[BLOCK_SIZE / 4] __DMA;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* Read Sector(s) */
|
/* Read Sector(s) */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
int8_t SD_ReadSectors(uint8_t *buff, uint32_t sector, uint32_t count)
|
int8_t SD_ReadSectors(uint8_t * buff, uint32_t sector, uint32_t count)
|
||||||
{
|
{
|
||||||
|
#if defined(STM32F4) && !defined(BOOT)
|
||||||
|
if ((DWORD)buff < 0x20000000 || ((DWORD)buff & 3)) {
|
||||||
|
TRACE("disk_read bad alignment (%p)", buff);
|
||||||
|
while (count--) {
|
||||||
|
int8_t res = SD_ReadSectors((BYTE *)scratch, sector++, 1);
|
||||||
|
|
||||||
|
if (res != 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(buff, scratch, BLOCK_SIZE);
|
||||||
|
|
||||||
|
buff += BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
|
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
|
||||||
|
|
||||||
if (count == 1) { /* Single block read */
|
if (count == 1) { /* Single block read */
|
||||||
@@ -686,8 +709,27 @@ DRESULT disk_read (
|
|||||||
/* Write Sector(s) */
|
/* Write Sector(s) */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
int8_t SD_WriteSectors(const uint8_t *buff, uint32_t sector, uint32_t count)
|
int8_t SD_WriteSectors(const uint8_t * buff, uint32_t sector, uint32_t count)
|
||||||
{
|
{
|
||||||
|
#if defined(STM32F4) && !defined(BOOT)
|
||||||
|
if ((DWORD)buff < 0x20000000 || ((DWORD)buff & 3)) {
|
||||||
|
TRACE("disk_write bad alignment (%p)", buff);
|
||||||
|
while (count--) {
|
||||||
|
memcpy(scratch, buff, BLOCK_SIZE);
|
||||||
|
|
||||||
|
int8_t res = SD_WriteSectors((const uint8_t *)scratch, sector++, 1);
|
||||||
|
|
||||||
|
if (res != 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
buff += BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
|
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
|
||||||
|
|
||||||
if (count == 1) { /* Single block write */
|
if (count == 1) { /* Single block write */
|
||||||
|
|||||||
Reference in New Issue
Block a user