gd32f30x_dbg.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*!
  2. \file gd32f30x_dbg.c
  3. \brief DBG driver
  4. \version 2023-12-30, V2.2.0, firmware for GD32F30x
  5. */
  6. /*
  7. Copyright (c) 2020, 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. #include "gd32f30x_dbg.h"
  30. #define DBG_RESET_VAL 0x00000000U
  31. /*!
  32. \brief deinitialize the DBG
  33. \param[in] none
  34. \param[out] none
  35. \retval none
  36. */
  37. void dbg_deinit(void)
  38. {
  39. DBG_CTL0 = DBG_RESET_VAL;
  40. }
  41. /*!
  42. \brief read DBG_ID code register
  43. \param[in] none
  44. \param[out] none
  45. \retval DBG_ID code
  46. */
  47. uint32_t dbg_id_get(void)
  48. {
  49. return DBG_ID;
  50. }
  51. /*!
  52. \brief enable low power behavior when the mcu is in debug mode
  53. \param[in] dbg_low_power:
  54. this parameter can be any combination of the following values:
  55. \arg DBG_LOW_POWER_SLEEP: keep debugger connection during sleep mode
  56. \arg DBG_LOW_POWER_DEEPSLEEP: keep debugger connection during deepsleep mode
  57. \arg DBG_LOW_POWER_STANDBY: keep debugger connection during standby mode
  58. \param[out] none
  59. \retval none
  60. */
  61. void dbg_low_power_enable(uint32_t dbg_low_power)
  62. {
  63. DBG_CTL0 |= dbg_low_power;
  64. }
  65. /*!
  66. \brief disable low power behavior when the mcu is in debug mode
  67. \param[in] dbg_low_power:
  68. this parameter can be any combination of the following values:
  69. \arg DBG_LOW_POWER_SLEEP: donot keep debugger connection during sleep mode
  70. \arg DBG_LOW_POWER_DEEPSLEEP: donot keep debugger connection during deepsleep mode
  71. \arg DBG_LOW_POWER_STANDBY: donot keep debugger connection during standby mode
  72. \param[out] none
  73. \retval none
  74. */
  75. void dbg_low_power_disable(uint32_t dbg_low_power)
  76. {
  77. DBG_CTL0 &= ~dbg_low_power;
  78. }
  79. /*!
  80. \brief enable peripheral behavior when the mcu is in debug mode
  81. \param[in] dbg_periph: refer to dbg_periph_enum
  82. only one parameter can be selected which is shown as below:
  83. \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
  84. \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
  85. \arg DBG_CANx_HOLD (x=0,1,CAN1 is only available for CL series): hold CANx counter when core is halted
  86. \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
  87. \arg DBG_TIMERx_HOLD (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13,TIMER8..13 are not available for HD series): hold TIMERx counter when core is halted
  88. \param[out] none
  89. \retval none
  90. */
  91. void dbg_periph_enable(dbg_periph_enum dbg_periph)
  92. {
  93. DBG_REG_VAL(dbg_periph) |= BIT(DBG_BIT_POS(dbg_periph));
  94. }
  95. /*!
  96. \brief disable peripheral behavior when the mcu is in debug mode
  97. \param[in] dbg_periph: refer to dbg_periph_enum
  98. only one parameter can be selected which is shown as below:
  99. \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
  100. \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
  101. \arg DBG_CANx_HOLD (x=0,1,CAN1 is only available for CL series): hold CAN0 counter when core is halted
  102. \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
  103. \arg DBG_TIMERx_HOLD (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13,TIMER8..13 are not available for HD series): hold TIMERx counter when core is halted
  104. \param[out] none
  105. \retval none
  106. */
  107. void dbg_periph_disable(dbg_periph_enum dbg_periph)
  108. {
  109. DBG_REG_VAL(dbg_periph) &= ~BIT(DBG_BIT_POS(dbg_periph));
  110. }
  111. /*!
  112. \brief enable trace pin assignment
  113. \param[in] none
  114. \param[out] none
  115. \retval none
  116. */
  117. void dbg_trace_pin_enable(void)
  118. {
  119. DBG_CTL0 |= DBG_CTL0_TRACE_IOEN;
  120. }
  121. /*!
  122. \brief disable trace pin assignment
  123. \param[in] none
  124. \param[out] none
  125. \retval none
  126. */
  127. void dbg_trace_pin_disable(void)
  128. {
  129. DBG_CTL0 &= ~DBG_CTL0_TRACE_IOEN;
  130. }