gd32f30x_dbg.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*!
  2. \file gd32f30x_dbg.c
  3. \brief DBG driver
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-02-10, V1.0.0, firmware for GD32F30x
  8. */
  9. #include "gd32f30x_dbg.h"
  10. /*!
  11. \brief read DBG_ID code register
  12. \param[in] none
  13. \param[out] none
  14. \retval DBG_ID code
  15. */
  16. uint32_t dbg_id_get(void)
  17. {
  18. return DBG_ID;
  19. }
  20. /*!
  21. \brief enable low power behavior when the mcu is in debug mode
  22. \param[in] dbg_low_power:
  23. this parameter can be any combination of the following values:
  24. \arg DBG_LOW_POWER_SLEEP: keep debugger connection during sleep mode
  25. \arg DBG_LOW_POWER_DEEPSLEEP: keep debugger connection during deepsleep mode
  26. \arg DBG_LOW_POWER_STANDBY: keep debugger connection during standby mode
  27. \param[out] none
  28. \retval none
  29. */
  30. void dbg_low_power_enable(uint32_t dbg_low_power)
  31. {
  32. DBG_CTL0 |= dbg_low_power;
  33. }
  34. /*!
  35. \brief disable low power behavior when the mcu is in debug mode
  36. \param[in] dbg_low_power:
  37. this parameter can be any combination of the following values:
  38. \arg DBG_LOW_POWER_SLEEP: donot keep debugger connection during sleep mode
  39. \arg DBG_LOW_POWER_DEEPSLEEP: donot keep debugger connection during deepsleep mode
  40. \arg DBG_LOW_POWER_STANDBY: donot keep debugger connection during standby mode
  41. \param[out] none
  42. \retval none
  43. */
  44. void dbg_low_power_disable(uint32_t dbg_low_power)
  45. {
  46. DBG_CTL0 &= ~dbg_low_power;
  47. }
  48. /*!
  49. \brief enable peripheral behavior when the mcu is in debug mode
  50. \param[in] dbg_periph: refer to dbg_periph_enum
  51. only one parameter can be selected which is shown as below:
  52. \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
  53. \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
  54. \arg DBG_CANx_HOLD (x=0,1,CAN1 is only available for CL series): hold CANx counter when core is halted
  55. \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
  56. \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
  57. \param[out] none
  58. \retval none
  59. */
  60. void dbg_periph_enable(dbg_periph_enum dbg_periph)
  61. {
  62. DBG_CTL0 |= (uint32_t)dbg_periph;
  63. }
  64. /*!
  65. \brief disable peripheral behavior when the mcu is in debug mode
  66. \param[in] dbg_periph: refer to dbg_periph_enum
  67. only one parameter can be selected which is shown as below:
  68. \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
  69. \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
  70. \arg DBG_CANx_HOLD (x=0,1,CAN1 is only available for CL series): hold CAN0 counter when core is halted
  71. \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
  72. \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
  73. \param[out] none
  74. \retval none
  75. */
  76. void dbg_periph_disable(dbg_periph_enum dbg_periph)
  77. {
  78. DBG_CTL0 &= ~(uint32_t)dbg_periph;
  79. }
  80. /*!
  81. \brief enable trace pin assignment
  82. \param[in] none
  83. \param[out] none
  84. \retval none
  85. */
  86. void dbg_trace_pin_enable(void)
  87. {
  88. DBG_CTL0 |= DBG_CTL0_TRACE_IOEN;
  89. }
  90. /*!
  91. \brief disable trace pin assignment
  92. \param[in] none
  93. \param[out] none
  94. \retval none
  95. */
  96. void dbg_trace_pin_disable(void)
  97. {
  98. DBG_CTL0 &= ~DBG_CTL0_TRACE_IOEN;
  99. }
  100. /*!
  101. \brief trace pin mode selection
  102. \param[in] trace_mode:
  103. \arg TRACE_MODE_ASYNC: trace pin used for async mode
  104. \arg TRACE_MODE_SYNC_DATASIZE_1: trace pin used for sync mode and data size is 1
  105. \arg TRACE_MODE_SYNC_DATASIZE_2: trace pin used for sync mode and data size is 2
  106. \arg TRACE_MODE_SYNC_DATASIZE_4: trace pin used for sync mode and data size is 4
  107. \param[out] none
  108. \retval none
  109. */
  110. void dbg_trace_pin_mode_set(uint32_t trace_mode)
  111. {
  112. DBG_CTL0 &= ~DBG_CTL0_TRACE_MODE;
  113. DBG_CTL0 |= trace_mode;
  114. }