RISC-V update

master
Ivan Olenichev 3 years ago
parent 78354caede
commit 6185c52b56

@ -0,0 +1,69 @@
/*!
\file msc_bbb.h
\brief definitions for the USB MSC BBB(bulk/bulk/bulk) protocol
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __MSC_BBB_H
#define __MSC_BBB_H
#include "usb_ch9_std.h"
#define BBB_CBW_SIGNATURE 0x43425355U
#define BBB_CSW_SIGNATURE 0x53425355U
#define BBB_CBW_LENGTH 31U
#define BBB_CSW_LENGTH 13U
typedef struct {
uint32_t dCBWSignature;
uint32_t dCBWTag;
uint32_t dCBWDataTransferLength;
uint8_t bmCBWFlags;
uint8_t bCBWLUN;
uint8_t bCBWCBLength;
uint8_t CBWCB[16];
}msc_bbb_cbw;
typedef struct {
uint32_t dCSWSignature;
uint32_t dCSWTag;
uint32_t dCSWDataResidue;
uint8_t bCSWStatus;
}msc_bbb_csw;
/* CSW command status */
enum msc_csw_status {
CSW_CMD_PASSED = 0,
CSW_CMD_FAILED,
CSW_PHASE_ERROR
};
#endif /* __MSC_BBB_H */

@ -0,0 +1,117 @@
/*!
\file msc_scsi.h
\brief definitions for the USB MSC SCSI commands
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __MSC_SCSI_H
#define __MSC_SCSI_H
#include "usb_ch9_std.h"
/* SCSI commands */
#define SCSI_FORMAT_UNIT 0x04U
#define SCSI_INQUIRY 0x12U
#define SCSI_MODE_SELECT6 0x15U
#define SCSI_MODE_SELECT10 0x55U
#define SCSI_MODE_SENSE6 0x1AU
#define SCSI_READ_TOC_DATA 0x43U
#define SCSI_MODE_SENSE10 0x5AU
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1EU
#define SCSI_READ6 0x08U
#define SCSI_READ10 0x28U
#define SCSI_READ12 0xA8U
#define SCSI_READ16 0x88U
#define SCSI_READ_CAPACITY10 0x25U
#define SCSI_READ_CAPACITY16 0x9EU
#define SCSI_REQUEST_SENSE 0x03U
#define SCSI_START_STOP_UNIT 0x1BU
#define SCSI_TEST_UNIT_READY 0x00U
#define SCSI_WRITE6 0x0AU
#define SCSI_WRITE10 0x2AU
#define SCSI_WRITE12 0xAAU
#define SCSI_WRITE16 0x8AU
#define SCSI_VERIFY10 0x2FU
#define SCSI_VERIFY12 0xAFU
#define SCSI_VERIFY16 0x8FU
#define SCSI_SEND_DIAGNOSTIC 0x1DU
#define SCSI_READ_FORMAT_CAPACITIES 0x23U
#define INVALID_CDB 0x20U
#define INVALID_FIELED_IN_COMMAND 0x24U
#define PARAMETER_LIST_LENGTH_ERROR 0x1AU
#define INVALID_FIELD_IN_PARAMETER_LIST 0x26U
#define ADDRESS_OUT_OF_RANGE 0x21U
#define MEDIUM_NOT_PRESENT 0x3AU
#define MEDIUM_HAVE_CHANGED 0x28U
#define WRITE_PROTECTED 0x27U
#define UNRECOVERED_READ_ERROR 0x11U
#define WRITE_FAULT 0x03U
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0CU
#define READ_CAPACITY10_DATA_LEN 0x08U
#define MODE_SENSE10_DATA_LEN 0x08U
#define MODE_SENSE6_DATA_LEN 0x04U
#define READ_TOC_CMD_LEN 0x14U
#define REQUEST_SENSE_DATA_LEN 0x12U
#define STANDARD_INQUIRY_DATA_LEN 0x24U
#define BLKVFY 0x04U
enum sense_state {
NO_SENSE = 0U,
RECOVERED_ERROR,
NOT_READY,
MEDIUM_ERROR,
HARDWARE_ERROR,
ILLEGAL_REQUEST,
UNIT_ATTENTION,
DATA_PROTECT,
BLANK_CHECK,
VENDOR_SPECIFIC,
COPY_ABORTED,
ABORTED_COMMAND,
RESERVED,
VOLUME_OVERFLOW,
MISCOMPARE
};
typedef struct {
uint8_t SenseKey;
uint32_t Information;
uint8_t ASC;
uint8_t ASCQ;
} msc_scsi_sense;
#endif /* __MSC_SCSI_H */

@ -0,0 +1,90 @@
/*!
\file usb_conf.h
\brief general low level driver configuration
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __USB_CONF_H
#define __USB_CONF_H
#include "gd32vf103.h"
#include <stddef.h>
#ifdef USE_USB_FS
#define USB_FS_CORE
#endif
#ifdef USB_FS_CORE
#define USB_RX_FIFO_FS_SIZE 128
#define USB_HTX_NPFIFO_FS_SIZE 96
#define USB_HTX_PFIFO_FS_SIZE 96
#endif
#define USB_SOF_OUTPUT 0
#define USB_LOW_POWER 0
#define USE_HOST_MODE
//#define USE_DEVICE_MODE
//#define USE_OTG_MODE
#ifndef USB_FS_CORE
#ifndef USB_HS_CORE
#error "USB_HS_CORE or USB_FS_CORE should be defined"
#endif
#endif
#ifndef USE_DEVICE_MODE
#ifndef USE_HOST_MODE
#error "USE_DEVICE_MODE or USE_HOST_MODE should be defined"
#endif
#endif
#ifndef USE_USB_HS
#ifndef USE_USB_FS
#error "USE_USB_HS or USE_USB_FS should be defined"
#endif
#endif
/****************** C Compilers dependant keywords ****************************/
/* In HS mode and when the DMA is used, all variables and data structures dealing
with the DMA during the transaction process should be 4-bytes aligned */
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined (__GNUC__) /* GNU Compiler */
#define __ALIGN_END __attribute__ ((aligned(4)))
#define __ALIGN_BEGIN
#endif /* __GNUC__ */
#else
#define __ALIGN_BEGIN
#define __ALIGN_END
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
#endif /* __USB_CONF_H */

@ -0,0 +1,66 @@
/*!
\file usb_msc.h
\brief definitions for the USB MSC class
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __USB_MSC_H
#define __USB_MSC_H
#include "usb_ch9_std.h"
/* mass storage device class code */
#define USB_CLASS_MSC 0x08U
/* mass storage subclass code */
#define USB_MSC_SUBCLASS_RBC 0x01U
#define USB_MSC_SUBCLASS_ATAPI 0x02U
#define USB_MSC_SUBCLASS_UFI 0x04U
#define USB_MSC_SUBCLASS_SCSI 0x06U
#define USB_MSC_SUBCLASS_LOCKABLE 0x07U
#define USB_MSC_SUBCLASS_IEEE1667 0x08U
/* mass storage interface class control protocol codes */
#define USB_MSC_PROTOCOL_CBI 0x00U
#define USB_MSC_PROTOCOL_CBI_ALT 0x01U
#define USB_MSC_PROTOCOL_BBB 0x50U
/* mass storage request codes */
#define USB_MSC_REQ_CODES_ADSC 0x00U
#define USB_MSC_REQ_CODES_GET 0xFCU
#define USB_MSC_REQ_CODES_PUT 0xFDU
#define USB_MSC_REQ_CODES_GML 0xFEU
#define USB_MSC_REQ_CODES_BOMSR 0xFFU
#define BBB_GET_MAX_LUN 0xFEU
#define BBB_RESET 0xFFU
#endif /* __USB_MSC_H */

@ -0,0 +1,42 @@
/*!
\file usbh_conf.h
\brief general low level driver configuration
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __USBH_CONF_H
#define __USBH_CONF_H
#define USBH_MAX_EP_NUM 2
#define USBH_MAX_INTERFACES_NUM 2
#define USBH_MSC_MPS_SIZE 0x200
#endif /* __USBH_CONF_H */

@ -0,0 +1,127 @@
/*!
\file usbh_msc_bbb.h
\brief header file for usbh_msc_bbb.c
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __USBH_MSC_BBB_H
#define __USBH_MSC_BBB_H
#include "usbh_enum.h"
#include "msc_bbb.h"
typedef union {
msc_bbb_cbw field;
uint8_t CBWArray[31];
}usbh_cbw_pkt;
typedef union {
msc_bbb_csw field;
uint8_t CSWArray[13];
}usbh_csw_pkt;
enum usbh_msc_state {
USBH_MSC_BOT_INIT_STATE = 0,
USBH_MSC_BOT_RESET,
USBH_MSC_GET_MAX_LUN,
USBH_MSC_TEST_UNIT_READY,
USBH_MSC_READ_CAPACITY10,
USBH_MSC_MODE_SENSE6,
USBH_MSC_REQUEST_SENSE,
USBH_MSC_BOT_USB_TRANSFERS,
USBH_MSC_DEFAULT_APPLI_STATE,
USBH_MSC_CTRL_ERROR_STATE,
USBH_MSC_UNRECOVERED_STATE
};
enum msc_bot_state {
USBH_MSC_SEND_CBW = 1U,
USBH_MSC_SENT_CBW,
USBH_MSC_BOT_DATAIN_STATE,
USBH_MSC_BOT_DATAOUT_STATE,
USBH_MSC_RECEIVE_CSW_STATE,
USBH_MSC_DECODE_CSW,
USBH_MSC_BOT_ERROR_IN,
USBH_MSC_BOT_ERROR_OUT
};
typedef struct {
uint8_t msc_state;
uint8_t msc_state_bkp;
uint8_t msc_state_current;
uint8_t cmd_state_machine;
uint8_t bot_state;
uint8_t bot_state_bkp;
uint8_t *xfer_buf;
uint16_t data_len;
uint8_t bot_xfer_status;
} usbh_botxfer;
#define USBH_MSC_BOT_CBW_TAG 0x20304050
#define USBH_MSC_CSW_MAX_LENGTH 63
#define USBH_MSC_SEND_CSW_DISABLE 0
#define USBH_MSC_SEND_CSW_ENABLE 1
#define USBH_MSC_DIR_IN 0
#define USBH_MSC_DIR_OUT 1
#define USBH_MSC_BOTH_DIR 2
#define USBH_MSC_PAGE_LENGTH 512
#define CBW_CB_LENGTH 16
#define CBW_LENGTH 10
#define CBW_LENGTH_TEST_UNIT_READY 6
#define MAX_BULK_STALL_COUNT_LIMIT 0x04 /* If STALL is seen on Bulk
Endpoint continously, this means
that device and Host has phase error
Hence a Reset is needed */
extern usbh_botxfer msc_botxfer_param;
extern usbh_cbw_pkt msc_cbw_data;
extern usbh_csw_pkt msc_csw_data;
void usbh_msc_init (usb_core_driver *pudev);
void usbh_msc_botxfer (usb_core_driver *pudev, usbh_host *puhost);
uint8_t usbh_msc_csw_decode (usb_core_driver *pudev, usbh_host *puhost);
usbh_status usbh_msc_bot_abort (usb_core_driver *pudev, usbh_host *puhost, uint8_t direction);
#endif /* __USBH_MSC_BOT_H */

@ -0,0 +1,58 @@
/*!
\file usbh_msc_core.h
\brief header file for the usbh_msc_core.c
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __USBH_MSC_CORE_H
#define __USBH_MSC_CORE_H
#include "usb_msc.h"
#include "usbh_msc_scsi.h"
#include "usbh_msc_bbb.h"
/* structure for msc process */
typedef struct {
uint8_t hc_num_in;
uint8_t hc_num_out;
uint8_t msc_bulk_epin;
uint8_t msc_bulk_epout;
uint16_t msc_bulk_epinsize;
uint16_t msc_bulk_epoutsize;
uint8_t buf[USBH_MSC_MPS_SIZE];
uint8_t max_lun;
} usbh_msc_machine;
extern usbh_class_cb usbh_msc_cb;
extern usbh_msc_machine msc_machine;
extern uint8_t msc_error_count;
#endif /* __USBH_MSC_CORE_H */

@ -0,0 +1,91 @@
/*!
\file usbh_msc_scsi.h
\brief header file for usbh_msc_scsi.c
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __USBH_MSC_SCSI_H
#define __USBH_MSC_SCSI_H
#include "msc_scsi.h"
#include "usbh_enum.h"
typedef enum
{
USBH_MSC_OK = 0U,
USBH_MSC_FAIL = 1U,
USBH_MSC_PHASE_ERROR = 2U,
USBH_MSC_BUSY = 3U
}usbh_msc_status;
enum cmd_states {
CMD_UNINITIALIZED_STATE = 0,
CMD_SEND_STATE,
CMD_WAIT_STATUS
};
typedef struct
{
uint32_t msc_capacity;
uint32_t msc_sense_key;
uint16_t msc_page_len;
uint8_t msc_write_protect;
}usbh_msc_parameter;
#define DESC_REQUEST_SENSE 0x00U
#define ALLOCATION_LENGTH_REQUEST_SENSE 63U
#define XFER_LEN_MODE_SENSE6 63U
#define MASK_MODE_SENSE_WRITE_PROTECT 0x80U
#define MODE_SENSE_PAGE_CONTROL_FIELD 0x00U
#define MODE_SENSE_PAGE_CODE 0x3FU
#define DISK_WRITE_PROTECTED 0x01U
extern usbh_msc_parameter usbh_msc_param;
uint8_t usbh_msc_test_unitready (usb_core_driver *pudev);
uint8_t usbh_msc_read_capacity10 (usb_core_driver *pudev);
uint8_t usbh_msc_mode_sense6 (usb_core_driver *pudev);
uint8_t usbh_msc_request_sense (usb_core_driver *pudev);
uint8_t usbh_msc_write10 (usb_core_driver *pudev,
uint8_t *data_buf,
uint32_t addr,
uint32_t byte_num);
uint8_t usbh_msc_read10 (usb_core_driver *pudev,
uint8_t *data_buf,
uint32_t addr,
uint32_t byte_num);
void usbh_msc_state_machine (usb_core_driver *pudev);
#endif /* __USBH_MSC_SCSI_H */

@ -0,0 +1,94 @@
/*!
\file usbh_usr.h
\brief user application layer header file
\version 2019-06-05, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef USBH_USR_H
#define USBH_USR_H
#include "ff.h"
#include "usbh_core.h"
#include "usb_conf.h"
#include "usbh_msc_core.h"
#include <stdio.h>
extern usbh_user_cb user_callback_funs;
/* state machine for the usbh_usr_application_state */
#define USBH_USR_FS_INIT 0
#define USBH_USR_FS_READLIST 1
#define USBH_USR_FS_WRITEFILE 2
#define USBH_USR_FS_DEMOEND 3
extern uint8_t usbh_usr_application_state;
/* function declarations */
/* user operation for host-mode initialization */
void usbh_user_init (void);
/* de-int user state and associated variables */
void usbh_user_deinit (void);
/* user operation for device attached */
void usbh_user_device_connected (void);
/* user operation for reset USB Device */
void usbh_user_device_reset (void);
/* user operation for device disconnect event */
void usbh_user_device_disconnected (void);
/* user operation for device overcurrent detection event */
void usbh_user_over_current_detected (void);
/* user operation for detectting device speed */
void usbh_user_device_speed_detected (uint32_t device_speed);
/* user operation when device descriptor is available */
void usbh_user_device_desc_available (void *dev_desc);
/* USB device is successfully assigned the address */
void usbh_user_device_address_assigned (void);
/* user operation when configuration descriptor is available */
void usbh_user_configuration_descavailable (usb_desc_config *cfg_desc,
usb_desc_itf *itf_desc,
usb_desc_ep *ep_desc);
/* user operation when manufacturer string exists */
void usbh_user_manufacturer_string (void *mfc_string);
/* user operation when product string exists */
void usbh_user_product_string (void *prod_string);
/* user operatin when serialNum string exists */
void usbh_user_serialnum_string (void *serialnum_string);
/* user response request is displayed to ask for application jump to class */
void usbh_user_enumeration_finish (void);
/* user action for application state entry */
usbh_user_status usbh_user_userinput (void);
/* user operation when device is not supported */
void usbh_user_device_not_supported (void);
/* user operation when unrecoveredError happens */
void usbh_user_unrecovered_error (void);
/* demo application for mass storage */
int usbh_usr_msc_application (void);
#endif /* USBH_USR_H */
Loading…
Cancel
Save