gd32f10x_dbg.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*!
  2. \file gd32f10x_dbg.h
  3. \brief definitions for the DBG
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2019-07-01, V2.1.1, firmware for GD32F10x
  8. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  9. */
  10. /*
  11. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  12. Redistribution and use in source and binary forms, with or without modification,
  13. are permitted provided that the following conditions are met:
  14. 1. Redistributions of source code must retain the above copyright notice, this
  15. list of conditions and the following disclaimer.
  16. 2. Redistributions in binary form must reproduce the above copyright notice,
  17. this list of conditions and the following disclaimer in the documentation
  18. and/or other materials provided with the distribution.
  19. 3. Neither the name of the copyright holder nor the names of its contributors
  20. may be used to endorse or promote products derived from this software without
  21. specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  26. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  31. OF SUCH DAMAGE.
  32. */
  33. #ifndef GD32F10X_DBG_H
  34. #define GD32F10X_DBG_H
  35. #include "gd32f10x.h"
  36. /* DBG definitions */
  37. #define DBG DBG_BASE
  38. /* registers definitions */
  39. #define DBG_ID REG32(DBG + 0x00U) /*!< DBG_ID code register */
  40. #define DBG_CTL REG32(DBG + 0x04U) /*!< DBG control register */
  41. /* bits definitions */
  42. /* DBG_ID */
  43. #define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
  44. /* DBG_CTL */
  45. #define DBG_CTL_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */
  46. #define DBG_CTL_DSLP_HOLD BIT(1) /*!< keep debugger connection during deepsleep mode */
  47. #define DBG_CTL_STB_HOLD BIT(2) /*!< keep debugger connection during standby mode */
  48. #define DBG_CTL_TRACE_IOEN BIT(5) /*!< enable trace pin assignment */
  49. #define DBG_CTL_TRACE_MODE BITS(6,7) /*!< trace pin mode selection */
  50. #define DBG_CTL_FWDGT_HOLD BIT(8) /*!< debug FWDGT kept when core is halted */
  51. #define DBG_CTL_WWDGT_HOLD BIT(9) /*!< debug WWDGT kept when core is halted */
  52. #define DBG_CTL_TIMER0_HOLD BIT(10) /*!< hold TIMER0 counter when core is halted */
  53. #define DBG_CTL_TIMER1_HOLD BIT(11) /*!< hold TIMER1 counter when core is halted */
  54. #define DBG_CTL_TIMER2_HOLD BIT(12) /*!< hold TIMER2 counter when core is halted */
  55. #define DBG_CTL_TIMER3_HOLD BIT(13) /*!< hold TIMER3 counter when core is halted */
  56. #define DBG_CTL_CAN0_HOLD BIT(14) /*!< debug CAN0 kept when core is halted */
  57. #define DBG_CTL_I2C0_HOLD BIT(15) /*!< hold I2C0 smbus when core is halted */
  58. #define DBG_CTL_I2C1_HOLD BIT(16) /*!< hold I2C1 smbus when core is halted */
  59. #define DBG_CTL_TIMER7_HOLD BIT(17) /*!< hold TIMER7 counter when core is halted */
  60. #define DBG_CTL_TIMER4_HOLD BIT(18) /*!< hold TIMER4 counter when core is halted */
  61. #define DBG_CTL_TIMER5_HOLD BIT(19) /*!< hold TIMER5 counter when core is halted */
  62. #define DBG_CTL_TIMER6_HOLD BIT(20) /*!< hold TIMER6 counter when core is halted */
  63. #ifdef GD32F10X_CL
  64. #define DBG_CTL_CAN1_HOLD BIT(21) /*!< debug CAN1 kept when core is halted */
  65. #endif /* GD32F10X_CL */
  66. #ifdef GD32F10X_XD
  67. #define DBG_CTL_TIMER11_HOLD BIT(25) /*!< hold TIMER11 counter when core is halted */
  68. #define DBG_CTL_TIMER12_HOLD BIT(26) /*!< hold TIMER12 counter when core is halted */
  69. #define DBG_CTL_TIMER13_HOLD BIT(27) /*!< hold TIMER13 counter when core is halted */
  70. #define DBG_CTL_TIMER8_HOLD BIT(28) /*!< hold TIMER8 counter when core is halted */
  71. #define DBG_CTL_TIMER9_HOLD BIT(29) /*!< hold TIMER9 counter when core is halted */
  72. #define DBG_CTL_TIMER10_HOLD BIT(30) /*!< hold TIMER10 counter when core is halted */
  73. #endif /* GD32F10X_XD */
  74. /* constants definitions */
  75. /* debug hold when core is halted */
  76. typedef enum
  77. {
  78. DBG_FWDGT_HOLD = BIT(8), /*!< debug FWDGT kept when core is halted */
  79. DBG_WWDGT_HOLD = BIT(9), /*!< debug WWDGT kept when core is halted */
  80. DBG_TIMER0_HOLD = BIT(10), /*!< hold TIMER0 counter when core is halted */
  81. DBG_TIMER1_HOLD = BIT(11), /*!< hold TIMER1 counter when core is halted */
  82. DBG_TIMER2_HOLD = BIT(12), /*!< hold TIMER2 counter when core is halted */
  83. DBG_TIMER3_HOLD = BIT(13), /*!< hold TIMER3 counter when core is halted */
  84. DBG_CAN0_HOLD = BIT(14), /*!< debug CAN0 kept when core is halted */
  85. DBG_I2C0_HOLD = BIT(15), /*!< hold I2C0 smbus when core is halted */
  86. DBG_I2C1_HOLD = BIT(16), /*!< hold I2C1 smbus when core is halted */
  87. DBG_TIMER7_HOLD = BIT(17), /*!< hold TIMER7 counter when core is halted */
  88. DBG_TIMER4_HOLD = BIT(18), /*!< hold TIMER4 counter when core is halted */
  89. DBG_TIMER5_HOLD = BIT(19), /*!< hold TIMER5 counter when core is halted */
  90. DBG_TIMER6_HOLD = BIT(20), /*!< hold TIMER6 counter when core is halted */
  91. #ifdef GD32F10X_CL
  92. DBG_CAN1_HOLD = BIT(21), /*!< debug CAN1 kept when core is halted */
  93. #endif /* GD32F10X_CL */
  94. #if (defined(GD32F10X_XD) || defined(GD32F10X_CL))
  95. DBG_TIMER11_HOLD = BIT(25), /*!< hold TIMER11 counter when core is halted */
  96. DBG_TIMER12_HOLD = BIT(26), /*!< hold TIMER12 counter when core is halted */
  97. DBG_TIMER13_HOLD = BIT(27), /*!< hold TIMER13 counter when core is halted */
  98. DBG_TIMER8_HOLD = BIT(28), /*!< hold TIMER8 counter when core is halted */
  99. DBG_TIMER9_HOLD = BIT(29), /*!< hold TIMER9 counter when core is halted */
  100. DBG_TIMER10_HOLD = BIT(30), /*!< hold TIMER10 counter when core is halted */
  101. #endif /* GD32F10X_XD || GD32F10X_CL*/
  102. }dbg_periph_enum;
  103. /* DBG low power mode configurations */
  104. #define DBG_LOW_POWER_SLEEP DBG_CTL_SLP_HOLD /*!< keep debugger connection during sleep mode */
  105. #define DBG_LOW_POWER_DEEPSLEEP DBG_CTL_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */
  106. #define DBG_LOW_POWER_STANDBY DBG_CTL_STB_HOLD /*!< keep debugger connection during standby mode */
  107. /* DBG_CTL0_TRACE_MODE configurations */
  108. #define CTL_TRACE_MODE(regval) (BITS(6,7) & ((uint32_t)(regval) << 6U))
  109. #define TRACE_MODE_ASYNC CTL_TRACE_MODE(0) /*!< trace pin used for async mode */
  110. #define TRACE_MODE_SYNC_DATASIZE_1 CTL_TRACE_MODE(1) /*!< trace pin used for sync mode and data size is 1 */
  111. #define TRACE_MODE_SYNC_DATASIZE_2 CTL_TRACE_MODE(2) /*!< trace pin used for sync mode and data size is 2 */
  112. #define TRACE_MODE_SYNC_DATASIZE_4 CTL_TRACE_MODE(3) /*!< trace pin used for sync mode and data size is 4 */
  113. /* function declarations */
  114. /* read DBG_ID code register */
  115. uint32_t dbg_id_get(void);
  116. /* low power behavior configuration */
  117. /* enable low power behavior when the MCU is in debug mode */
  118. void dbg_low_power_enable(uint32_t dbg_low_power);
  119. /* disable low power behavior when the MCU is in debug mode */
  120. void dbg_low_power_disable(uint32_t dbg_low_power);
  121. /* peripheral behavior configuration */
  122. /* enable peripheral behavior when the MCU is in debug mode */
  123. void dbg_periph_enable(dbg_periph_enum dbg_periph);
  124. /* disable peripheral behavior when the MCU is in debug mode */
  125. void dbg_periph_disable(dbg_periph_enum dbg_periph);
  126. /* trace pin assignment configuration */
  127. /* enable trace pin assignment */
  128. void dbg_trace_pin_enable(void);
  129. /* disable trace pin assignment */
  130. void dbg_trace_pin_disable(void);
  131. /* set trace pin mode */
  132. void dbg_trace_pin_mode_set(uint32_t trace_mode);
  133. #endif /* GD32F10X_DBG_H */