1
0

gd32f4xx_dbg.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*!
  2. \file gd32f4xx_dbg.c
  3. \brief DBG driver
  4. \version 2016-08-15, V1.0.0, firmware for GD32F4xx
  5. \version 2018-12-12, V2.0.0, firmware for GD32F4xx
  6. \version 2020-09-30, V2.1.0, firmware for GD32F4xx
  7. */
  8. /*
  9. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. 1. Redistributions of source code must retain the above copyright notice, this
  13. list of conditions and the following disclaimer.
  14. 2. Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. 3. Neither the name of the copyright holder nor the names of its contributors
  18. may be used to endorse or promote products derived from this software without
  19. specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. OF SUCH DAMAGE.
  30. */
  31. #include "gd32f4xx_dbg.h"
  32. #define DBG_RESET_VAL 0x00000000U
  33. /*!
  34. \brief deinitialize the DBG
  35. \param[in] none
  36. \param[out] none
  37. \retval none
  38. */
  39. void dbg_deinit(void)
  40. {
  41. DBG_CTL0 = DBG_RESET_VAL;
  42. DBG_CTL1 = 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: dbg_periph_enum
  85. only one parameter can be selected which is shown as below:
  86. \arg DBG_TIMER1_HOLD: hold TIMER1 counter when core is halted
  87. \arg DBG_TIMER2_HOLD: hold TIMER2 counter when core is halted
  88. \arg DBG_TIMER3_HOLD: hold TIMER3 counter when core is halted
  89. \arg DBG_TIMER4_HOLD: hold TIMER4 counter when core is halted
  90. \arg DBG_TIMER5_HOLD: hold TIMER5 counter when core is halted
  91. \arg DBG_TIMER6_HOLD: hold TIMER6 counter when core is halted
  92. \arg DBG_TIMER11_HOLD: hold TIMER11 counter when core is halted
  93. \arg DBG_TIMER12_HOLD: hold TIMER12 counter when core is halted
  94. \arg DBG_TIMER13_HOLD: hold TIMER13 counter when core is halted
  95. \arg DBG_RTC_HOLD: hold RTC calendar and wakeup counter when core is halted
  96. \arg DBG_WWDGT_HOLD: debug WWDGT kept when core is halted
  97. \arg DBG_FWDGT_HOLD: debug FWDGT kept when core is halted
  98. \arg DBG_I2C0_HOLD: hold I2C0 smbus when core is halted
  99. \arg DBG_I2C1_HOLD: hold I2C1 smbus when core is halted
  100. \arg DBG_I2C2_HOLD: hold I2C2 smbus when core is halted
  101. \arg DBG_CAN0_HOLD: debug CAN0 kept when core is halted
  102. \arg DBG_CAN1_HOLD: debug CAN1 kept when core is halted
  103. \arg DBG_TIMER0_HOLD: hold TIMER0 counter when core is halted
  104. \arg DBG_TIMER7_HOLD: hold TIMER7 counter when core is halted
  105. \arg DBG_TIMER8_HOLD: hold TIMER8 counter when core is halted
  106. \arg DBG_TIMER9_HOLD: hold TIMER9 counter when core is halted
  107. \arg DBG_TIMER10_HOLD: hold TIMER10 counter when core is halted
  108. \arg \param[out] none
  109. \retval none
  110. */
  111. void dbg_periph_enable(dbg_periph_enum dbg_periph)
  112. {
  113. DBG_REG_VAL(dbg_periph) |= BIT(DBG_BIT_POS(dbg_periph));
  114. }
  115. /*!
  116. \brief disable peripheral behavior when the mcu is in debug mode
  117. \param[in] dbg_periph: dbg_periph_enum
  118. only one parameter can be selected which is shown as below:
  119. \arg DBG_TIMER1_HOLD: hold TIMER1 counter when core is halted
  120. \arg DBG_TIMER2_HOLD: hold TIMER2 counter when core is halted
  121. \arg DBG_TIMER3_HOLD: hold TIMER3 counter when core is halted
  122. \arg DBG_TIMER4_HOLD: hold TIMER4 counter when core is halted
  123. \arg DBG_TIMER5_HOLD: hold TIMER5 counter when core is halted
  124. \arg DBG_TIMER6_HOLD: hold TIMER6 counter when core is halted
  125. \arg DBG_TIMER11_HOLD: hold TIMER11 counter when core is halted
  126. \arg DBG_TIMER12_HOLD: hold TIMER12 counter when core is halted
  127. \arg DBG_TIMER13_HOLD: hold TIMER13 counter when core is halted
  128. \arg DBG_RTC_HOLD: hold RTC calendar and wakeup counter when core is halted
  129. \arg DBG_WWDGT_HOLD: debug WWDGT kept when core is halted
  130. \arg DBG_FWDGT_HOLD: debug FWDGT kept when core is halted
  131. \arg DBG_I2C0_HOLD: hold I2C0 smbus when core is halted
  132. \arg DBG_I2C1_HOLD: hold I2C1 smbus when core is halted
  133. \arg DBG_I2C2_HOLD: hold I2C2 smbus when core is halted
  134. \arg DBG_CAN0_HOLD: debug CAN0 kept when core is halted
  135. \arg DBG_CAN1_HOLD: debug CAN1 kept when core is halted
  136. \arg DBG_TIMER0_HOLD: hold TIMER0 counter when core is halted
  137. \arg DBG_TIMER7_HOLD: hold TIMER7 counter when core is halted
  138. \arg DBG_TIMER8_HOLD: hold TIMER8 counter when core is halted
  139. \arg DBG_TIMER9_HOLD: hold TIMER9 counter when core is halted
  140. \arg DBG_TIMER10_HOLD: hold TIMER10 counter when core is halted
  141. \param[out] none
  142. \retval none
  143. */
  144. void dbg_periph_disable(dbg_periph_enum dbg_periph)
  145. {
  146. DBG_REG_VAL(dbg_periph) &= ~BIT(DBG_BIT_POS(dbg_periph));
  147. }
  148. /*!
  149. \brief enable trace pin assignment
  150. \param[in] none
  151. \param[out] none
  152. \retval none
  153. */
  154. void dbg_trace_pin_enable(void)
  155. {
  156. DBG_CTL0 |= DBG_CTL0_TRACE_IOEN;
  157. }
  158. /*!
  159. \brief disable trace pin assignment
  160. \param[in] none
  161. \param[out] none
  162. \retval none
  163. */
  164. void dbg_trace_pin_disable(void)
  165. {
  166. DBG_CTL0 &= ~DBG_CTL0_TRACE_IOEN;
  167. }
  168. /*!
  169. \brief trace pin mode selection
  170. \param[in] trace_mode:
  171. \arg TRACE_MODE_ASYNC: trace pin used for async mode
  172. \arg TRACE_MODE_SYNC_DATASIZE_1: trace pin used for sync mode and data size is 1
  173. \arg TRACE_MODE_SYNC_DATASIZE_2: trace pin used for sync mode and data size is 2
  174. \arg TRACE_MODE_SYNC_DATASIZE_4: trace pin used for sync mode and data size is 4
  175. \param[out] none
  176. \retval none
  177. */
  178. void dbg_trace_pin_mode_set(uint32_t trace_mode)
  179. {
  180. DBG_CTL0 &= ~DBG_CTL0_TRACE_MODE;
  181. DBG_CTL0 |= trace_mode;
  182. }