gd32f30x_dbg.c 5.4 KB

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