utilisation de diskio.c pour répartir les commandes en fonction du support
2
.vscode/c_cpp_properties.json
vendored
@ -6,7 +6,7 @@
|
||||
"${workspaceFolder}/build/generated/pico_base",
|
||||
"${env:PICO_SDK_PATH}/src/**/include",
|
||||
"${env:PICO_SDK_PATH}/lib/**/src",
|
||||
"${workspaceFolder}/lib/source"
|
||||
"${workspaceFolder}/lib/FatFs/source"
|
||||
|
||||
],
|
||||
"myCompilerPath": "/usr/bin/arm-none-eabi-gcc"
|
||||
|
7
.vscode/settings.json
vendored
@ -4,6 +4,11 @@
|
||||
"tusb.h": "c",
|
||||
"inttypes.h": "c",
|
||||
"stdlib.h": "c",
|
||||
"cdefs.h": "c"
|
||||
"cdefs.h": "c",
|
||||
"tusb_fifo.h": "c",
|
||||
"tusb_common.h": "c",
|
||||
"diskio.h": "c",
|
||||
"ff.h": "c",
|
||||
"time.h": "c"
|
||||
}
|
||||
}
|
@ -18,14 +18,16 @@ target_sources(host_cdc_msc_hid PUBLIC
|
||||
main.c
|
||||
msc_app.c
|
||||
cdc_app.c
|
||||
lib/source/ff.c
|
||||
lib/source/ffsystem.c
|
||||
diskio_USB.c
|
||||
lib/FatFs/source/ff.c
|
||||
lib/FatFs/source/ffsystem.c
|
||||
lib/FatFs/source/diskio.c
|
||||
)
|
||||
|
||||
# Make sure TinyUSB can find tusb_config.h
|
||||
target_include_directories(host_cdc_msc_hid PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/lib/source/)
|
||||
${CMAKE_CURRENT_LIST_DIR}/lib/FatFs/source/)
|
||||
|
||||
# In addition to pico_stdlib required for common PicoSDK functionality, add dependency on tinyusb_host
|
||||
# for TinyUSB device support and tinyusb_board for the additional board support library used by the example
|
||||
|
122
diskio_USB.c
Normal file
@ -0,0 +1,122 @@
|
||||
#include "ff.h" /* Obtains integer types */
|
||||
#include "tusb.h"
|
||||
#include "diskio.h"
|
||||
|
||||
static volatile bool _disk_busy[CFG_TUH_DEVICE_MAX];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DiskIO
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static void wait_for_disk_io(BYTE pdrv)
|
||||
{
|
||||
while(_disk_busy[pdrv])
|
||||
{
|
||||
tuh_task();
|
||||
}
|
||||
}
|
||||
|
||||
static bool disk_io_complete(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||
{
|
||||
(void) dev_addr; (void) cb_data;
|
||||
_disk_busy[dev_addr-1] = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
DSTATUS USB_disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
uint8_t dev_addr = pdrv + 1;
|
||||
return tuh_msc_mounted(dev_addr) ? 0 : STA_NODISK;
|
||||
}
|
||||
|
||||
DSTATUS USB_disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
(void) pdrv;
|
||||
return 0; // nothing to do
|
||||
}
|
||||
|
||||
DRESULT USB_disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
uint8_t const dev_addr = pdrv + 1;
|
||||
uint8_t const lun = 0;
|
||||
|
||||
_disk_busy[pdrv] = true;
|
||||
tuh_msc_read10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete, 0);
|
||||
wait_for_disk_io(pdrv);
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
#if FF_FS_READONLY == 0
|
||||
|
||||
DRESULT USB_disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
uint8_t const dev_addr = pdrv + 1;
|
||||
uint8_t const lun = 0;
|
||||
|
||||
_disk_busy[pdrv] = true;
|
||||
tuh_msc_write10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete, 0);
|
||||
wait_for_disk_io(pdrv);
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DRESULT USB_disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
uint8_t const dev_addr = pdrv + 1;
|
||||
uint8_t const lun = 0;
|
||||
switch ( cmd )
|
||||
{
|
||||
case CTRL_SYNC:
|
||||
// nothing to do since we do blocking
|
||||
return RES_OK;
|
||||
|
||||
case GET_SECTOR_COUNT:
|
||||
*((DWORD*) buff) = (WORD) tuh_msc_get_block_count(dev_addr, lun);
|
||||
return RES_OK;
|
||||
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD*) buff) = (WORD) tuh_msc_get_block_size(dev_addr, lun);
|
||||
return RES_OK;
|
||||
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD*) buff) = 1; // erase block size in units of sector size
|
||||
return RES_OK;
|
||||
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
DWORD get_fattime (void){
|
||||
return
|
||||
(2025-1970) << 25 | // Année
|
||||
6 << 21 | // Mois
|
||||
7 << 16 | // jour du mois
|
||||
17 << 11 | // Heures
|
||||
29 << 5 | // Minutes
|
||||
30 << 0 // Secondes
|
||||
;
|
||||
}
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
@ -11,9 +11,7 @@
|
||||
#include "diskio.h" /* Declarations of disk functions */
|
||||
|
||||
/* Definitions of physical drive number for each drive */
|
||||
#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */
|
||||
#define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
|
||||
#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
@ -27,28 +25,16 @@ DSTATUS disk_status (
|
||||
DSTATUS stat;
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
result = RAM_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_MMC :
|
||||
result = MMC_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_USB :
|
||||
result = USB_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
if(pdrv >= DEV_SDIO_MIN && pdrv <= DEV_SDIO_MAX){
|
||||
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
if(pdrv >= DEV_USB_MIN && pdrv <= DEV_USB_MAX){
|
||||
USB_disk_status(pdrv - DEV_USB_MIN);
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
@ -64,28 +50,14 @@ DSTATUS disk_initialize (
|
||||
{
|
||||
DSTATUS stat;
|
||||
int result;
|
||||
if(pdrv >= DEV_SDIO_MIN && pdrv <= DEV_SDIO_MAX){
|
||||
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
result = RAM_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_MMC :
|
||||
result = MMC_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_USB :
|
||||
result = USB_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
if(pdrv >= DEV_USB_MIN && pdrv <= DEV_USB_MAX){
|
||||
USB_disk_initialize(pdrv - DEV_USB_MIN);
|
||||
return 0; // OK
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
@ -106,33 +78,14 @@ DRESULT disk_read (
|
||||
DRESULT res;
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
// translate the arguments here
|
||||
if(pdrv >= DEV_SDIO_MIN && pdrv <= DEV_SDIO_MAX){
|
||||
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
result = RAM_disk_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_MMC :
|
||||
// translate the arguments here
|
||||
|
||||
result = MMC_disk_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_USB :
|
||||
// translate the arguments here
|
||||
|
||||
result = USB_disk_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
if(pdrv >= DEV_USB_MIN && pdrv <= DEV_USB_MAX){
|
||||
USB_disk_read(pdrv - DEV_USB_MIN, buff, sector, count);
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
@ -156,35 +109,16 @@ DRESULT disk_write (
|
||||
DRESULT res;
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
// translate the arguments here
|
||||
|
||||
result = RAM_disk_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_MMC :
|
||||
// translate the arguments here
|
||||
|
||||
result = MMC_disk_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_USB :
|
||||
// translate the arguments here
|
||||
|
||||
result = USB_disk_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
if(pdrv >= DEV_SDIO_MIN && pdrv <= DEV_SDIO_MAX){
|
||||
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
if(pdrv >= DEV_USB_MIN && pdrv <= DEV_USB_MAX){
|
||||
result = USB_disk_write(pdrv - DEV_USB_MIN, buff, sector, count);
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
@ -204,24 +138,15 @@ DRESULT disk_ioctl (
|
||||
DRESULT res;
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
|
||||
// Process of the command for the RAM drive
|
||||
if(pdrv >= DEV_SDIO_MIN && pdrv <= DEV_SDIO_MAX){
|
||||
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_MMC :
|
||||
|
||||
// Process of the command for the MMC/SD card
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_USB :
|
||||
|
||||
// Process of the command the USB drive
|
||||
|
||||
return res;
|
||||
if(pdrv >= DEV_USB_MIN && pdrv <= DEV_USB_MAX){
|
||||
USB_disk_ioctl(pdrv - DEV_USB_MIN, cmd, buff);
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
@ -32,6 +32,12 @@ DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
DSTATUS USB_disk_initialize (BYTE pdrv);
|
||||
DSTATUS USB_disk_status (BYTE pdrv);
|
||||
DRESULT USB_disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT USB_disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT USB_disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
@ -22,6 +22,11 @@
|
||||
#ifndef FF_DEFINED
|
||||
#define FF_DEFINED 5380 /* Revision ID */
|
||||
|
||||
#define DEV_SDIO_MIN 0
|
||||
#define DEV_SDIO_MAX 1
|
||||
#define DEV_USB_MIN 2
|
||||
#define DEV_USB_MAX 9
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
117
msc_app.c
@ -36,7 +36,6 @@ static scsi_inquiry_resp_t inquiry_resp;
|
||||
|
||||
//------------- Elm Chan FatFS -------------//
|
||||
static FATFS fatfs[CFG_TUH_DEVICE_MAX]; // for simplicity only support 1 LUN per device
|
||||
static volatile bool _disk_busy[CFG_TUH_DEVICE_MAX];
|
||||
|
||||
bool file_accessible = false;
|
||||
FIL fp;
|
||||
@ -161,119 +160,3 @@ void tuh_msc_umount_cb(uint8_t dev_addr)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DiskIO
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static void wait_for_disk_io(BYTE pdrv)
|
||||
{
|
||||
while(_disk_busy[pdrv])
|
||||
{
|
||||
tuh_task();
|
||||
}
|
||||
}
|
||||
|
||||
static bool disk_io_complete(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||
{
|
||||
(void) dev_addr; (void) cb_data;
|
||||
_disk_busy[dev_addr-1] = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
uint8_t dev_addr = pdrv + 1;
|
||||
return tuh_msc_mounted(dev_addr) ? 0 : STA_NODISK;
|
||||
}
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
(void) pdrv;
|
||||
return 0; // nothing to do
|
||||
}
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
uint8_t const dev_addr = pdrv + 1;
|
||||
uint8_t const lun = 0;
|
||||
|
||||
_disk_busy[pdrv] = true;
|
||||
tuh_msc_read10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete, 0);
|
||||
wait_for_disk_io(pdrv);
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
#if FF_FS_READONLY == 0
|
||||
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
uint8_t const dev_addr = pdrv + 1;
|
||||
uint8_t const lun = 0;
|
||||
|
||||
_disk_busy[pdrv] = true;
|
||||
tuh_msc_write10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete, 0);
|
||||
wait_for_disk_io(pdrv);
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
uint8_t const dev_addr = pdrv + 1;
|
||||
uint8_t const lun = 0;
|
||||
switch ( cmd )
|
||||
{
|
||||
case CTRL_SYNC:
|
||||
// nothing to do since we do blocking
|
||||
return RES_OK;
|
||||
|
||||
case GET_SECTOR_COUNT:
|
||||
*((DWORD*) buff) = (WORD) tuh_msc_get_block_count(dev_addr, lun);
|
||||
return RES_OK;
|
||||
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD*) buff) = (WORD) tuh_msc_get_block_size(dev_addr, lun);
|
||||
return RES_OK;
|
||||
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD*) buff) = 1; // erase block size in units of sector size
|
||||
return RES_OK;
|
||||
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
DWORD get_fattime (void){
|
||||
return
|
||||
(2025-1970) << 25 | // Année
|
||||
6 << 21 | // Mois
|
||||
7 << 16 | // jour du mois
|
||||
17 << 11 | // Heures
|
||||
29 << 5 | // Minutes
|
||||
30 << 0 // Secondes
|
||||
;
|
||||
}
|