2 * At32 MSC scsi interface
3 * FLASH emfat reads and writes are implemented
4 * Other storage read and write services, such as sd, are not supported
13 #include "at32_msc_diskio.h"
16 #include "common/utils.h"
17 #include "msc_bot_scsi.h"
18 #include "drivers/usb_msc.h"
22 #define STORAGE_LUN_NBR 1
23 #define SCSI_BLOCK_SIZE 512
25 static const uint8_t scsi_inquiry
[MSC_SUPPORT_MAX_LUN
][SCSI_INQUIRY_DATA_LENGTH
] =
29 0x00, /* peripheral device type (direct-access device) */
30 0x80, /* removable media bit */
31 0x00, /* ansi version, ecma version, iso version */
32 0x01, /* respond data format */
33 SCSI_INQUIRY_DATA_LENGTH
- 5, /* additional length */
34 0x00, 0x00, 0x00, /* reserved */
35 'I', 'N', 'A', 'V', ' ', 'F', 'C', ' ', // Manufacturer : 8 bytes
36 'O', 'n', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes
37 'F', 'l', 'a', 's', 'h', ' ', ' ', ' ', //
38 ' ', ' ', ' ' ,' ', // Version : 4 Bytes
42 usb_sts_type
msc_disk_capacity(uint8_t lun
, uint32_t *block_num
, uint32_t *block_size
)
45 *block_size
= SCSI_BLOCK_SIZE
;
46 *block_num
= emfat
.disk_sectors
;
52 if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun ,
54 hmsc->scsi_blk_addr / hmsc->scsi_blk_size,
55 len / hmsc->scsi_blk_size) < 0)
57 static int8_t STORAGE_Read(
58 uint8_t lun, // logical unit number
59 uint8_t *buf, // Pointer to the buffer to save data
60 uint32_t blk_addr, // address of 1st block to be read
61 uint16_t blk_len) // nmber of blocks to be read
65 emfat_read(&emfat, buf, blk_addr, blk_len);
70 usb_sts_type
msc_disk_read(
71 uint8_t lun
, // logical unit number
72 uint32_t blk_addr
, // address of 1st block to be read
73 uint8_t *buf
, // Pointer to the buffer to save data
74 uint32_t blk_len
) // nmber of blocks to be read
78 emfat_read(&emfat
, buf
, blk_addr
/SCSI_BLOCK_SIZE
, blk_len
/SCSI_BLOCK_SIZE
);
82 usb_sts_type
msc_disk_write(uint8_t lun
,
97 * @brief get disk inquiry
98 * @param lun: logical units number
99 * @retval inquiry string
101 uint8_t * get_inquiry(uint8_t lun
)
103 if(lun
< MSC_SUPPORT_MAX_LUN
)
104 return (uint8_t *)scsi_inquiry
[lun
];