添加GD32H7的CMake工程

This commit is contained in:
2026-07-23 19:44:30 +08:00
commit d07f065b1c
202 changed files with 204039 additions and 0 deletions
@@ -0,0 +1,147 @@
/*!
\file usbh_msc_bbb.h
\brief header file for usbh_msc_bbb.c
\version 2025-01-24, V1.4.0, firmware for GD32H7xx
*/
/*
Copyright (c) 2025, 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"
#define USBH_MSC_BBB_CBW_TAG 0x20304050U /*!< MSC BBB CBW tag */
#define USBH_MSC_CSW_MAX_LENGTH 63U /*!< MSC CSW maximum length */
#define USBH_MSC_SEND_CSW_DISABLE 0U /*!< MSC send CSW disable */
#define USBH_MSC_SEND_CSW_ENABLE 1U /*!< MSC send CSW enable */
#define USBH_MSC_DIR_IN 0U /*!< MSC data transfer IN */
#define USBH_MSC_DIR_OUT 1U /*!< MSC data transfer OUT */
#define USBH_MSC_BOTH_DIR 2U /*!< MSC data transfer IN/OUT */
#define USBH_MSC_PAGE_LENGTH 512U /*!< MSC memory page length */
#define CBW_CB_LENGTH 16U /*!< MSC CBW CB length */
#define CBW_LENGTH 10U /*!< MSC CBW length */
#define CBW_LENGTH_TEST_UNIT_READY 0U /*!< MSC CBW test unit ready length */
/*!< if STALL is seen on bulk endpoint continuously, this means
that device and host has phase error, hence a reset is needed */
#define MAX_BULK_STALL_COUNT_LIMIT 0x04U
typedef union {
msc_bbb_cbw field; /*!< MSC BBB CBW structure */
uint8_t CBWArray[31]; /*!< MSC BBB CBW array buff */
}usbh_cbw_pkt;
typedef union {
msc_bbb_csw field; /*!< MSC BBB CSW structure */
uint8_t CSWArray[13]; /*!< MSC BBB CSW array buff */
}usbh_csw_pkt;
enum usbh_msc_state {
USBH_MSC_BBB_INIT_STATE = 0U, /*!< MSC BBB init state */
USBH_MSC_BBB_RESET, /*!< MSC BBB reset state */
USBH_MSC_GET_MAX_LUN, /*!< MSC init state */
USBH_MSC_TEST_UNIT_READY, /*!< MSC test unit ready state */
USBH_MSC_READ_CAPACITY10, /*!< MSC read capacity10 state */
USBH_MSC_MODE_SENSE6, /*!< MSC sense6 mode state */
USBH_MSC_REQUEST_SENSE, /*!< MSC request sense state */
USBH_MSC_BBB_USB_TRANSFERS, /*!< MSC BBB transfers state */
USBH_MSC_DEFAULT_APPLI_STATE, /*!< MSC default application state */
USBH_MSC_CTRL_ERROR_STATE, /*!< MSC control error state */
USBH_MSC_UNRECOVERED_STATE /*!< MSC unrecovered state */
};
/* MSC BBB status types */
typedef enum {
BBB_OK = 0U, /*!< MSC BBB OK status */
BBB_FAIL, /*!< MSC BBB fail status */
BBB_PHASE_ERROR, /*!< MSC BBB phase error status */
BBB_BUSY /*!< MSC BBB busy status */
} bbb_status;
/* MSC BBB command state types */
typedef enum {
BBB_CMD_IDLE = 0U, /*!< MSC BBB command idle state */
BBB_CMD_SEND, /*!< MSC BBB command send state */
BBB_CMD_WAIT /*!< MSC BBB command wait state */
} bbb_cmd_state;
/* CSW status definitions */
typedef enum {
BBB_CSW_CMD_PASSED = 0U, /*!< MSC BBB CSW command passed status */
BBB_CSW_CMD_FAILED, /*!< MSC BBB CSW command failed status */
BBB_CSW_PHASE_ERROR /*!< MSC BBB CSW phase error status */
} bbb_csw_status;
/* MSC BBB state types */
typedef enum {
BBB_SEND_CBW = 1U, /*!< MSC BBB send CBW state */
BBB_SEND_CBW_WAIT, /*!< MSC BBB send CBW wait state */
BBB_DATA_IN, /*!< MSC BBB data IN state */
BBB_DATA_IN_WAIT, /*!< MSC BBB data IN wait state */
BBB_DATA_OUT, /*!< MSC BBB data OUT state */
BBB_DATA_OUT_WAIT, /*!< MSC BBB data OUT wait state */
BBB_RECEIVE_CSW, /*!< MSC BBB receive CSW state */
BBB_RECEIVE_CSW_WAIT, /*!< MSC BBB receive CSW wait state */
BBB_ERROR_IN, /*!< MSC BBB error IN state */
BBB_ERROR_OUT, /*!< MSC BBB error OUT state */
BBB_UNRECOVERED_ERROR /*!< MSC BBB unrecovered error state */
} bbb_state;
typedef struct {
uint8_t *pbuf; /*!< MSC BBB data buff pointer */
uint32_t data[16]; /*!< MSC BBB data buff */
bbb_state state; /*!< MSC BBB state */
bbb_state prev_state; /*!< MSC BBB previous state */
bbb_cmd_state cmd_state; /*!< MSC BBB command state */
usbh_cbw_pkt cbw; /*!< MSC CBW pocket structure */
usbh_csw_pkt csw; /*!< MSC CSW pocket structure */
} bbb_handle;
/* function declarations */
/* initialize the mass storage parameters */
void usbh_msc_bbb_init(usbh_host *uhost);
/* manage the different states of BBB transfer and updates the status to upper layer */
usbh_status usbh_msc_bbb_process(usbh_host *uhost, uint8_t lun);
/* manages the different error handling for STALL */
usbh_status usbh_msc_bbb_abort(usbh_host *uhost, uint8_t direction);
/* reset MSC BBB request structure */
usbh_status usbh_msc_bbb_reset(usbh_host *uhost);
/* decode the CSW received by the device and updates the same to upper layer */
bbb_csw_status usbh_msc_csw_decode(usbh_host *uhost);
#endif /* USBH_MSC_BBB_H */
@@ -0,0 +1,122 @@
/*!
\file usbh_core.h
\brief header file for the usbh_core.c
\version 2025-01-24, V1.4.0, firmware for GD32H7xx
*/
/*
Copyright (c) 2025, 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"
#define MSC_MAX_SUPPORTED_LUN 2U
/* MSC state types */
typedef enum {
MSC_INIT = 0U, /*!< MSC init state */
MSC_IDLE, /*!< MSC idle state */
MSC_TEST_UNIT_READY, /*!< MSC test unit ready state */
MSC_READ_CAPACITY10, /*!< MSC read capacity10 state */
MSC_READ_INQUIRY, /*!< MSC read inquiry state */
MSC_REQUEST_SENSE, /*!< MSC request sense state */
MSC_READ, /*!< MSC read state */
MSC_WRITE, /*!< MSC write state */
MSC_UNRECOVERED_ERROR, /*!< MSC unrecovered state */
MSC_PERIODIC_CHECK /*!< MSC periodic check state */
} msc_state;
/* MSC error types */
typedef enum {
MSC_OK = 0U, /*!< MSC no error */
MSC_NOT_READY, /*!< MSC not ready */
MSC_ERROR /*!< MSC error */
} msc_error;
/* MSC request types */
typedef enum {
MSC_REQ_IDLE = 0U, /*!< MSC idle request state */
MSC_REQ_RESET, /*!< MSC reset request state */
MSC_REQ_GET_MAX_LUN, /*!< MSC get maximum LUN request state */
MSC_REQ_ERROR /*!< MSC error request state */
} msc_req_state;
/* structure for LUN */
typedef struct {
msc_state state; /*!< MSC LUN state */
msc_error error; /*!< MSC LUN error */
msc_scsi_sense sense; /*!< MSC SCSI sense */
scsi_capacity capacity; /*!< MSC SCSI capacity */
scsi_std_inquiry_data inquiry; /*!< MSC SCSI standard inquiry data */
usbh_status prev_ready_state; /*!< MSC previous ready state */
uint8_t state_changed; /*!< MSC state changed */
} msc_lun;
/* structure for MSC process */
typedef struct _msc_process {
uint8_t pipe_in; /*!< MSC pipe IN */
uint8_t pipe_out; /*!< MSC pipe OUT */
uint8_t ep_in; /*!< MSC endpoint IN */
uint8_t ep_out; /*!< MSC endpoint OUT */
uint16_t ep_size_in; /*!< MSC endpoint IN size */
uint16_t ep_size_out; /*!< MSC endpoint OUT size */
uint8_t cur_lun; /*!< MSC current LUN */
uint16_t rw_lun; /*!< MSC review LUN */
uint32_t max_lun; /*!< MSC maximum LUN */
msc_state state; /*!< MSC state */
msc_error error; /*!< MSC error */
msc_req_state req_state; /*!< MSC request state */
msc_req_state prev_req_state; /*!< MSC previous request state */
bbb_handle bbb; /*!< MSC BBB correlation parameter handle */
msc_lun unit[MSC_MAX_SUPPORTED_LUN]; /*!< MSC LUN unit buff */
uint32_t timer; /*!< MSC read/write timer */
} usbh_msc_handler;
extern usbh_class usbh_msc;
/* function declarations */
/* get MSC logic unit information */
usbh_status usbh_msc_lun_info_get(usbh_host *uhost, uint8_t lun, msc_lun *info);
/* MSC read interface */
usbh_status usbh_msc_read(usbh_host *uhost, \
uint8_t lun, \
uint32_t address, \
uint8_t *pbuf, \
uint32_t length);
/* MSC write interface */
usbh_status usbh_msc_write(usbh_host *uhost, \
uint8_t lun, \
uint32_t address, \
uint8_t *pbuf, \
uint32_t length);
#endif /* USBH_MSC_CORE_H */
@@ -0,0 +1,97 @@
/*!
\file usbh_msc_scsi.h
\brief header file for usbh_msc_scsi.c
\version 2025-01-24, V1.4.0, firmware for GD32H7xx
*/
/*
Copyright (c) 2025, 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_core.h"
#define DESC_REQUEST_SENSE 00U /*!< sense request descriptor */
#define ALLOCATION_LENGTH_REQUEST_SENSE 63U /*!< sense request allocation length */
#define XFER_LEN_MODE_SENSE6 63U /*!< MSC sense6 mode transfer length */
#define MASK_MODE_SENSE_WRITE_PROTECT 0x80U /*!< sense write protect mask mode */
#define MODE_SENSE_PAGE_CONTROL_FIELD 0x00U /*!< sense page control field mode */
#define MODE_SENSE_PAGE_CODE 0x3FU /*!< sense page code mode */
#define DISK_WRITE_PROTECTED 0x01U /*!< disk write protected */
/* capacity data */
typedef struct {
uint32_t block_nbr; /*!< MSC SCSI block number */
uint16_t block_size; /*!< MSC SCSI block size */
} scsi_capacity;
/* inquiry data */
typedef struct {
uint8_t peripheral_qualifier; /*!< MSC SCSI standard peripheral qualifier */
uint8_t device_type; /*!< MSC SCSI standard inquiry device types */
uint8_t removable_media; /*!< MSC SCSI standard inquiry removable media */
uint8_t vendor_id[9]; /*!< MSC SCSI standard inquiry vendor id buff */
uint8_t product_id[17]; /*!< MSC SCSI standard inquiry product id buff */
uint8_t revision_id[5]; /*!< MSC SCSI standard inquiry revision id buff */
} scsi_std_inquiry_data;
typedef struct {
uint32_t msc_capacity; /*!< MSC capacity */
uint32_t msc_sense_key; /*!< MSC sense key */
uint16_t msc_page_len; /*!< MSC memory page length */
uint8_t msc_write_protect; /*!< MSC write protect */
}usbh_msc_parameter;
/* function declarations */
/* send 'inquiry' command to the device */
usbh_status usbh_msc_scsi_inquiry(usbh_host *uhost, uint8_t lun, scsi_std_inquiry_data *inquiry);
/* send 'test unit ready' command to the device */
usbh_status usbh_msc_test_unitready(usbh_host *uhost, uint8_t lun);
/* send the read capacity command to the device */
usbh_status usbh_msc_read_capacity10(usbh_host *uhost, uint8_t lun, scsi_capacity *capacity);
/* send the mode sense6 command to the device */
usbh_status usbh_msc_mode_sense6(usbh_host *uhost, uint8_t lun);
/* send the request sense command to the device */
usbh_status usbh_msc_request_sense(usbh_host *uhost, uint8_t lun, msc_scsi_sense *sense_data);
/* send the write10 command to the device */
usbh_status usbh_msc_write10(usbh_host *uhost, \
uint8_t lun, \
uint8_t *data_buf, \
uint32_t addr, \
uint32_t byte_num);
/* send the read10 command to the device */
usbh_status usbh_msc_read10(usbh_host *uhost, \
uint8_t lun, \
uint8_t *data_buf, \
uint32_t addr, \
uint32_t byte_num);
#endif /* USBH_MSC_SCSI_H */