gd32f1x0_dbg.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*!
  2. \file gd32f1x0_dbg.h
  3. \brief definitions for the DBG
  4. \version 2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
  5. \version 2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
  6. \version 2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
  7. \version 2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
  8. \version 2019-11-20, V3.2.0, firmware update for GD32F1x0(x=3,5,7,9)
  9. */
  10. /*
  11. Copyright (c) 2019, 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 GD32F1X0_DBG_H
  34. #define GD32F1X0_DBG_H
  35. #include "gd32f1x0.h"
  36. /* DBG definitions */
  37. #define DBG DBG_BASE
  38. /* registers definitions */
  39. #define DBG_ID REG32(DBG + 0x00000000U) /*!< DBG_ID code register */
  40. #define DBG_CTL0 REG32(DBG + 0x00000004U) /*!< DBG control register 0 */
  41. #define DBG_CTL1 REG32(DBG + 0x00000008U) /*!< DBG control register 1 */
  42. /* bits definitions */
  43. /* DBG_ID */
  44. #define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
  45. /* DBG_CTL0 */
  46. #define DBG_CTL0_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */
  47. #define DBG_CTL0_DSLP_HOLD BIT(1) /*!< keep debugger connection during deepsleep mode */
  48. #define DBG_CTL0_STB_HOLD BIT(2) /*!< keep debugger connection during standby mode */
  49. #define DBG_CTL0_FWDGT_HOLD BIT(8) /*!< debug FWDGT kept when core is halted */
  50. #define DBG_CTL0_WWDGT_HOLD BIT(9) /*!< debug WWDGT kept when core is halted */
  51. #define DBG_CTL0_TIMER0_HOLD BIT(10) /*!< TIMER0 counter kept when core is halted */
  52. #define DBG_CTL0_TIMER1_HOLD BIT(11) /*!< TIMER1 counter kept when core is halted */
  53. #define DBG_CTL0_TIMER2_HOLD BIT(12) /*!< TIMER2 counter kept when core is halted */
  54. #define DBG_CTL0_I2C0_HOLD BIT(15) /*!< hold I2C0 smbus when core is halted */
  55. #define DBG_CTL0_I2C1_HOLD BIT(16) /*!< hold I2C1 smbus when core is halted */
  56. #define DBG_CTL0_I2C2_HOLD BIT(17) /*!< hold I2C2 smbus when core is halted */
  57. #ifdef GD32F170_190
  58. #define DBG_CTL0_CAN0_HOLD BIT(18) /*!< CAN0 counter kept when core is halted */
  59. #endif /* GD32F170_190 */
  60. #define DBG_CTL0_TIMER5_HOLD BIT(19) /*!< hold TIMER5 counter when core is halted */
  61. #ifdef GD32F170_190
  62. #define DBG_CTL0_CAN1_HOLD BIT(21) /*!< hold CAN1 counter when core is halted */
  63. #endif /* GD32F170_190 */
  64. #define DBG_CTL0_TIMER13_HOLD BIT(27) /*!< hold TIMER13 counter when core is halted */
  65. /* DBG_CTL1 */
  66. #define DBG_CTL1_RTC_HOLD BIT(10) /*!< hold RTC calendar and wakeup counter when core is halted */
  67. #define DBG_CTL1_TIMER14_HOLD BIT(16) /*!< hold TIMER14 counter when core is halted */
  68. #define DBG_CTL1_TIMER15_HOLD BIT(17) /*!< hold TIMER15 counter when core is halted */
  69. #define DBG_CTL1_TIMER16_HOLD BIT(18) /*!< hold TIMER16 counter when core is halted */
  70. /* constants definitions */
  71. #define DBG_LOW_POWER_SLEEP DBG_CTL0_SLP_HOLD /*!< keep debugger connection during sleep mode */
  72. #define DBG_LOW_POWER_DEEPSLEEP DBG_CTL0_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */
  73. #define DBG_LOW_POWER_STANDBY DBG_CTL0_STB_HOLD /*!< keep debugger connection during standby mode */
  74. /* define the peripheral debug hold bit position and its register index offset */
  75. #define DBG_REGIDX_BIT(regidx, bitpos) (((regidx) << 6) | (bitpos))
  76. #define DBG_REG_VAL(periph) (REG32(DBG + ((uint32_t)(periph) >> 6)))
  77. #define DBG_BIT_POS(val) ((uint32_t)(val) & 0x0000001FU)
  78. /* register index */
  79. typedef enum
  80. {
  81. DBG_IDX_CTL0 = 0x04U, /*!< DBG control register 0 offset */
  82. DBG_IDX_CTL1 = 0x08U, /*!< DBG control register 1 offset */
  83. }dbg_reg_idx;
  84. /* peripherals hold bit */
  85. typedef enum
  86. {
  87. DBG_FWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 8U), /*!< FWDGT hold bit */
  88. DBG_WWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 9U), /*!< WWDGT hold bit */
  89. DBG_TIMER0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 10U), /*!< TIMER0 hold bit */
  90. DBG_TIMER1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 11U), /*!< TIMER1 hold bit */
  91. DBG_TIMER2_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 12U), /*!< TIMER2 hold bit */
  92. #ifdef GD32F170_190
  93. DBG_CAN0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 14U), /*!< CAN0 hold bit */
  94. #endif /* GD32F170_190 */
  95. DBG_I2C0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 15U), /*!< I2C0 hold bit */
  96. DBG_I2C1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 16U), /*!< I2C1 hold bit */
  97. DBG_I2C2_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 17U), /*!< I2C2 hold bit */
  98. DBG_TIMER5_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 19U), /*!< TIMER5 hold bit */
  99. #ifdef GD32F170_190
  100. DBG_CAN1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 21U), /*!< CAN1 hold bit */
  101. #endif /* GD32F170_190 */
  102. DBG_TIMER13_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 27U), /*!< TIMER13 hold bit */
  103. DBG_RTC_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 10U), /*!< RTC hold bit */
  104. DBG_TIMER14_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 16U), /*!< TIMER14 hold bit */
  105. DBG_TIMER15_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 17U), /*!< TIMER15 hold bit */
  106. DBG_TIMER16_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 18U), /*!< TIMER16 hold bit */
  107. }dbg_periph_enum;
  108. /* function declarations */
  109. /* deinitialize the DBG */
  110. void dbg_deinit(void);
  111. /* read DBG_ID code register */
  112. uint32_t dbg_id_get(void);
  113. /* enable low power behavior when the MCU is in debug mode */
  114. void dbg_low_power_enable(uint32_t dbg_low_power);
  115. /* disable low power behavior when the MCU is in debug mode */
  116. void dbg_low_power_disable(uint32_t dbg_low_power);
  117. /* enable peripheral behavior when the MCU is in debug mode */
  118. void dbg_periph_enable(dbg_periph_enum dbg_periph);
  119. /* disable peripheral behavior when the MCU is in debug mode */
  120. void dbg_periph_disable(dbg_periph_enum dbg_periph);
  121. #endif /* GD32F1X0_DBG_H */