mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 09:22:11 +00:00
update version to v2.0.4
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_bot_scsi.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb mass storage bulk-only transport and scsi command
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
@@ -33,7 +33,7 @@
|
||||
/** @defgroup USB_msc_bot_scsi
|
||||
* @brief usb device class mass storage demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_bot_functions
|
||||
* @{
|
||||
@@ -44,11 +44,11 @@
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t page00_inquiry_data[] ALIGNED_TAIL = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
|
||||
};
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
@@ -70,7 +70,7 @@ ALIGNED_HEAD sense_type sense_data ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t mode_sense6_data[8] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t mode_sense6_data[8] ALIGNED_TAIL =
|
||||
{
|
||||
0x00,
|
||||
0x00,
|
||||
@@ -85,7 +85,7 @@ ALIGNED_HEAD uint8_t mode_sense6_data[8] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
|
||||
{
|
||||
0x00,
|
||||
0x06,
|
||||
@@ -99,7 +99,7 @@ ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
|
||||
/**
|
||||
* @brief initialize bulk-only transport and scsi
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_init(void *udev)
|
||||
{
|
||||
@@ -108,14 +108,14 @@ void bot_scsi_init(void *udev)
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
pmsc->bot_status = MSC_BOT_STATE_IDLE;
|
||||
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
|
||||
pmsc->csw_struct.dCSWDataResidue = 0;
|
||||
pmsc->csw_struct.dCSWSignature = 0;
|
||||
pmsc->csw_struct.dCSWTag = CSW_BCSWSTATUS_PASS;
|
||||
|
||||
|
||||
usbd_flush_tx_fifo(pudev, USBD_MSC_BULK_IN_EPT&0x7F);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ void bot_scsi_init(void *udev)
|
||||
/**
|
||||
* @brief reset bulk-only transport and scsi
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_reset(void *udev)
|
||||
{
|
||||
@@ -133,7 +133,7 @@ void bot_scsi_reset(void *udev)
|
||||
pmsc->bot_status = MSC_BOT_STATE_RECOVERY;
|
||||
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
usbd_flush_tx_fifo(pudev, USBD_MSC_BULK_IN_EPT&0x7F);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ void bot_scsi_reset(void *udev)
|
||||
* @brief bulk-only transport data in handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -156,12 +156,12 @@ void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_FAILED);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case MSC_STATE_MACHINE_LAST_DATA:
|
||||
case MSC_STATE_MACHINE_SEND_DATA:
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
* @brief bulk-only transport data out handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -182,7 +182,7 @@ void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
case MSC_STATE_MACHINE_IDLE:
|
||||
bot_cbw_decode(udev);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_STATE_MACHINE_DATA_OUT:
|
||||
if(bot_scsi_cmd_process(udev) != USB_OK)
|
||||
{
|
||||
@@ -195,16 +195,16 @@ void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief bulk-only cbw decode
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_cbw_decode(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWTag = pmsc->cbw_struct.dCBWTage;
|
||||
pmsc->csw_struct.dCSWDataResidue = pmsc->cbw_struct.dCBWDataTransferLength;
|
||||
|
||||
|
||||
/* check param */
|
||||
if((pmsc->cbw_struct.dCBWSignature != CBW_DCBWSIGNATURE) ||
|
||||
(usbd_get_recv_len(pudev, USBD_MSC_BULK_OUT_EPT) != CBW_CMD_LENGTH)
|
||||
@@ -242,20 +242,20 @@ void bot_cbw_decode(void *udev)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param buffer: data buffer
|
||||
* @param len: data len
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint32_t data_len = MIN(len, pmsc->cbw_struct.dCBWDataTransferLength);
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWDataResidue -= data_len;
|
||||
pmsc->csw_struct.bCSWStatus = CSW_BCSWSTATUS_PASS;
|
||||
|
||||
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_SEND_DATA;
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
buffer, data_len);
|
||||
}
|
||||
|
||||
@@ -263,20 +263,20 @@ void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len)
|
||||
* @brief send command status
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param status: csw status
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_send_csw(void *udev, uint8_t status)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
pmsc->csw_struct.bCSWStatus = status;
|
||||
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
(uint8_t *)&pmsc->csw_struct, CSW_CMD_LENGTH);
|
||||
|
||||
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
@@ -287,7 +287,7 @@ void bot_scsi_send_csw(void *udev, uint8_t status)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param sense_key: sense key
|
||||
* @param asc: asc
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_sense_code(void *udev, uint8_t sense_key, uint8_t asc)
|
||||
{
|
||||
@@ -302,7 +302,7 @@ void bot_scsi_sense_code(void *udev, uint8_t sense_key, uint8_t asc)
|
||||
* @param lun: logical units number
|
||||
* @param blk_offset: blk offset address
|
||||
* @param blk_count: blk number
|
||||
* @retval usb_sts_type
|
||||
* @retval usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset, uint32_t blk_count)
|
||||
{
|
||||
@@ -319,13 +319,13 @@ usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset
|
||||
/**
|
||||
* @brief bot endpoint stall
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_stall(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if((pmsc->cbw_struct.dCBWDataTransferLength != 0) &&
|
||||
(pmsc->cbw_struct.bmCBWFlags == 0) &&
|
||||
pmsc->bot_status == MSC_BOT_STATE_IDLE)
|
||||
@@ -333,10 +333,10 @@ void bot_scsi_stall(void *udev)
|
||||
usbd_set_stall(pudev, USBD_MSC_BULK_OUT_EPT);
|
||||
}
|
||||
usbd_set_stall(pudev, USBD_MSC_BULK_IN_EPT);
|
||||
|
||||
|
||||
if(pmsc->bot_status == MSC_BOT_STATE_ERROR)
|
||||
{
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
}
|
||||
@@ -345,20 +345,20 @@ void bot_scsi_stall(void *udev)
|
||||
* @brief bulk-only transport scsi command test unit
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_test_unit(void *udev, uint8_t lun)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != 0)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->data_len = 0;
|
||||
return status;
|
||||
}
|
||||
@@ -367,7 +367,7 @@ usb_sts_type bot_scsi_test_unit(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command inquiry
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -376,7 +376,7 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.CBWCB[1] & 0x01)
|
||||
{
|
||||
pdata = page00_inquiry_data;
|
||||
@@ -394,7 +394,7 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
trans_len = SCSI_INQUIRY_DATA_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pmsc->data_len = trans_len;
|
||||
while(trans_len)
|
||||
{
|
||||
@@ -408,7 +408,7 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command start stop
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -422,7 +422,7 @@ usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command meidum removal
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -436,7 +436,7 @@ usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command mode sense6
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -456,7 +456,7 @@ usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command mode sense10
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -476,7 +476,7 @@ usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command capacity
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -484,17 +484,17 @@ usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
|
||||
|
||||
|
||||
pdata[0] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
|
||||
pdata[1] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
|
||||
pdata[2] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
|
||||
pdata[3] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
|
||||
|
||||
|
||||
pdata[4] = (uint8_t)((pmsc->blk_size[lun]) >> 24);
|
||||
pdata[5] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
|
||||
pdata[6] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
|
||||
pdata[7] = (uint8_t)((pmsc->blk_size[lun]));
|
||||
|
||||
|
||||
pmsc->data_len = 8;
|
||||
return USB_OK;
|
||||
}
|
||||
@@ -503,34 +503,34 @@ usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command format capacity
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun)
|
||||
{
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
|
||||
|
||||
pdata[0] = 0;
|
||||
pdata[1] = 0;
|
||||
pdata[2] = 0;
|
||||
pdata[3] = 0x08;
|
||||
|
||||
|
||||
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
|
||||
|
||||
|
||||
pdata[4] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
|
||||
pdata[5] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
|
||||
pdata[6] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
|
||||
pdata[7] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
|
||||
|
||||
|
||||
pdata[8] = 0x02;
|
||||
|
||||
|
||||
pdata[9] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
|
||||
pdata[10] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
|
||||
pdata[11] = (uint8_t)((pmsc->blk_size[lun]));
|
||||
|
||||
|
||||
pmsc->data_len = 12;
|
||||
|
||||
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command request sense
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -547,13 +547,13 @@ usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
uint8_t *sdata = (uint8_t *)&sense_data;
|
||||
|
||||
|
||||
while(trans_len)
|
||||
{
|
||||
trans_len --;
|
||||
pdata[trans_len] = sdata[trans_len];
|
||||
}
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength < REQ_SENSE_STANDARD_DATA_LEN)
|
||||
{
|
||||
pmsc->data_len = pmsc->cbw_struct.dCBWDataTransferLength;
|
||||
@@ -569,7 +569,7 @@ usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command verify
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -581,10 +581,10 @@ usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
@@ -597,7 +597,7 @@ usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command read10
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -605,7 +605,7 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
|
||||
uint32_t len;
|
||||
|
||||
|
||||
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
{
|
||||
if((pmsc->cbw_struct.bmCBWFlags & 0x80) != 0x80)
|
||||
@@ -613,18 +613,18 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr *= pmsc->blk_size[lun];
|
||||
pmsc->blk_len *= pmsc->blk_size[lun];
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
@@ -633,7 +633,7 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_DATA_IN;
|
||||
}
|
||||
pmsc->data_len = MSC_MAX_DATA_BUF_LEN;
|
||||
|
||||
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
if( msc_disk_read(lun, pmsc->blk_addr, pmsc->data, len) != USB_OK)
|
||||
{
|
||||
@@ -643,13 +643,13 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT, pmsc->data, len);
|
||||
pmsc->blk_addr += len;
|
||||
pmsc->blk_len -= len;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWDataResidue -= len;
|
||||
if(pmsc->blk_len == 0)
|
||||
{
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_LAST_DATA;
|
||||
}
|
||||
|
||||
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -658,7 +658,7 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command write10
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -666,7 +666,7 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
|
||||
uint32_t len;
|
||||
|
||||
|
||||
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
{
|
||||
if((pmsc->cbw_struct.bmCBWFlags & 0x80) == 0x80)
|
||||
@@ -674,28 +674,28 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr *= pmsc->blk_size[lun];
|
||||
pmsc->blk_len *= pmsc->blk_size[lun];
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_DATA_OUT;
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)pmsc->data, len);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -705,12 +705,12 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_HARDWARE_ERROR, MEDIUM_NOT_PRESENT);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr += len;
|
||||
pmsc->blk_len -= len;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWDataResidue -= len;
|
||||
|
||||
|
||||
if(pmsc->blk_len == 0)
|
||||
{
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
|
||||
@@ -728,7 +728,7 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
* @brief clear feature
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param etp_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
void bot_scsi_clear_feature(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -748,7 +748,7 @@ void bot_scsi_clear_feature(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief bulk-only transport scsi command process
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_cmd_process(void *udev)
|
||||
{
|
||||
@@ -760,51 +760,51 @@ usb_sts_type bot_scsi_cmd_process(void *udev)
|
||||
case MSC_CMD_INQUIRY:
|
||||
status = bot_scsi_inquiry(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_START_STOP:
|
||||
status = bot_scsi_start_stop(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case MSC_CMD_MODE_SENSE6:
|
||||
status = bot_scsi_mode_sense6(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_MODE_SENSE10:
|
||||
status = bot_scsi_mode_sense10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_ALLOW_MEDIUM_REMOVAL:
|
||||
status = bot_scsi_allow_medium_removal(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_READ_10:
|
||||
status = bot_scsi_read10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_READ_CAPACITY:
|
||||
status = bot_scsi_capacity(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_REQUEST_SENSE:
|
||||
status = bot_scsi_request_sense(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_TEST_UNIT:
|
||||
status = bot_scsi_test_unit(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_VERIFY:
|
||||
status = bot_scsi_verify(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_WRITE_10:
|
||||
status = bot_scsi_write10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_READ_FORMAT_CAPACITY:
|
||||
status = bot_scsi_format_capacity(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
status = USB_FAIL;
|
||||
@@ -815,7 +815,7 @@ usb_sts_type bot_scsi_cmd_process(void *udev)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_bot_scsi.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb mass storage bulk-only transport and scsi command header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MSC_BOT_SCSI_H
|
||||
#define __MSC_BOT_SCSI_H
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "msc_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
@@ -41,8 +41,8 @@ extern "C" {
|
||||
/** @addtogroup USB_msc_bot_scsi
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_bot_scsi_definition
|
||||
|
||||
/** @defgroup USB_msc_bot_scsi_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -195,21 +195,21 @@ typedef struct
|
||||
uint8_t msc_state;
|
||||
uint8_t bot_status;
|
||||
uint32_t max_lun;
|
||||
|
||||
|
||||
uint32_t blk_nbr[MSC_SUPPORT_MAX_LUN];
|
||||
uint32_t blk_size[MSC_SUPPORT_MAX_LUN];
|
||||
|
||||
|
||||
uint32_t blk_addr;
|
||||
uint32_t blk_len;
|
||||
|
||||
|
||||
uint32_t data_len;
|
||||
uint8_t data[MSC_MAX_DATA_BUF_LEN];
|
||||
|
||||
|
||||
uint32_t alt_setting;
|
||||
|
||||
|
||||
cbw_type cbw_struct;
|
||||
csw_type csw_struct;
|
||||
|
||||
|
||||
}msc_type;
|
||||
|
||||
void bot_scsi_init(void *udev);
|
||||
@@ -241,11 +241,11 @@ void bot_scsi_clear_feature(void *udev, uint8_t ept_num);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "msc_class.h"
|
||||
#include "msc_desc.h"
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_msc_class
|
||||
* @brief usb device class msc demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_class_private_functions
|
||||
* @{
|
||||
@@ -54,7 +54,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
msc_type msc_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler msc_class_handler =
|
||||
usbd_class_handler msc_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -71,40 +71,40 @@ usbd_class_handler msc_class_handler =
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_MSC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_MSC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
bot_scsi_init(udev);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_clear_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_MSC_BULK_IN_EPT);
|
||||
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_MSC_BULK_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @brief usb device class setup request handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -123,7 +123,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
/* class request */
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
|
||||
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case MSC_REQ_GET_MAX_LUN:
|
||||
@@ -136,12 +136,12 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
/* standard request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
|
||||
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case USB_STD_REQ_GET_DESCRIPTOR:
|
||||
@@ -155,7 +155,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
break;
|
||||
case USB_STD_REQ_CLEAR_FEATURE:
|
||||
usbd_ept_close(pudev, (uint8_t)setup->wIndex);
|
||||
|
||||
|
||||
if((setup->wIndex & 0x80) == 0x80)
|
||||
{
|
||||
usbd_flush_tx_fifo(pudev, setup->wIndex & 0x7F);
|
||||
@@ -181,21 +181,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint 0 out status stage complete
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -210,7 +210,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device transmision complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -225,7 +225,7 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device endpoint receive data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -238,14 +238,14 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief usb device sof handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device event handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -261,20 +261,20 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -282,7 +282,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MSC_CLASS_H
|
||||
#define __MSC_CLASS_H
|
||||
@@ -30,19 +30,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_msc_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_class_definition
|
||||
/** @defgroup USB_msc_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -61,7 +61,7 @@ extern usbd_class_handler msc_class_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
#include "stdio.h"
|
||||
#include "usb_std.h"
|
||||
#include "usbd_sdr.h"
|
||||
@@ -32,11 +32,11 @@
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_msc_desc
|
||||
* @brief usb device msc descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_desc_private_functions
|
||||
* @{
|
||||
@@ -121,7 +121,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MSC_CONFIG_DESC_SIZE] ALIG
|
||||
the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 100 mA: this current is used for detecting vbus */
|
||||
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: number of interface */
|
||||
@@ -131,7 +131,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MSC_CONFIG_DESC_SIZE] ALIG
|
||||
0x06, /* bInterfaceSubClass: subclass code scsi */
|
||||
0x50, /* bInterfaceProtocol: protocol code BBB */
|
||||
0x05, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_MSC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -139,12 +139,12 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MSC_CONFIG_DESC_SIZE] ALIG
|
||||
LBYTE(USBD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_MSC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
@@ -210,24 +210,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @retval length
|
||||
*/
|
||||
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
{
|
||||
uint16_t str_len = 0, id_pos = 2;
|
||||
uint8_t *tmp_str = string;
|
||||
|
||||
|
||||
while(*tmp_str != '\0')
|
||||
{
|
||||
str_len ++;
|
||||
unicode_buf[id_pos ++] = *tmp_str ++;
|
||||
unicode_buf[id_pos ++] = 0x00;
|
||||
}
|
||||
|
||||
|
||||
str_len = str_len * 2 + 2;
|
||||
unicode_buf[0] = (uint8_t)str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -236,12 +236,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
{
|
||||
uint8_t idx = 0;
|
||||
|
||||
|
||||
for( idx = 0 ; idx < len ; idx ++)
|
||||
{
|
||||
if( ((value >> 28)) < 0xA )
|
||||
@@ -250,11 +250,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -262,18 +262,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void get_serial_num(void)
|
||||
{
|
||||
uint32_t serial0, serial1, serial2;
|
||||
|
||||
|
||||
serial0 = *(uint32_t*)MCU_ID1;
|
||||
serial1 = *(uint32_t*)MCU_ID2;
|
||||
serial2 = *(uint32_t*)MCU_ID3;
|
||||
|
||||
|
||||
serial0 += serial2;
|
||||
|
||||
|
||||
if (serial0 != 0)
|
||||
{
|
||||
usbd_int_to_unicode (serial0, &g_string_serial[2] ,8);
|
||||
@@ -284,7 +284,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -294,7 +294,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -304,7 +304,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -314,7 +314,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -324,7 +324,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -335,7 +335,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -347,7 +347,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -359,7 +359,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -370,7 +370,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -382,7 +382,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -393,7 +393,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MSC_DESC_H
|
||||
#define __MSC_DESC_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "msc_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_msc_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_desc_definition
|
||||
/** @defgroup USB_msc_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -70,11 +70,11 @@ extern usbd_desc_handler msc_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user