[X9E] Massstorage OK?

This commit is contained in:
Bertrand Songis
2016-07-29 20:53:01 +02:00
parent e5bbf6766b
commit 85f3bd4ed0
10 changed files with 130 additions and 94 deletions
+1 -1
View File
@@ -22,9 +22,9 @@
#define _DISK_CACHE_H_
#include "diskio.h"
#include "sdio_sd.h"
// tunable parameters
#define BLOCK_SIZE 512 // sector Size in Bytes
#define DISK_CACHE_BLOCKS_NUM 8 // no cache blocks
#define DISK_CACHE_BLOCK_SECTORS 16 // no sectors
@@ -37,8 +37,6 @@ enum MassstorageLuns {
STORAGE_LUN_NBR
};
#define BLOCKSIZE 512
/* USB Mass storage Standard Inquiry Data */
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 (lun == STORAGE_EEPROM_LUN) {
*block_size = BLOCKSIZE;
*block_num = 3 + EESIZE/BLOCKSIZE + FLASHSIZE/BLOCKSIZE;
*block_size = BLOCK_SIZE;
*block_num = 3 + EESIZE/BLOCK_SIZE + FLASHSIZE/BLOCK_SIZE;
return 0;
}
#endif
@@ -156,7 +154,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
if (!SD_CARD_PRESENT())
return -1;
*block_size = BLOCKSIZE;
*block_size = BLOCK_SIZE;
static DWORD sector_count = 0;
if (sector_count == 0) {
@@ -273,7 +271,7 @@ int8_t STORAGE_GetMaxLun (void)
/**
* FAT12 boot sector partition.
*/
const char g_FATboot[BLOCKSIZE] =
const char g_FATboot[BLOCK_SIZE] =
{
0xeb, 0x3c, 0x90, // Jump instruction.
0x39, 0x58, 0x20, 0x54, 0x45, 0x41, 0x4D, 0x00, // OEM Name
@@ -283,7 +281,7 @@ const char g_FATboot[BLOCKSIZE] =
0x01, // Number of FATs
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
0x01, 0x00, // Sectors per FAT table
0x20, 0x00, // Sectors per track
@@ -332,7 +330,7 @@ const char g_FATboot[BLOCKSIZE] =
};
#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,
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,
};
#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,
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,
0xA302,
0x3D55,
0x0002 + (EESIZE/BLOCKSIZE)/8,
0x0002 + (EESIZE/BLOCK_SIZE)/8,
FLASHSIZE
},
{
@@ -682,26 +680,26 @@ int32_t fat12Read(uint8_t * buffer, uint16_t sector, uint16_t count)
{
while(count) {
if (sector == 0) {
memcpy(buffer, g_FATboot, BLOCKSIZE ) ;
memcpy(buffer, g_FATboot, BLOCK_SIZE ) ;
}
else if (sector == 1/*Reserved sector count*/) {
// FAT table.
memcpy(buffer, g_FAT, BLOCKSIZE);
memcpy(buffer, g_FAT, BLOCK_SIZE);
}
else if (sector == 2) {
memcpy(buffer, g_DIRroot, BLOCKSIZE ) ;
memcpy(buffer, g_DIRroot, BLOCK_SIZE ) ;
}
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
eepromReadBlock(buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE);
else if (sector < 3 + (EESIZE/BLOCK_SIZE)) {
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;
address = sector - 3 - (EESIZE/BLOCKSIZE);
address *= BLOCKSIZE;
address = sector - 3 - (EESIZE/BLOCK_SIZE);
address *= BLOCK_SIZE;
address += FIRMWARE_ADDRESS;
memcpy(buffer, (uint8_t *)address, BLOCKSIZE);
memcpy(buffer, (uint8_t *)address, BLOCK_SIZE);
}
buffer += BLOCKSIZE ;
buffer += BLOCK_SIZE ;
sector++ ;
count-- ;
}
@@ -723,7 +721,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
if (sector < 3) {
// reserved, read-only
}
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
else if (sector < 3 + (EESIZE/BLOCK_SIZE)) {
// eeprom
while (count) {
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;
}
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++;
count--;
if (sector-3 >= (EESIZE/BLOCKSIZE)) {
if (sector-3 >= (EESIZE/BLOCK_SIZE)) {
TRACE("EEPROM end written at sector %d", sector-1);
operation = FATWRITE_NONE;
}
}
}
else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) {
else if (sector < 3 + (EESIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
// firmware
uint32_t address;
address = sector - 3 - (EESIZE/BLOCKSIZE);
address *= BLOCKSIZE;
address = sector - 3 - (EESIZE/BLOCK_SIZE);
address *= BLOCK_SIZE;
address += FIRMWARE_ADDRESS;
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 && isFirmwareStart(buffer)) {
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++;
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);
operation = FATWRITE_NONE;
}
+3 -5
View File
@@ -29,8 +29,6 @@
#include "opentx.h"
#include "sdio_sd.h"
#define BLOCK_SIZE 512 /* Block Size in Bytes */
/*-----------------------------------------------------------------------*/
/* Lock / unlock functions */
/*-----------------------------------------------------------------------*/
@@ -134,9 +132,9 @@ DRESULT __disk_read (
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);
while(count--) {
while (count--) {
res = disk_read(drv, (BYTE *)scratch, sector++, 1);
if (res != RES_OK) {
@@ -211,7 +209,7 @@ DRESULT __disk_write (
if (SD_Detect() != SD_PRESENT)
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);
while(count--) {
memcpy(scratch, buff, BLOCK_SIZE);
+2
View File
@@ -24,6 +24,8 @@
#include "board.h"
#define BLOCK_SIZE 512 /* Block Size in Bytes */
#ifdef __cplusplus
extern "C" {
#endif
+1 -2
View File
@@ -34,7 +34,6 @@
/// Number of SD Slots
#define NUM_SD_SLOTS 1
#define SD_BLOCK_SIZE 512
//------------------------------------------------------------------------------
/// Checks if the device is write protected.
@@ -224,7 +223,7 @@ unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
media->handler = 0;
media->flush = 0;
media->blockSize = SD_BLOCK_SIZE;
media->blockSize = BLOCK_SIZE;
media->baseAddress = 0;
media->size = SD_GET_BLOCKNR();
+26 -24
View File
@@ -1,27 +1,27 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
// TODO merge this file with board_sky9x.h
#ifndef _BOARD_H_
#define _BOARD_H_
#ifndef _BOARD_H_
#define _BOARD_H_
#include <stdint.h>
@@ -484,7 +484,9 @@
///// MCI Card Detect pin.
#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
#define SD_ST_ERR -1
@@ -634,4 +636,4 @@ struct t_serial_tx
volatile uint16_t ready ;
};
#endif // _BOARD_H_
#endif // _BOARD_H_
+21 -27
View File
@@ -1,24 +1,24 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "../opentx.h"
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
#ifndef SIMU
@@ -27,12 +27,6 @@ extern "C" {
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. */
unsigned char msdBuffer[MSD_BUFFER_SIZE];
@@ -33,7 +33,7 @@
#include "../../../usb/device/massstorage/MSDLun.h"
#include "board_lowlevel.h"
#include "../../../usb/device/core/USBD.h"
#include "debug.h"
@@ -42,7 +42,7 @@
//------------------------------------------------------------------------------
/// Default LUN block size in bytes
#define DEFAULT_LUN_BLOCK_SIZE 512
#define DEFAULT_LUN_BLOCK_SIZE BLOCK_SIZE
//------------------------------------------------------------------------------
// Internal variables
+3 -2
View File
@@ -157,6 +157,7 @@ void delay_ms(uint32_t ms);
void getCPUUniqueID(char * s);
// SD driver
#define BLOCK_SIZE 512 /* Block Size in Bytes */
#if !defined(SIMU) || defined(SIMU_DISKIO)
uint32_t sdIsHC(void);
uint32_t sdGetSpeed(void);
@@ -164,8 +165,8 @@ void getCPUUniqueID(char * s);
#define SD_GET_SPEED() (sdGetSpeed())
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
#else
#define SD_IS_HC() (0)
#define SD_GET_SPEED() (0)
#define SD_IS_HC() (0)
#define SD_GET_SPEED() (0)
#endif
#if defined(SIMU)
+44 -2
View File
@@ -628,12 +628,35 @@ DSTATUS disk_status (
}
#if defined(STM32F4) && !defined(BOOT)
DWORD scratch[BLOCK_SIZE / 4] __DMA;
#endif
/*-----------------------------------------------------------------------*/
/* 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 (count == 1) { /* Single block read */
@@ -686,8 +709,27 @@ DRESULT disk_read (
/* 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 (count == 1) { /* Single block write */