1 /*********************COPYRIGHT(C)  2019 WCH. A11 rights reserved***********************
2 * File Name          : ch32f10x_dbgmcu.c
3 * Author             : WCH
4 * Version            : V1.0.0
5 * Date               : 2019/10/15
6 * Description        : This file provides all the DBGMCU firmware functions.
7 ****************************************************************************************/
8 #include "ch32f10x_dbgmcu.h"
9 
10 #define IDCODE_DEVID_MASK    ((uint32_t)0x00000FFF)
11 
12 /*******************************************************************************
13 * Function Name  : DBGMCU_GetREVID
14 * Description    : Returns the device revision identifier.
15 * Input          : None
16 * Return         : Revision identifier.
17 *******************************************************************************/
DBGMCU_GetREVID(void)18 uint32_t DBGMCU_GetREVID(void)
19 {
20    return(DBGMCU->IDCODE >> 16);
21 }
22 
23 /*******************************************************************************
24 * Function Name  : DBGMCU_GetDEVID
25 * Description    : Returns the device identifier.
26 * Input          : None
27 * Return         : Device identifier.
28 *******************************************************************************/
DBGMCU_GetDEVID(void)29 uint32_t DBGMCU_GetDEVID(void)
30 {
31    return(DBGMCU->IDCODE & IDCODE_DEVID_MASK);
32 }
33 
34 /*******************************************************************************
35 * Function Name  : DBGMCU_Config
36 * Description    : Configures the specified peripheral and low power mode behavior
37 *      when the MCU under Debug mode.
38 * Input          : DBGMCU_Periph: specifies the peripheral and low power mode.
39 *                    DBGMCU_SLEEP: Keep debugger connection during SLEEP mode
40 *                    DBGMCU_STOP: Keep debugger connection during STOP mode
41 *                    DBGMCU_STANDBY: Keep debugger connection during STANDBY mode
42 *                    DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted
43 *                    DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted
44 *                    DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted
45 *                    DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted
46 *                    DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted
47 *                    DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted
48 *                    DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted
49 *                    DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted
50 *                    DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted
51 *                    DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted
52 *                    DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted
53 *                    DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted
54 *                    DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted
55 *                    DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted
56 *                    DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted
57 *                    DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted
58 *                    DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted
59 *                    DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted
60 *                    DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted
61 *                    DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted
62 *                    DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted
63 *                    DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted
64 *                    DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted
65 *                  NewState: ENABLE or DISABLE.
66 * Return         : None
67 *******************************************************************************/
DBGMCU_Config(uint32_t DBGMCU_Periph,FunctionalState NewState)68 void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState)
69 {
70   if (NewState != DISABLE)
71   {
72     DBGMCU->CFGR |= DBGMCU_Periph;
73   }
74   else
75   {
76     DBGMCU->CFGR &= ~DBGMCU_Periph;
77   }
78 }
79 
80 
81 
82 
83 
84 
85 
86