29#if CFG_TUH_ENABLED && CFG_TUH_MSC
37#ifndef CFG_TUH_MSC_LOG_LEVEL
38 #define CFG_TUH_MSC_LOG_LEVEL CFG_TUH_LOG_LEVEL
41#define TU_LOG_DRV(...) TU_LOG(CFG_TUH_MSC_LOG_LEVEL, __VA_ARGS__)
66 } capacity[CFG_TUH_MSC_MAXLUN];
82CFG_TUH_MEM_SECTION CFG_TUH_MEM_ALIGN
125 cbw->
tag = 0x54555342;
236 .lba = tu_htonl(lba),
237 .block_count = tu_htons(block_count)
258 .lba = tu_htonl(lba),
259 .block_count = tu_htons(block_count)
277 .wIndex = p_msc->itf_num,
280 TU_ASSERT( usbh_control_xfer(
dev_addr, &new_request, NULL ) );
298 TU_VERIFY(
dev_addr <= CFG_TUH_DEVICE_MAX,);
302 TU_LOG_DRV(
" MSCh close addr = %d\r\n",
dev_addr);
317 switch (p_msc->
stage) {
345 tuh_msc_complete_data_t
const cb_data = {
348 .scsi_data = p_msc->
buffer,
379 TU_ASSERT(drv_len <= max_len);
384 for (uint32_t i = 0; i < 2; i++) {
404 TU_ASSERT(p_msc->
itf_num == itf_num);
409 TU_LOG_DRV(
"MSC Get Max Lun\r\n");
443 TU_LOG_DRV(
" Max LUN = %u\r\n", p_msc->
max_lun);
446 TU_LOG_DRV(
"SCSI Test Unit Ready\r\n");
447 uint8_t
const lun = 0;
457 TU_LOG_DRV(
"SCSI Read Capacity\r\n");
464 TU_LOG_DRV(
"SCSI Request Sense\r\n");
475 TU_ASSERT(csw->
status == 0);
484 TU_ASSERT(csw->
status == 0);
xfer_td_t xfer[EP_CBI_COUNT+1][2]
@ MSC_PROTOCOL_BOT
Bulk-Only Transport.
struct TU_ATTR_PACKED scsi_read_capacity10_t
SCSI Read Capacity 10 Command: Read Capacity.
struct TU_ATTR_PACKED scsi_inquiry_resp_t
SCSI Inquiry Response Data.
struct TU_ATTR_PACKED scsi_request_sense_t
struct TU_ATTR_PACKED scsi_inquiry_t
SCSI Inquiry Command.
struct TU_ATTR_PACKED scsi_read10_t
SCSI Read 10 Command.
struct TU_ATTR_PACKED scsi_write10_t
@ MSC_CBW_SIGNATURE
Constant value of 43425355h (little endian)
struct TU_ATTR_PACKED scsi_test_unit_ready_t
SCSI Test Unit Ready Command.
@ SCSI_CMD_TEST_UNIT_READY
The SCSI Test Unit Ready command is used to determine if a device is ready to transfer data (read/wri...
@ SCSI_CMD_REQUEST_SENSE
The SCSI Request Sense command is part of the SCSI computer protocol standard. This command is used t...
@ SCSI_CMD_WRITE_10
The WRITE (10) command requests that the device server transfer the specified logical block(s) from t...
@ SCSI_CMD_READ_CAPACITY_10
The SCSI Read Capacity command is used to obtain data capacity information from a target device.
@ SCSI_CMD_READ_10
The READ (10) command requests that the device server read the specified logical block(s) and transfe...
@ SCSI_CMD_INQUIRY
The SCSI Inquiry command is used to obtain basic information from a target device.
@ MSC_REQ_RESET
This request is used to reset the mass storage device and its associated interface....
@ MSC_REQ_GET_MAX_LUN
The Get Max LUN device request is used to determine the number of logical units supported by the devi...
static CFG_TUH_MEM_SECTION msch_interface_t _msch_itf[CFG_TUH_DEVICE_MAX]
bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t *response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
static void cbw_init(msc_cbw_t *cbw, uint8_t lun)
bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
CFG_TUH_MEM_SECTION static CFG_TUH_MEM_ALIGN uint8_t _msch_buffer[sizeof(scsi_inquiry_resp_t)]
uint32_t tuh_msc_get_block_size(uint8_t dev_addr, uint8_t lun)
bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
static TU_ATTR_ALWAYS_INLINE msch_interface_t * get_itf(uint8_t dev_addr)
bool tuh_msc_ready(uint8_t dev_addr)
void msch_close(uint8_t dev_addr)
uint32_t tuh_msc_get_block_count(uint8_t dev_addr, uint8_t lun)
bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
static bool config_test_unit_ready_complete(uint8_t dev_addr, tuh_msc_complete_data_t const *cb_data)
bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
static bool config_request_sense_complete(uint8_t dev_addr, tuh_msc_complete_data_t const *cb_data)
bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t *response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
uint8_t tuh_msc_get_maxlun(uint8_t dev_addr)
bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const *buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
static void config_get_maxlun_complete(tuh_xfer_t *xfer)
bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void *buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
bool tuh_msc_reset(uint8_t dev_addr)
static bool config_read_capacity_complete(uint8_t dev_addr, tuh_msc_complete_data_t const *cb_data)
bool tuh_msc_mounted(uint8_t dev_addr)
bool tuh_msc_scsi_command(uint8_t daddr, msc_cbw_t const *cbw, void *data, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
TU_ATTR_WEAK void tuh_msc_umount_cb(uint8_t dev_addr)
bool(* tuh_msc_complete_cb_t)(uint8_t dev_addr, tuh_msc_complete_data_t const *cb_data)
TU_ATTR_WEAK void tuh_msc_mount_cb(uint8_t dev_addr)
static void * memcpy(void *dst, const void *src, size_t n)
AUDIO Channel Cluster Descriptor (4.1)
uint32_t tag
Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTa...
uint8_t cmd_code
SCSI OpCode for SCSI_CMD_TEST_UNIT_READY.
uint8_t status
indicates the success or failure of the command. Values from msc_csw_status_t
uint8_t lun
The device Logical Unit Number (LUN) to which the command block is being sent. For devices that suppo...
uint8_t cmd_len
The valid length of the CBWCBin bytes. This defines the valid length of the command block....
uint8_t dir
Bit 7 of this field define transfer direction - 0 : Data-Out from host to the device....
struct TU_ATTR_PACKED::@16::TU_ATTR_PACKED bmRequestType_bit
uint32_t signature
Signature that helps identify this data packet as a CBW. The signature field shall contain the value ...
uint8_t bmAttributes
See: audio_clock_source_attribute_t.
uint8_t bDescriptorType
Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
uint8_t command[16]
The command block to be executed by the device. The device shall interpret the first cmd_len bytes in...
uint8_t bInterfaceSubClass
Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bInterfaceCla...
uint32_t total_bytes
The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (as...
uint8_t bNumEndpoints
Number of endpoints used by this interface (excluding endpoint zero). If this value is zero,...
uint8_t bInterfaceProtocol
Protocol code (assigned by the USB). These codes are qualified by the value of the bInterfaceClass ...
uint8_t bInterfaceNumber
Number of this interface. Zero-based value identifying the index in the array of concurrent interface...
CFG_TUH_MEM_ALIGN msc_cbw_t cbw
tuh_msc_complete_cb_t complete_cb
struct msch_interface_t::@44 capacity[CFG_TUH_MSC_MAXLUN]
CFG_TUH_MEM_ALIGN msc_csw_t csw
SCSI Read Capacity 10 Response Data.
uint32_t last_lba
The last Logical Block Address of the device.
uint32_t block_size
Block size in bytes.
@ TUSB_REQ_RCPT_INTERFACE
TU_ATTR_PACKED_END TU_ATTR_BIT_FIELD_ORDER_END static TU_ATTR_ALWAYS_INLINE tusb_dir_t tu_edpt_dir(uint8_t addr)
struct TU_ATTR_PACKED tusb_desc_endpoint_t
USB Endpoint Descriptor.
static TU_ATTR_ALWAYS_INLINE uint8_t const * tu_desc_next(void const *desc)
void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
CFG_TUH_MEM_ALIGN tusb_control_request_t request
bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr)
bool tuh_control_xfer(tuh_xfer_t *xfer)
bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr)
tuh_xfer_cb_t complete_cb
bool tuh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const *desc_ep)
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
static TU_ATTR_ALWAYS_INLINE bool usbh_edpt_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)