1 /*!
2  * @file        apm32f0xx_dbg.c
3  *
4  * @brief       This file provides all the DBG firmware functions
5  *
6  * @version     V1.0.3
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Includes */
27 #include "apm32f0xx_dbg.h"
28 
29 /** @addtogroup APM32F0xx_StdPeriphDriver
30   @{
31 */
32 
33 /** @addtogroup DBG_Driver
34   @{
35 */
36 
37 /** @defgroup DBG_Macros Macros
38   @{
39 */
40 
41 /**@} end of group DBG_Macros */
42 
43 /** @defgroup DBG_Enumerations Enumerations
44   @{
45 */
46 
47 /**@} end of group DBG_Enumerations*/
48 
49 /** @defgroup DBG_Structures Structures
50   @{
51 */
52 
53 /**@} end of group DBG_Structures */
54 
55 /** @defgroup DBG_Variables Variables
56   @{
57 */
58 
59 /**@} end of group DBG_Variables */
60 
61 /** @defgroup DBG_Functions Functions
62   @{
63 */
64 
65 /*!
66  * @brief     Read Device Identifier
67  *
68  * @param     None
69  *
70  * @retval    The value of the Device Identifier
71  */
DBG_ReadDevId(void)72 uint32_t DBG_ReadDevId(void)
73 {
74     return ((uint32_t)DBG->IDCODE_B.EQR);
75 }
76 
77 /*!
78  * @brief     Read Revision Identifier
79  *
80  * @param     None
81  *
82  * @retval    The value of the Revision Identifier
83  */
DBG_ReadRevId(void)84 uint32_t DBG_ReadRevId(void)
85 {
86     return ((uint32_t)DBG->IDCODE_B.WVR);
87 }
88 
89 /*!
90  * @brief     Enable Debug Mode
91  *
92  * @param     mode: specifies the low power mode.
93  *                  The parameter can be combination of following values:
94  *                  @arg DBG_MODE_STOP:    Keep debugger connection during STOP mode
95  *                  @arg DBG_MODE_STANDBY: Keep debugger connection during STANDBY mode
96  * @retval    None
97  */
DBG_EnableDebugMode(uint32_t mode)98 void DBG_EnableDebugMode(uint32_t mode)
99 {
100     DBG->CFG |= (uint32_t)mode;
101 }
102 
103 /*!
104  * @brief     Disable Debug Mode
105  *
106  * @param     mode: specifies the low power mode.
107  *                  The parameter can be combination of following values:
108  *                  @arg DBG_MODE_STOP:    Keep debugger connection during STOP mode
109  *                  @arg DBG_MODE_STANDBY: Keep debugger connection during STANDBY mode
110  * @retval    None
111  */
DBG_DisableDebugMode(uint32_t mode)112 void DBG_DisableDebugMode(uint32_t mode)
113 {
114     DBG->CFG &= (uint32_t)~mode;
115 }
116 
117 /*!
118  * @brief     Enable APB1 peripheral in Debug mode.
119  *
120  * @param     peripheral: Specifies the APB1 peripheral.
121  *                        The parameter can be combination of following values:
122  *                        @arg DBG_APB1_PER_TMR2_STOP:    TMR2  counter stopped when Core is halted, Not for APM32F030 devices
123  *                        @arg DBG_APB1_PER_TMR3_STOP:    TMR3  counter stopped when Core is halted
124  *                        @arg DBG_APB1_PER_TMR6_STOP:    TMR6  counter stopped when Core is halted
125  *                        @arg DBG_APB1_PER_TMR7_STOP:    TMR7  counter stopped when Core is halted��Only for APM32F072 and APM32F091 devices
126  *                        @arg DBG_APB1_PER_TMR14_STOP:   TMR14 counter stopped when Core is halted
127  *                        @arg DBG_APB1_PER_RTC_STOP:     RTC   counter stopped when Core is halted
128  *                        @arg DBG_APB1_PER_WWDT_STOP:    Debug WWDT stopped when Core is halted
129  *                        @arg DBG_APB1_PER_IWDT_STOP:    Debug IWDT stopped when Core is halted
130  *                        @arg DBG_APB1_PER_CAN_STOP:     Debug CAN stopped when Core is halted��Only for APM32F072 and APM32F091 devices
131  *                        @arg DBG_APB1_PER_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted
132  * @retval      None
133  */
DBG_EnableAPB1Periph(uint32_t peripheral)134 void DBG_EnableAPB1Periph(uint32_t peripheral)
135 {
136     DBG->APB1F |= (uint32_t)peripheral;
137 }
138 
139 /*!
140  * @brief     Disable APB1 peripheral in Debug mode.
141  *
142  * @param     peripheral: Specifies the APB1 peripheral.
143  *                        The parameter can be combination of following values:
144  *                        @arg DBG_APB1_PER_TMR2_STOP:    TMR2  counter stopped when Core is halted, Not for APM32F030 devices
145  *                        @arg DBG_APB1_PER_TMR3_STOP:    TMR3  counter stopped when Core is halted
146  *                        @arg DBG_APB1_PER_TMR6_STOP:    TMR6  counter stopped when Core is halted
147  *                        @arg DBG_APB1_PER_TMR7_STOP:    TMR7  counter stopped when Core is halted��Only for APM32F072 and APM32F091 devices
148  *                        @arg DBG_APB1_PER_TMR14_STOP:   TMR14 counter stopped when Core is halted
149  *                        @arg DBG_APB1_PER_RTC_STOP:     RTC   counter stopped when Core is halted
150  *                        @arg DBG_APB1_PER_WWDT_STOP:    Debug WWDT stopped when Core is halted
151  *                        @arg DBG_APB1_PER_IWDT_STOP:    Debug IWDT stopped when Core is halted
152  *                        @arg DBG_APB1_PER_CAN_STOP:     Debug CAN stopped when Core is halted��Only for APM32F072 and APM32F091 devices
153  *                        @arg DBG_APB1_PER_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted
154  * @retval      None
155  */
DBG_DisableAPB1Periph(uint32_t peripheral)156 void DBG_DisableAPB1Periph(uint32_t peripheral)
157 {
158     DBG->APB1F &= (uint32_t)~peripheral;
159 }
160 
161 /*!
162  * @brief     Enable APB2 peripheral in Debug mode.
163  *
164  * @param     peripheral: Specifies the APB2 peripheral.
165  *                        The parameter can be combination of following values:
166  *                        @arg DBG_APB2_PER_TMR1_STOP:    TMR1  counter stopped when Core is halted
167  *                        @arg DBG_APB2_PER_TMR15_STOP:   TMR15 counter stopped when Core is halted
168  *                        @arg DBG_APB2_PER_TMR16_STOP:   TMR16 counter stopped when Core is halted
169  *                        @arg DBG_APB2_PER_TMR17_STOP:   TMR17 counter stopped when Core is halted
170  * @retval      None
171  */
DBG_EnableAPB2Periph(uint32_t peripheral)172 void DBG_EnableAPB2Periph(uint32_t peripheral)
173 {
174     DBG->APB2F |= (uint32_t)peripheral;
175 }
176 
177 /*!
178  * @brief     Disable APB2 peripheral in Debug mode.
179  *
180  * @param     peripheral: Specifies the APB2 peripheral.
181  *                        The parameter can be combination of following values:
182  *                        @arg DBG_APB2_PER_TMR1_STOP:    TMR1  counter stopped when Core is halted
183  *                        @arg DBG_APB2_PER_TMR15_STOP:   TMR15 counter stopped when Core is halted
184  *                        @arg DBG_APB2_PER_TMR16_STOP:   TMR16 counter stopped when Core is halted
185  *                        @arg DBG_APB2_PER_TMR17_STOP:   TMR17 counter stopped when Core is halted
186  *
187  * @retval    None
188  */
DBG_DisableAPB2Periph(uint32_t peripheral)189 void DBG_DisableAPB2Periph(uint32_t peripheral)
190 {
191     DBG->APB2F &= (uint32_t)~peripheral;
192 }
193 
194 /**@} end of group DBG_Functions */
195 /**@} end of group DBG_Driver */
196 /**@} end of group APM32F0xx_StdPeriphDriver */
197