添加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,100 @@
/*!
\file usbd_msc_bbb.h
\brief the header file of the usbd_msc_bot.c file
\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 USBD_MSC_BBB_H
#define USBD_MSC_BBB_H
#include "msc_bbb.h"
#include "msc_scsi.h"
#include "usbd_msc_scsi.h"
/* MSC BBB state */
enum msc_bbb_state {
BBB_IDLE = 0U, /*!< idle state */
BBB_DATA_OUT, /*!< data OUT state */
BBB_DATA_IN, /*!< data IN state */
BBB_LAST_DATA_IN, /*!< last data IN state */
BBB_SEND_DATA /*!< send immediate data state */
};
/* MSC BBB status */
enum msc_bbb_status {
BBB_STATUS_NORMAL = 0U, /*!< normal status */
BBB_STATUS_RECOVERY, /*!< recovery status*/
BBB_STATUS_ERROR /*!< error status */
};
typedef struct {
__ALIGN_BEGIN uint8_t bbb_data[MSC_MEDIA_PACKET_SIZE] __ALIGN_END; /*!< MSC BBB data buff */
uint8_t max_lun; /*!< maximum LUN */
uint8_t bbb_state; /*!< BBB state */
uint8_t bbb_status; /*!< BBB status */
uint32_t bbb_datalen; /*!< BBB data length */
__ALIGN_BEGIN msc_bbb_cbw bbb_cbw __ALIGN_END; /*!< MSC BBB CBW structural */
__ALIGN_BEGIN msc_bbb_csw bbb_csw __ALIGN_END; /*!< MSC BBB CSW structural */
uint8_t scsi_sense_head; /*!< SCSI sense header */
uint8_t scsi_sense_tail; /*!< SCSI sense tail */
uint32_t scsi_blk_size[MEM_LUN_NUM]; /*!< SCSI block size */
uint32_t scsi_blk_nbr[MEM_LUN_NUM]; /*!< SCSI block number */
uint32_t scsi_blk_addr; /*!< SCSI block address */
uint32_t scsi_blk_len; /*!< SCSI block length */
uint32_t scsi_disk_pop; /*!< SCSI disk pop */
__ALIGN_BEGIN msc_scsi_sense scsi_sense[SENSE_LIST_DEEPTH] __ALIGN_END; /*!< MSC SCSI sense structural buffer */
} usbd_msc_handler;
/* function declarations */
/* initialize the BBB process */
void msc_bbb_init(usb_core_driver *udev);
/* reset the BBB machine */
void msc_bbb_reset(usb_core_driver *udev);
/* deinitialize the BBB machine */
void msc_bbb_deinit(usb_core_driver *udev);
/* handle BBB data IN stage */
void msc_bbb_data_in(usb_core_driver *udev, uint8_t ep_num);
/* handle BBB data OUT stage */
void msc_bbb_data_out(usb_core_driver *udev, uint8_t ep_num);
/* send the CSW(command status wrapper) */
void msc_bbb_csw_send(usb_core_driver *udev, uint8_t csw_status);
/* complete the clear feature request */
void msc_bbb_clrfeature(usb_core_driver *udev, uint8_t ep_num);
#endif /* USBD_MSC_BBB_H */
@@ -0,0 +1,58 @@
/*!
\file usbd_msc_core.h
\brief the header file of USB MSC device class core functions
\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 USBD_MSC_CORE_H
#define USBD_MSC_CORE_H
#include "usbd_core.h"
#include "usb_msc.h"
#define USB_MSC_CONFIG_DESC_SIZE 32U /*!< MSC configuration descriptor size */
#define MSC_EPIN_SIZE MSC_DATA_PACKET_SIZE /*!< MSC endpoint IN size */
#define MSC_EPOUT_SIZE MSC_DATA_PACKET_SIZE /*!< MSC endpoint OUT size */
/* USB configuration descriptor structure */
typedef struct {
usb_desc_config config; /*!< configuration descriptor */
usb_desc_itf msc_itf; /*!< interface descriptor */
usb_desc_ep msc_epin; /*!< endpoint IN descriptor */
usb_desc_ep msc_epout; /*!< endpoint OUT descriptor */
} usb_desc_config_set;
extern usb_desc msc_desc;
extern usb_class_core msc_class;
#endif /* USBD_MSC_CORE_H */
@@ -0,0 +1,58 @@
/*!
\file usbd_msc_mem.h
\brief header file for storage memory
\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 USBD_MSC_MEM_H
#define USBD_MSC_MEM_H
#include "usbd_conf.h"
#define USBD_STD_INQUIRY_LENGTH 36U /*!< standard inquiry length */
typedef struct {
int8_t (*mem_init)(uint8_t lun);
int8_t (*mem_ready)(uint8_t lun);
int8_t (*mem_protected)(uint8_t lun);
int8_t (*mem_read)(uint8_t lun, uint8_t *buf, uint32_t block_addr, uint16_t block_len);
int8_t (*mem_write)(uint8_t lun, uint8_t *buf, uint32_t block_addr, uint16_t block_len);
int8_t (*mem_maxlun)(void);
uint8_t *mem_toc_data; /*!< memory TOC command data pointer */
uint8_t *mem_inquiry_data[MEM_LUN_NUM]; /*!< memory inquiry data buff */
uint32_t mem_block_size[MEM_LUN_NUM]; /*!< memory block size buff */
uint32_t mem_block_len[MEM_LUN_NUM]; /*!< memory block length buff */
}usbd_mem_cb;
extern usbd_mem_cb *usbd_mem_fops;
#endif /* USBD_MSC_MEM_H */
@@ -0,0 +1,53 @@
/*!
\file usbd_msc_scsi.h
\brief the header file of the usbd_msc_scsi.c file
\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 USBD_MSC_SCSI_H
#define USBD_MSC_SCSI_H
#include "usbd_core.h"
#define SENSE_LIST_DEEPTH 4U /*!< sense list deepth */
#define MODE_SENSE6_LENGTH 8U /*!< sense6 mode length */
#define MODE_SENSE10_LENGTH 8U /*!< sense10 mode length */
#define INQUIRY_PAGE00_LENGTH 96U /*!< sense page 0 inquiry length */
#define FORMAT_CAPACITIES_LENGTH 20U /*!< format capacities length */
/* function declarations */
/* process SCSI commands */
int8_t scsi_process_cmd(usb_core_driver *udev, uint8_t lun, uint8_t *cmd);
/* load the last error code in the error list */
void scsi_sense_code(usb_core_driver *udev, uint8_t lun, uint8_t skey, uint8_t asc);
#endif /* USBD_MSC_SCSI_H */