gd32f30x_dbg.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*!
  2. \file gd32f30x_dbg.h
  3. \brief definitions for the DBG
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-02-10, V1.0.0, firmware for GD32F30x
  8. */
  9. #ifndef GD32F30X_DBG_H
  10. #define GD32F30X_DBG_H
  11. #include "gd32f30x.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. /* bits definitions */
  18. /* DBG_ID */
  19. #define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
  20. /* DBG_CTL0 */
  21. #define DBG_CTL0_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */
  22. #define DBG_CTL0_DSLP_HOLD BIT(1) /*!< keep debugger connection during deepsleep mode */
  23. #define DBG_CTL0_STB_HOLD BIT(2) /*!< keep debugger connection during standby mode */
  24. #define DBG_CTL0_TRACE_IOEN BIT(5) /*!< enable trace pin assignment */
  25. #define DBG_CTL0_TRACE_MODE BITS(6,7) /*!< trace pin mode selection */
  26. #define DBG_CTL0_FWDGT_HOLD BIT(8) /*!< debug FWDGT kept when core is halted */
  27. #define DBG_CTL0_WWDGT_HOLD BIT(9) /*!< debug WWDGT kept when core is halted */
  28. #define DBG_CTL0_TIMER0_HOLD BIT(10) /*!< hold TIMER0 counter when core is halted */
  29. #define DBG_CTL0_TIMER1_HOLD BIT(11) /*!< hold TIMER1 counter when core is halted */
  30. #define DBG_CTL0_TIMER2_HOLD BIT(12) /*!< hold TIMER2 counter when core is halted */
  31. #define DBG_CTL0_TIMER3_HOLD BIT(13) /*!< hold TIMER3 counter when core is halted */
  32. #define DBG_CTL0_CAN0_HOLD BIT(14) /*!< debug CAN0 kept when core is halted */
  33. #define DBG_CTL0_I2C0_HOLD BIT(15) /*!< hold I2C0 smbus when core is halted */
  34. #define DBG_CTL0_I2C1_HOLD BIT(16) /*!< hold I2C1 smbus when core is halted */
  35. #define DBG_CTL0_TIMER4_HOLD BIT(17) /*!< hold TIMER4 counter when core is halted */
  36. #define DBG_CTL0_TIMER5_HOLD BIT(18) /*!< hold TIMER5 counter when core is halted */
  37. #define DBG_CTL0_TIMER6_HOLD BIT(19) /*!< hold TIMER6 counter when core is halted */
  38. #define DBG_CTL0_TIMER7_HOLD BIT(20) /*!< hold TIMER7 counter when core is halted */
  39. #ifdef GD32F30X_CL
  40. #define DBG_CTL0_CAN1_HOLD BIT(21) /*!< debug CAN1 kept when core is halted */
  41. #endif /* GD32F30X_CL */
  42. #ifndef GD32F30X_HD
  43. #define DBG_CTL0_TIMER11_HOLD BIT(25) /*!< hold TIMER11 counter when core is halted */
  44. #define DBG_CTL0_TIMER12_HOLD BIT(26) /*!< hold TIMER12 counter when core is halted */
  45. #define DBG_CTL0_TIMER13_HOLD BIT(27) /*!< hold TIMER13 counter when core is halted */
  46. #define DBG_CTL0_TIMER8_HOLD BIT(28) /*!< hold TIMER8 counter when core is halted */
  47. #define DBG_CTL0_TIMER9_HOLD BIT(29) /*!< hold TIMER9 counter when core is halted */
  48. #define DBG_CTL0_TIMER10_HOLD BIT(30) /*!< hold TIMER10 counter when core is halted */
  49. #endif /* GD32F30X_HD */
  50. /* constants definitions */
  51. #define DBG_LOW_POWER_SLEEP DBG_CTL0_SLP_HOLD /*!< keep debugger connection during sleep mode */
  52. #define DBG_LOW_POWER_DEEPSLEEP DBG_CTL0_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */
  53. #define DBG_LOW_POWER_STANDBY DBG_CTL0_STB_HOLD /*!< keep debugger connection during standby mode */
  54. typedef enum
  55. {
  56. DBG_FWDGT_HOLD = BIT(8), /*!< debug FWDGT kept when core is halted */
  57. DBG_WWDGT_HOLD = BIT(9), /*!< debug WWDGT kept when core is halted */
  58. DBG_TIMER0_HOLD = BIT(10), /*!< hold TIMER0 counter when core is halted */
  59. DBG_TIMER1_HOLD = BIT(11), /*!< hold TIMER1 counter when core is halted */
  60. DBG_TIMER2_HOLD = BIT(12), /*!< hold TIMER2 counter when core is halted */
  61. DBG_TIMER3_HOLD = BIT(13), /*!< hold TIMER3 counter when core is halted */
  62. DBG_CAN0_HOLD = BIT(14), /*!< debug CAN0 kept when core is halted */
  63. DBG_I2C0_HOLD = BIT(15), /*!< hold I2C0 smbus when core is halted */
  64. DBG_I2C1_HOLD = BIT(16), /*!< hold I2C1 smbus when core is halted */
  65. DBG_TIMER4_HOLD = BIT(17), /*!< hold TIMER4 counter when core is halted */
  66. DBG_TIMER5_HOLD = BIT(18), /*!< hold TIMER5 counter when core is halted */
  67. DBG_TIMER6_HOLD = BIT(19), /*!< hold TIMER6 counter when core is halted */
  68. DBG_TIMER7_HOLD = BIT(20), /*!< hold TIMER7 counter when core is halted */
  69. #ifdef GD32F30X_CL
  70. DBG_CAN1_HOLD = BIT(21), /*!< debug CAN1 kept when core is halted */
  71. #endif /* GD32F30X_CL */
  72. #ifndef GD32F30X_HD
  73. DBG_TIMER11_HOLD = BIT(25), /*!< hold TIMER11 counter when core is halted */
  74. DBG_TIMER12_HOLD = BIT(26), /*!< hold TIMER12 counter when core is halted */
  75. DBG_TIMER13_HOLD = BIT(27), /*!< hold TIMER13 counter when core is halted */
  76. DBG_TIMER8_HOLD = BIT(28), /*!< hold TIMER8 counter when core is halted */
  77. DBG_TIMER9_HOLD = BIT(29), /*!< hold TIMER9 counter when core is halted */
  78. DBG_TIMER10_HOLD = BIT(30), /*!< hold TIMER10 counter when core is halted */
  79. #endif /* GD32F30X_HD */
  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 /* GD32F30X_DBG_H */