gd32f3x0_dbg.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*!
  2. \file gd32f3x0_dbg.h
  3. \brief definitions for the DBG
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #ifndef GD32F3X0_DBG_H
  10. #define GD32F3X0_DBG_H
  11. #include "gd32f3x0.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. /* bits definitions */
  19. /* DBG_ID */
  20. #define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
  21. /* DBG_CTL0 */
  22. #define DBG_CTL0_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */
  23. #define DBG_CTL0_DSLP_HOLD BIT(1) /*!< keep debugger connection during deepsleep mode */
  24. #define DBG_CTL0_STB_HOLD BIT(2) /*!< keep debugger connection during standby mode */
  25. #define DBG_CTL0_FWDGT_HOLD BIT(8) /*!< debug FWDGT kept when core is halted */
  26. #define DBG_CTL0_WWDGT_HOLD BIT(9) /*!< debug WWDGT kept when core is halted */
  27. #define DBG_CTL0_TIMER0_HOLD BIT(10) /*!< TIMER0 counter kept when core is halted */
  28. #define DBG_CTL0_TIMER1_HOLD BIT(11) /*!< TIMER1 counter kept when core is halted */
  29. #define DBG_CTL0_TIMER2_HOLD BIT(12) /*!< TIMER2 counter kept when core is halted */
  30. #define DBG_CTL0_I2C0_HOLD BIT(15) /*!< hold I2C0 smbus when core is halted */
  31. #define DBG_CTL0_I2C1_HOLD BIT(16) /*!< hold I2C1 smbus when core is halted */
  32. #define DBG_CTL0_I2C2_HOLD BIT(17) /*!< hold I2C2 smbus when core is halted */
  33. #ifdef GD32F350
  34. #define DBG_CTL0_TIMER5_HOLD BIT(19) /*!< hold TIMER5 counter when core is halted */
  35. #endif /* GD32F350 */
  36. #define DBG_CTL0_TIMER13_HOLD BIT(27) /*!< hold TIMER13 counter when core is halted */
  37. /* DBG_CTL1 */
  38. #define DBG_CTL1_RTC_HOLD BIT(10) /*!< hold RTC calendar and wakeup counter when core is halted */
  39. #define DBG_CTL1_TIMER14_HOLD BIT(16) /*!< hold TIMER14 counter when core is halted */
  40. #define DBG_CTL1_TIMER15_HOLD BIT(17) /*!< hold TIMER15 counter when core is halted */
  41. #define DBG_CTL1_TIMER16_HOLD BIT(18) /*!< hold TIMER16 counter when core is halted */
  42. /* constants definitions */
  43. #define DBG_LOW_POWER_SLEEP DBG_CTL0_SLP_HOLD /*!< keep debugger connection during sleep mode */
  44. #define DBG_LOW_POWER_DEEPSLEEP DBG_CTL0_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */
  45. #define DBG_LOW_POWER_STANDBY DBG_CTL0_STB_HOLD /*!< keep debugger connection during standby mode */
  46. /* define the peripheral debug hold bit position and its register index offset */
  47. #define DBG_REGIDX_BIT(regidx, bitpos) (((regidx) << 6) | (bitpos))
  48. #define DBG_REG_VAL(periph) (REG32(DBG + ((uint32_t)(periph) >> 6)))
  49. #define DBG_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
  50. /* register index */
  51. enum dbg_reg_idx
  52. {
  53. DBG_IDX_CTL0 = 0x04U,
  54. DBG_IDX_CTL1 = 0x08U,
  55. };
  56. /* peripherals hold bit */
  57. typedef enum
  58. {
  59. DBG_FWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 8U), /*!< FWDGT hold bit */
  60. DBG_WWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 9U), /*!< WWDGT hold bit */
  61. DBG_TIMER0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 10U), /*!< TIMER0 hold bit */
  62. DBG_TIMER1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 11U), /*!< TIMER1 hold bit */
  63. DBG_TIMER2_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 12U), /*!< TIMER2 hold bit */
  64. #ifdef GD32F350
  65. DBG_TIMER5_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 19U), /*!< TIMER5 hold bit */
  66. #endif /* GD32F350 */
  67. DBG_TIMER13_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 27U), /*!< TIMER13 hold bit */
  68. DBG_TIMER14_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 16U), /*!< TIMER14 hold bit */
  69. DBG_TIMER15_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 17U), /*!< TIMER15 hold bit */
  70. DBG_TIMER16_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 18U), /*!< TIMER16 hold bit */
  71. DBG_I2C0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 15U), /*!< I2C0 hold bit */
  72. DBG_I2C1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 16U), /*!< I2C1 hold bit */
  73. DBG_I2C2_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL0, 17U), /*!< I2C2 hold bit */
  74. DBG_RTC_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 10U), /*!< RTC hold bit */
  75. }dbg_periph_enum;
  76. /* function declarations */
  77. /* deinitialize the DBG */
  78. void dbg_deinit(void);
  79. /* read DBG_ID code register */
  80. uint32_t dbg_id_get(void);
  81. /* enable low power behavior when the MCU is in debug mode */
  82. void dbg_low_power_enable(uint32_t dbg_low_power);
  83. /* disable low power behavior when the MCU is in debug mode */
  84. void dbg_low_power_disable(uint32_t dbg_low_power);
  85. /* enable peripheral behavior when the MCU is in debug mode */
  86. void dbg_periph_enable(dbg_periph_enum dbg_periph);
  87. /* disable peripheral behavior when the MCU is in debug mode */
  88. void dbg_periph_disable(dbg_periph_enum dbg_periph);
  89. #endif /* GD32F3X0_DBG_H */