1 /*! 2 \file gd32vf103_dbg.h 3 \brief definitions for the DBG 4 5 \version 2019-06-05, V1.0.0, firmware for GD32VF103 6 \version 2020-08-04, V1.1.0, firmware for GD32VF103 7 */ 8 9 /* 10 Copyright (c) 2020, GigaDevice Semiconductor Inc. 11 12 Redistribution and use in source and binary forms, with or without modification, 13 are permitted provided that the following conditions are met: 14 15 1. Redistributions of source code must retain the above copyright notice, this 16 list of conditions and the following disclaimer. 17 2. Redistributions in binary form must reproduce the above copyright notice, 18 this list of conditions and the following disclaimer in the documentation 19 and/or other materials provided with the distribution. 20 3. Neither the name of the copyright holder nor the names of its contributors 21 may be used to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 28 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 33 OF SUCH DAMAGE. 34 */ 35 36 #ifndef GD32VF103_DBG_H 37 #define GD32VF103_DBG_H 38 39 #include "gd32vf103.h" 40 41 /* DBG definitions */ 42 #define DBG DBG_BASE 43 44 /* registers definitions */ 45 #define DBG_ID REG32(DBG + 0x00U) /*!< DBG_ID code register */ 46 #define DBG_CTL REG32(DBG + 0x04U) /*!< DBG control register */ 47 48 /* bits definitions */ 49 /* DBG_ID */ 50 #define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */ 51 52 /* DBG_CTL */ 53 #define DBG_CTL_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */ 54 #define DBG_CTL_DSLP_HOLD BIT(1) /*!< keep debugger connection during deepsleep mode */ 55 #define DBG_CTL_STB_HOLD BIT(2) /*!< keep debugger connection during standby mode */ 56 #define DBG_CTL_FWDGT_HOLD BIT(8) /*!< debug FWDGT kept when core is halted */ 57 #define DBG_CTL_WWDGT_HOLD BIT(9) /*!< debug WWDGT kept when core is halted */ 58 #define DBG_CTL_TIMER0_HOLD BIT(10) /*!< hold TIMER0 counter when core is halted */ 59 #define DBG_CTL_TIMER1_HOLD BIT(11) /*!< hold TIMER1 counter when core is halted */ 60 #define DBG_CTL_TIMER2_HOLD BIT(12) /*!< hold TIMER2 counter when core is halted */ 61 #define DBG_CTL_TIMER3_HOLD BIT(13) /*!< hold TIMER3 counter when core is halted */ 62 #define DBG_CTL_CAN0_HOLD BIT(14) /*!< debug CAN0 kept when core is halted */ 63 #define DBG_CTL_I2C0_HOLD BIT(15) /*!< hold I2C0 smbus when core is halted */ 64 #define DBG_CTL_I2C1_HOLD BIT(16) /*!< hold I2C1 smbus when core is halted */ 65 #define DBG_CTL_TIMER4_HOLD BIT(18) /*!< hold TIMER4 counter when core is halted */ 66 #define DBG_CTL_TIMER5_HOLD BIT(19) /*!< hold TIMER5 counter when core is halted */ 67 #define DBG_CTL_TIMER6_HOLD BIT(20) /*!< hold TIMER6 counter when core is halted */ 68 #define DBG_CTL_CAN1_HOLD BIT(21) /*!< debug CAN1 kept when core is halted */ 69 70 /* constants definitions */ 71 /* debug hold when core is halted */ 72 typedef enum 73 { 74 DBG_FWDGT_HOLD = BIT(8), /*!< debug FWDGT kept when core is halted */ 75 DBG_WWDGT_HOLD = BIT(9), /*!< debug WWDGT kept when core is halted */ 76 DBG_TIMER0_HOLD = BIT(10), /*!< hold TIMER0 counter when core is halted */ 77 DBG_TIMER1_HOLD = BIT(11), /*!< hold TIMER1 counter when core is halted */ 78 DBG_TIMER2_HOLD = BIT(12), /*!< hold TIMER2 counter when core is halted */ 79 DBG_TIMER3_HOLD = BIT(13), /*!< hold TIMER3 counter when core is halted */ 80 DBG_CAN0_HOLD = BIT(14), /*!< debug CAN0 kept when core is halted */ 81 DBG_I2C0_HOLD = BIT(15), /*!< hold I2C0 smbus when core is halted */ 82 DBG_I2C1_HOLD = BIT(16), /*!< hold I2C1 smbus when core is halted */ 83 DBG_TIMER4_HOLD = BIT(17), /*!< hold TIMER4 counter when core is halted */ 84 DBG_TIMER5_HOLD = BIT(18), /*!< hold TIMER5 counter when core is halted */ 85 DBG_TIMER6_HOLD = BIT(19), /*!< hold TIMER6 counter when core is halted */ 86 DBG_CAN1_HOLD = BIT(21), /*!< debug CAN1 kept when core is halted */ 87 }dbg_periph_enum; 88 89 /* DBG low power mode configurations */ 90 #define DBG_LOW_POWER_SLEEP DBG_CTL_SLP_HOLD /*!< keep debugger connection during sleep mode */ 91 #define DBG_LOW_POWER_DEEPSLEEP DBG_CTL_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */ 92 #define DBG_LOW_POWER_STANDBY DBG_CTL_STB_HOLD /*!< keep debugger connection during standby mode */ 93 94 /* function declarations */ 95 /* read DBG_ID code register */ 96 uint32_t dbg_id_get(void); 97 98 /* low power behavior configuration */ 99 /* enable low power behavior when the MCU is in debug mode */ 100 void dbg_low_power_enable(uint32_t dbg_low_power); 101 /* disable low power behavior when the MCU is in debug mode */ 102 void dbg_low_power_disable(uint32_t dbg_low_power); 103 104 /* peripheral behavior configuration */ 105 /* enable peripheral behavior when the MCU is in debug mode */ 106 void dbg_periph_enable(dbg_periph_enum dbg_periph); 107 /* disable peripheral behavior when the MCU is in debug mode */ 108 void dbg_periph_disable(dbg_periph_enum dbg_periph); 109 110 #endif /* GD32VF103_DBG_H */ 111