gd32f4xx_dbg.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*!
  2. \file gd32f4xx_dbg.h
  3. \brief definitions for the DBG
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_DBG_H
  10. #define GD32F4XX_DBG_H
  11. #include "gd32f4xx.h"
  12. /* DBG definitions */
  13. #define DBG DBG_BASE
  14. /* registers definitions */
  15. #define DBG_ID REG32(DBG + 0x00U) /*!< DBG_ID code register */
  16. #define DBG_CTL0 REG32(DBG + 0x04U) /*!< DBG control register 0 */
  17. #define DBG_CTL1 REG32(DBG + 0x08U) /*!< DBG control register 1 */
  18. #define DBG_CTL2 REG32(DBG + 0x0CU) /*!< DBG control register 2 */
  19. /* bits definitions */
  20. /* DBG_ID */
  21. #define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
  22. /* DBG_CTL0 */
  23. #define DBG_CTL0_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */
  24. #define DBG_CTL0_DSLP_HOLD BIT(1) /*!< keep debugger connection during deepsleep mode */
  25. #define DBG_CTL0_STB_HOLD BIT(2) /*!< keep debugger connection during standby mode */
  26. #define DBG_CTL0_TRACE_IOEN BIT(5) /*!< enable trace pin assignment */
  27. #define DBG_CTL0_TRACE_MODE BITS(6,7) /*!< trace pin mode selection */
  28. /* DBG_CTL1 */
  29. #define DBG_CTL1_TIMER1_HOLD BIT(0) /*!< hold TIMER1 counter when core is halted */
  30. #define DBG_CTL1_TIMER2_HOLD BIT(1) /*!< hold TIMER2 counter when core is halted */
  31. #define DBG_CTL1_TIMER3_HOLD BIT(2) /*!< hold TIMER3 counter when core is halted */
  32. #define DBG_CTL1_TIMER4_HOLD BIT(3) /*!< hold TIMER4 counter when core is halted */
  33. #define DBG_CTL1_TIMER5_HOLD BIT(4) /*!< hold TIMER5 counter when core is halted */
  34. #define DBG_CTL1_TIMER6_HOLD BIT(5) /*!< hold TIMER6 counter when core is halted */
  35. #define DBG_CTL1_TIMER11_HOLD BIT(6) /*!< hold TIMER11 counter when core is halted */
  36. #define DBG_CTL1_TIMER12_HOLD BIT(7) /*!< hold TIMER12 counter when core is halted */
  37. #define DBG_CTL1_TIMER13_HOLD BIT(8) /*!< hold TIMER13 counter when core is halted */
  38. #define DBG_CTL1_RTC_HOLD BIT(10) /*!< hold RTC calendar and wakeup counter when core is halted */
  39. #define DBG_CTL1_WWDGT_HOLD BIT(11) /*!< debug WWDGT kept when core is halted */
  40. #define DBG_CTL1_FWDGT_HOLD BIT(12) /*!< debug FWDGT kept when core is halted */
  41. #define DBG_CTL1_I2C0_HOLD BIT(21) /*!< hold I2C0 smbus when core is halted */
  42. #define DBG_CTL1_I2C1_HOLD BIT(22) /*!< hold I2C1 smbus when core is halted */
  43. #define DBG_CTL1_I2C2_HOLD BIT(23) /*!< hold I2C2 smbus when core is halted */
  44. #define DBG_CTL1_CAN0_HOLD BIT(25) /*!< debug CAN0 kept when core is halted */
  45. #define DBG_CTL1_CAN1_HOLD BIT(26) /*!< debug CAN1 kept when core is halted */
  46. /* DBG_CTL2 */
  47. #define DBG_CTL2_TIMER0_HOLD BIT(0) /*!< hold TIMER0 counter when core is halted */
  48. #define DBG_CTL2_TIMER7_HOLD BIT(1) /*!< hold TIMER7 counter when core is halted */
  49. #define DBG_CTL2_TIMER8_HOLD BIT(16) /*!< hold TIMER8 counter when core is halted */
  50. #define DBG_CTL2_TIMER9_HOLD BIT(17) /*!< hold TIMER9 counter when core is halted */
  51. #define DBG_CTL2_TIMER10_HOLD BIT(18) /*!< hold TIMER10 counter when core is halted */
  52. /* constants definitions */
  53. #define DBG_LOW_POWER_SLEEP DBG_CTL0_SLP_HOLD /*!< keep debugger connection during sleep mode */
  54. #define DBG_LOW_POWER_DEEPSLEEP DBG_CTL0_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */
  55. #define DBG_LOW_POWER_STANDBY DBG_CTL0_STB_HOLD /*!< keep debugger connection during standby mode */
  56. typedef enum
  57. {
  58. DBG_TIMER1_HOLD = BIT(0), /*!< hold TIMER1 counter when core is halted */
  59. DBG_TIMER2_HOLD = BIT(1), /*!< hold TIMER2 counter when core is halted */
  60. DBG_TIMER3_HOLD = BIT(2), /*!< hold TIMER3 counter when core is halted */
  61. DBG_TIMER4_HOLD = BIT(3), /*!< hold TIMER4 counter when core is halted */
  62. DBG_TIMER5_HOLD = BIT(4), /*!< hold TIMER5 counter when core is halted */
  63. DBG_TIMER6_HOLD = BIT(5), /*!< hold TIMER6 counter when core is halted */
  64. DBG_TIMER11_HOLD = BIT(6), /*!< hold TIMER11 counter when core is halted */
  65. DBG_TIMER12_HOLD = BIT(7), /*!< hold TIMER12 counter when core is halted */
  66. DBG_TIMER13_HOLD = BIT(8), /*!< hold TIMER13 counter when core is halted */
  67. DBG_RTC_HOLD = BIT(10), /*!< hold RTC calendar and wakeup counter when core is halted */
  68. DBG_WWDGT_HOLD = BIT(11), /*!< debug WWDGT kept when core is halted */
  69. DBG_FWDGT_HOLD = BIT(12), /*!< debug FWDGT kept when core is halted */
  70. DBG_I2C0_HOLD = BIT(21), /*!< hold I2C0 smbus when core is halted */
  71. DBG_I2C1_HOLD = BIT(22), /*!< hold I2C1 smbus when core is halted */
  72. DBG_I2C2_HOLD = BIT(23), /*!< hold I2C2 smbus when core is halted */
  73. DBG_CAN0_HOLD = BIT(25), /*!< debug CAN0 kept when core is halted */
  74. DBG_CAN1_HOLD = BIT(26), /*!< debug CAN1 kept when core is halted */
  75. DBG_TIMER0_HOLD = (BIT(0) | BIT(30)), /*!< hold TIMER0 counter when core is halted */
  76. DBG_TIMER7_HOLD = (BIT(1) | BIT(30)), /*!< hold TIMER7 counter when core is halted */
  77. DBG_TIMER8_HOLD = (BIT(16) | BIT(30)), /*!< hold TIMER8 counter when core is halted */
  78. DBG_TIMER9_HOLD = (BIT(17) | BIT(30)), /*!< hold TIMER9 counter when core is halted */
  79. DBG_TIMER10_HOLD = (BIT(18) | BIT(30)), /*!< hold TIMER10 counter when core is halted */
  80. }dbg_periph_enum;
  81. #define CTL0_TRACE_MODE(regval) (BITS(6,7)&((uint32_t)(regval)<<6))
  82. #define TRACE_MODE_ASYNC CTL0_TRACE_MODE(0) /*!< trace pin used for async mode */
  83. #define TRACE_MODE_SYNC_DATASIZE_1 CTL0_TRACE_MODE(1) /*!< trace pin used for sync mode and data size is 1 */
  84. #define TRACE_MODE_SYNC_DATASIZE_2 CTL0_TRACE_MODE(2) /*!< trace pin used for sync mode and data size is 2 */
  85. #define TRACE_MODE_SYNC_DATASIZE_4 CTL0_TRACE_MODE(3) /*!< trace pin used for sync mode and data size is 4 */
  86. /* function declarations */
  87. /* read DBG_ID code register */
  88. uint32_t dbg_id_get(void);
  89. /* enable low power behavior when the MCU is in debug mode */
  90. void dbg_low_power_enable(uint32_t dbg_low_power);
  91. /* disable low power behavior when the MCU is in debug mode */
  92. void dbg_low_power_disable(uint32_t dbg_low_power);
  93. /* enable peripheral behavior when the MCU is in debug mode */
  94. void dbg_periph_enable(dbg_periph_enum dbg_periph);
  95. /* disable peripheral behavior when the MCU is in debug mode */
  96. void dbg_periph_disable(dbg_periph_enum dbg_periph);
  97. /* enable trace pin assignment */
  98. void dbg_trace_pin_enable(void);
  99. /* disable trace pin assignment */
  100. void dbg_trace_pin_disable(void);
  101. /* set trace pin mode */
  102. void dbg_trace_pin_mode_set(uint32_t trace_mode);
  103. #endif /* GD32F4XX_DBG_H */