gd32f30x_dbg.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*!
  2. \file gd32f30x_dbg.h
  3. \brief definitions for the DBG
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #ifndef GD32F30X_DBG_H
  33. #define GD32F30X_DBG_H
  34. #include "gd32f30x.h"
  35. /* DBG definitions */
  36. #define DBG DBG_BASE
  37. /* registers definitions */
  38. #define DBG_ID REG32(DBG + 0x00U) /*!< DBG_ID code register */
  39. #define DBG_CTL0 REG32(DBG + 0x04U) /*!< DBG control register 0 */
  40. /* bits definitions */
  41. /* DBG_ID */
  42. #define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
  43. /* DBG_CTL0 */
  44. #define DBG_CTL0_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */
  45. #define DBG_CTL0_DSLP_HOLD BIT(1) /*!< keep debugger connection during deepsleep mode */
  46. #define DBG_CTL0_STB_HOLD BIT(2) /*!< keep debugger connection during standby mode */
  47. #define DBG_CTL0_TRACE_IOEN BIT(5) /*!< enable trace pin assignment */
  48. #define DBG_CTL0_FWDGT_HOLD BIT(8) /*!< debug FWDGT kept when core is halted */
  49. #define DBG_CTL0_WWDGT_HOLD BIT(9) /*!< debug WWDGT kept when core is halted */
  50. #define DBG_CTL0_TIMER0_HOLD BIT(10) /*!< hold TIMER0 counter when core is halted */
  51. #define DBG_CTL0_TIMER1_HOLD BIT(11) /*!< hold TIMER1 counter when core is halted */
  52. #define DBG_CTL0_TIMER2_HOLD BIT(12) /*!< hold TIMER2 counter when core is halted */
  53. #define DBG_CTL0_TIMER3_HOLD BIT(13) /*!< hold TIMER3 counter when core is halted */
  54. #define DBG_CTL0_CAN0_HOLD BIT(14) /*!< debug CAN0 kept when core is halted */
  55. #define DBG_CTL0_I2C0_HOLD BIT(15) /*!< hold I2C0 smbus when core is halted */
  56. #define DBG_CTL0_I2C1_HOLD BIT(16) /*!< hold I2C1 smbus when core is halted */
  57. #define DBG_CTL0_TIMER7_HOLD BIT(17) /*!< hold TIMER7 counter when core is halted */
  58. #define DBG_CTL0_TIMER4_HOLD BIT(18) /*!< hold TIMER4 counter when core is halted */
  59. #define DBG_CTL0_TIMER5_HOLD BIT(19) /*!< hold TIMER5 counter when core is halted */
  60. #define DBG_CTL0_TIMER6_HOLD BIT(20) /*!< hold TIMER6 counter when core is halted */
  61. #ifdef GD32F30X_CL
  62. #define DBG_CTL0_CAN1_HOLD BIT(21) /*!< debug CAN1 kept when core is halted */
  63. #endif /* GD32F30X_CL */
  64. #ifndef GD32F30X_HD
  65. #define DBG_CTL0_TIMER11_HOLD BIT(25) /*!< hold TIMER11 counter when core is halted */
  66. #define DBG_CTL0_TIMER12_HOLD BIT(26) /*!< hold TIMER12 counter when core is halted */
  67. #define DBG_CTL0_TIMER13_HOLD BIT(27) /*!< hold TIMER13 counter when core is halted */
  68. #define DBG_CTL0_TIMER8_HOLD BIT(28) /*!< hold TIMER8 counter when core is halted */
  69. #define DBG_CTL0_TIMER9_HOLD BIT(29) /*!< hold TIMER9 counter when core is halted */
  70. #define DBG_CTL0_TIMER10_HOLD BIT(30) /*!< hold TIMER10 counter when core is halted */
  71. #endif /* GD32F30X_HD */
  72. /* constants definitions */
  73. #define DBG_LOW_POWER_SLEEP DBG_CTL0_SLP_HOLD /*!< keep debugger connection during sleep mode */
  74. #define DBG_LOW_POWER_DEEPSLEEP DBG_CTL0_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */
  75. #define DBG_LOW_POWER_STANDBY DBG_CTL0_STB_HOLD /*!< keep debugger connection during standby mode */
  76. /* define the peripheral debug hold bit position and its register index offset */
  77. #define DBG_REGIDX_BIT(regidx, bitpos) (((regidx) << 6) | (bitpos))
  78. #define DBG_REG_VAL(periph) (REG32(DBG + ((uint32_t)(periph) >> 6)))
  79. #define DBG_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
  80. /* register index */
  81. enum dbg_reg_idx
  82. {
  83. DBG_IDX_CTL0 = 0x04U
  84. };
  85. typedef enum
  86. {
  87. DBG_FWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 8U), /*!< debug FWDGT kept when core is halted */
  88. DBG_WWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 9U), /*!< debug WWDGT kept when core is halted */
  89. DBG_TIMER0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 10U), /*!< hold TIMER0 counter when core is halted */
  90. DBG_TIMER1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 11U), /*!< hold TIMER1 counter when core is halted */
  91. DBG_TIMER2_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 12U), /*!< hold TIMER2 counter when core is halted */
  92. DBG_TIMER3_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 13U), /*!< hold TIMER3 counter when core is halted */
  93. DBG_CAN0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 14U), /*!< debug CAN0 kept when core is halted */
  94. DBG_I2C0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 15U), /*!< hold I2C0 smbus when core is halted */
  95. DBG_I2C1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 16U), /*!< hold I2C1 smbus when core is halted */
  96. DBG_TIMER7_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 17U), /*!< hold TIMER7 counter when core is halted */
  97. DBG_TIMER4_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 18U), /*!< hold TIMER4 counter when core is halted */
  98. DBG_TIMER5_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 19U), /*!< hold TIMER5 counter when core is halted */
  99. DBG_TIMER6_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 20U), /*!< hold TIMER6 counter when core is halted */
  100. #ifdef GD32F30X_CL
  101. DBG_CAN1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 21U), /*!< debug CAN1 kept when core is halted */
  102. #endif /* GD32F30X_CL */
  103. #ifndef GD32F30X_HD
  104. DBG_TIMER11_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 25U), /*!< hold TIMER11 counter when core is halted */
  105. DBG_TIMER12_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 26U), /*!< hold TIMER12 counter when core is halted */
  106. DBG_TIMER13_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 27U), /*!< hold TIMER13 counter when core is halted */
  107. DBG_TIMER8_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 28U), /*!< hold TIMER8 counter when core is halted */
  108. DBG_TIMER9_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 29U), /*!< hold TIMER9 counter when core is halted */
  109. DBG_TIMER10_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 30U), /*!< hold TIMER10 counter when core is halted */
  110. #endif /* GD32F30X_HD */
  111. }dbg_periph_enum;
  112. /* function declarations */
  113. /* deinitialize the DBG */
  114. void dbg_deinit(void);
  115. /* read DBG_ID code register */
  116. uint32_t dbg_id_get(void);
  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. /* enable peripheral behavior when the MCU is in debug mode */
  122. void dbg_periph_enable(dbg_periph_enum dbg_periph);
  123. /* disable peripheral behavior when the MCU is in debug mode */
  124. void dbg_periph_disable(dbg_periph_enum dbg_periph);
  125. /* enable trace pin assignment */
  126. void dbg_trace_pin_enable(void);
  127. /* disable trace pin assignment */
  128. void dbg_trace_pin_disable(void);
  129. #endif /* GD32F30X_DBG_H */