usb_conf.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*!
  2. \file usb_conf.h
  3. \brief USB core driver basic configuration
  4. \version 2023-06-30, V2.1.6, firmware for GD32F30x
  5. */
  6. /*
  7. Copyright (c) 2023, GigaDevice Semiconductor Inc.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice, this
  11. list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright notice,
  13. this list of conditions and the following disclaimer in the documentation
  14. and/or other materials provided with the distribution.
  15. 3. Neither the name of the copyright holder nor the names of its contributors
  16. may be used to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #ifndef __USB_CONF_H
  30. #define __USB_CONF_H
  31. #include <stdio.h>
  32. #include "gd32f30x.h"
  33. #include "gd32f307c_eval.h"
  34. /* USB Core and PHY interface configuration */
  35. /****************** USB FS PHY CONFIGURATION *******************************
  36. * The USB FS Core supports one on-chip Full Speed PHY.
  37. * The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor
  38. * when FS core is used.
  39. *******************************************************************************/
  40. #ifdef USE_USB_FS
  41. #define USB_FS_CORE
  42. #endif
  43. /*******************************************************************************
  44. * FIFO Size Configuration in Device mode
  45. *
  46. * (i) Receive data FIFO size = RAM for setup packets +
  47. * OUT endpoint control information +
  48. * data OUT packets + miscellaneous
  49. * Space = ONE 32-bits words
  50. * --> RAM for setup packets = 10 spaces
  51. * (n is the nbr of CTRL EPs the device core supports)
  52. * --> OUT EP CTRL info = 1 space
  53. * (one space for status information written to the FIFO along with each
  54. * received packet)
  55. * --> Data OUT packets = (Largest Packet Size / 4) + 1 spaces
  56. * (MINIMUM to receive packets)
  57. * --> OR data OUT packets = at least 2* (Largest Packet Size / 4) + 1 spaces
  58. * (if high-bandwidth EP is enabled or multiple isochronous EPs)
  59. * --> Miscellaneous = 1 space per OUT EP
  60. * (one space for transfer complete status information also pushed to the
  61. * FIFO with each endpoint's last packet)
  62. *
  63. * (ii) MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
  64. * that particular IN EP. More space allocated in the IN EP Tx FIFO results
  65. * in a better performance on the USB and can hide latencies on the AHB.
  66. *
  67. * (iii) TXn min size = 16 words. (n:Transmit FIFO index)
  68. *
  69. * (iv) When a TxFIFO is not used, the Configuration should be as follows:
  70. * case 1: n > m and Txn is not used (n,m:Transmit FIFO indexes)
  71. * --> Txm can use the space allocated for Txn.
  72. * case 2: n < m and Txn is not used (n,m:Transmit FIFO indexes)
  73. * --> Txn should be configured with the minimum space of 16 words
  74. *
  75. * (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
  76. * of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
  77. *******************************************************************************/
  78. #ifdef USB_FS_CORE
  79. #define RX_FIFO_FS_SIZE 128U
  80. #define TX0_FIFO_FS_SIZE 64U
  81. #define TX1_FIFO_FS_SIZE 128U
  82. #define TX2_FIFO_FS_SIZE 0U
  83. #define TX3_FIFO_FS_SIZE 0U
  84. #endif /* USB_FS_CORE */
  85. #define USB_SOF_OUTPUT 1U
  86. #define USB_LOW_POWER 0U
  87. //#define VBUS_SENSING_ENABLED
  88. //#define USE_HOST_MODE
  89. #define USE_DEVICE_MODE
  90. //#define USE_OTG_MODE
  91. #ifndef USE_DEVICE_MODE
  92. #ifndef USE_HOST_MODE
  93. #error "USE_DEVICE_MODE or USE_HOST_MODE should be defined!"
  94. #endif
  95. #endif
  96. #define __ALIGN_BEGIN
  97. #define __ALIGN_END
  98. /* __packed keyword used to decrease the data type alignment to 1-byte */
  99. #if defined (__GNUC__) /* GNU Compiler */
  100. #define __packed __attribute__ ((__packed__))
  101. #elif defined (__TASKING__) /* TASKING Compiler */
  102. #define __packed __unaligned
  103. #endif /* __CC_ARM */
  104. #endif /* __USB_CONF_H */