gd32f10x_dbg.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*!
  2. \file gd32f10x_dbg.c
  3. \brief DBG driver
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  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 "gd32f10x_dbg.h"
  33. /*!
  34. \brief read DBG_ID code register
  35. \param[in] none
  36. \param[out] none
  37. \retval DBG_ID code
  38. */
  39. uint32_t dbg_id_get(void)
  40. {
  41. return DBG_ID;
  42. }
  43. /*!
  44. \brief enable low power behavior when the mcu is in debug mode
  45. \param[in] dbg_low_power:
  46. one or more parameters can be selected which are shown as below:
  47. \arg DBG_LOW_POWER_SLEEP: keep debugger connection during sleep mode
  48. \arg DBG_LOW_POWER_DEEPSLEEP: keep debugger connection during deepsleep mode
  49. \arg DBG_LOW_POWER_STANDBY: keep debugger connection during standby mode
  50. \param[out] none
  51. \retval none
  52. */
  53. void dbg_low_power_enable(uint32_t dbg_low_power)
  54. {
  55. DBG_CTL |= dbg_low_power;
  56. }
  57. /*!
  58. \brief disable low power behavior when the mcu is in debug mode
  59. \param[in] dbg_low_power:
  60. one or more parameters can be selected which are shown as below:
  61. \arg DBG_LOW_POWER_SLEEP: donot keep debugger connection during sleep mode
  62. \arg DBG_LOW_POWER_DEEPSLEEP: donot keep debugger connection during deepsleep mode
  63. \arg DBG_LOW_POWER_STANDBY: donot keep debugger connection during standby mode
  64. \param[out] none
  65. \retval none
  66. */
  67. void dbg_low_power_disable(uint32_t dbg_low_power)
  68. {
  69. DBG_CTL &= ~dbg_low_power;
  70. }
  71. /*!
  72. \brief enable peripheral behavior when the mcu is in debug mode
  73. \param[in] dbg_periph: refer to dbg_periph_enum
  74. one or more parameters can be selected which are shown as below:
  75. \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
  76. \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
  77. \arg DBG_CANx_HOLD (x=0,1,CAN1 is only available for CL series): hold CANx counter when core is halted
  78. \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
  79. \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
  80. \param[out] none
  81. \retval none
  82. */
  83. void dbg_periph_enable(dbg_periph_enum dbg_periph)
  84. {
  85. DBG_CTL |= (uint32_t)dbg_periph;
  86. }
  87. /*!
  88. \brief disable peripheral behavior when the mcu is in debug mode
  89. \param[in] dbg_periph: refer to dbg_periph_enum
  90. one or more parameters can be selected which are shown as below:
  91. \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
  92. \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
  93. \arg DBG_CANx_HOLD (x=0,1,CAN1 is only available for CL series): hold CAN0 counter when core is halted
  94. \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
  95. \arg DBG_TIMERx_HOLD (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13,TIMER8..13 are only available for XD and CL series): hold TIMERx counter when core is halted
  96. \param[out] none
  97. \retval none
  98. */
  99. void dbg_periph_disable(dbg_periph_enum dbg_periph)
  100. {
  101. DBG_CTL &= ~(uint32_t)dbg_periph;
  102. }
  103. /*!
  104. \brief enable trace pin assignment
  105. \param[in] none
  106. \param[out] none
  107. \retval none
  108. */
  109. void dbg_trace_pin_enable(void)
  110. {
  111. DBG_CTL |= DBG_CTL_TRACE_IOEN;
  112. }
  113. /*!
  114. \brief disable trace pin assignment
  115. \param[in] none
  116. \param[out] none
  117. \retval none
  118. */
  119. void dbg_trace_pin_disable(void)
  120. {
  121. DBG_CTL &= ~DBG_CTL_TRACE_IOEN;
  122. }
  123. /*!
  124. \brief trace pin mode selection
  125. \param[in] trace_mode:
  126. only one parameter can be selected which is shown as below:
  127. \arg TRACE_MODE_ASYNC: trace pin used for async mode
  128. \arg TRACE_MODE_SYNC_DATASIZE_1: trace pin used for sync mode and data size is 1
  129. \arg TRACE_MODE_SYNC_DATASIZE_2: trace pin used for sync mode and data size is 2
  130. \arg TRACE_MODE_SYNC_DATASIZE_4: trace pin used for sync mode and data size is 4
  131. \param[out] none
  132. \retval none
  133. */
  134. void dbg_trace_pin_mode_set(uint32_t trace_mode)
  135. {
  136. DBG_CTL &= ~DBG_CTL_TRACE_MODE;
  137. DBG_CTL |= trace_mode;
  138. }