gd32f4xx_dbg.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*!
  2. \file gd32f4xx_dbg.c
  3. \brief DBG driver
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #include "gd32f4xx_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: dbg_periph_enum
  51. \param[out] none
  52. \retval none
  53. */
  54. void dbg_periph_enable(dbg_periph_enum dbg_periph)
  55. {
  56. if(RESET == ((uint32_t)dbg_periph & BIT(30))){
  57. DBG_CTL1 |= (uint32_t)dbg_periph;
  58. }else{
  59. DBG_CTL2 |= ((uint32_t)dbg_periph & (~BIT(30)));
  60. }
  61. }
  62. /*!
  63. \brief disable peripheral behavior when the mcu is in debug mode
  64. \param[in] dbg_periph: dbg_periph_enum
  65. \param[out] none
  66. \retval none
  67. */
  68. void dbg_periph_disable(dbg_periph_enum dbg_periph)
  69. {
  70. if(RESET == ((uint32_t)dbg_periph & BIT(30))){
  71. DBG_CTL1 &= ~(uint32_t)dbg_periph;
  72. }else{
  73. DBG_CTL2 &= ~((uint32_t)dbg_periph & (~BIT(30)));
  74. }
  75. }
  76. /*!
  77. \brief enable trace pin assignment
  78. \param[in] none
  79. \param[out] none
  80. \retval none
  81. */
  82. void dbg_trace_pin_enable(void)
  83. {
  84. DBG_CTL0 |= DBG_CTL0_TRACE_IOEN;
  85. }
  86. /*!
  87. \brief disable trace pin assignment
  88. \param[in] none
  89. \param[out] none
  90. \retval none
  91. */
  92. void dbg_trace_pin_disable(void)
  93. {
  94. DBG_CTL0 &= ~DBG_CTL0_TRACE_IOEN;
  95. }
  96. /*!
  97. \brief trace pin mode selection
  98. \param[in] trace_mode:
  99. \arg TRACE_MODE_ASYNC: trace pin used for async mode
  100. \arg TRACE_MODE_SYNC_DATASIZE_1: trace pin used for sync mode and data size is 1
  101. \arg TRACE_MODE_SYNC_DATASIZE_2: trace pin used for sync mode and data size is 2
  102. \arg TRACE_MODE_SYNC_DATASIZE_4: trace pin used for sync mode and data size is 4
  103. \param[out] none
  104. \retval none
  105. */
  106. void dbg_trace_pin_mode_set(uint32_t trace_mode)
  107. {
  108. DBG_CTL0 &= ~DBG_CTL0_TRACE_MODE;
  109. DBG_CTL0 |= trace_mode;
  110. }