use flash for msc_disk_ram in case mcu does have enough sram

This commit is contained in:
hathach
2018-12-03 16:30:39 +07:00
parent 786b04e19d
commit b2b1704f10
2 changed files with 34 additions and 6 deletions

View File

@@ -41,6 +41,12 @@
#if CFG_TUD_MSC
// Some MCU doesn't have enough 8KB SRAM to store the whole disk
// We will use Flash as read-only disk
#if CFG_TUSB_MCU == OPT_MCU_LPC13XX
#define DISK_READONLY 1
#endif
#define README_CONTENTS \
"This is tinyusb's MassStorage Class demo.\r\n\r\n\
If you find any bugs or get any questions, feel free to file an\r\n\
@@ -52,7 +58,10 @@ enum
DISK_BLOCK_SIZE = 512
};
uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
#if DISK_READONLY
const
#endif
static uint8_t msc_disk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
{
//------------- Boot Sector -------------//
// byte_per_sector = DISK_BLOCK_SIZE; fat12_sector_num_16 = DISK_BLOCK_NUM;
@@ -99,7 +108,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
{
(void) lun;
uint8_t* addr = msc_device_ramdisk[lba] + offset;
uint8_t* addr = msc_disk[lba] + offset;
memcpy(buffer, addr, bufsize);
return bufsize;
@@ -111,8 +120,10 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
{
(void) lun;
uint8_t* addr = msc_device_ramdisk[lba] + offset;
#if !DISK_READONLY
uint8_t* addr = msc_disk[lba] + offset;
memcpy(addr, buffer, bufsize);
#endif
return bufsize;
}