1 /***************************************************************************//**
2 * @file
3 * @brief Debug (DBG) API
4 *******************************************************************************
5 * # License
6 * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
7 *******************************************************************************
8 *
9 * SPDX-License-Identifier: Zlib
10 *
11 * The licensor of this software is Silicon Laboratories Inc.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty. In no event will the authors be held liable for any damages
15 * arising from the use of this software.
16 *
17 * Permission is granted to anyone to use this software for any purpose,
18 * including commercial applications, and to alter it and redistribute it
19 * freely, subject to the following restrictions:
20 *
21 * 1. The origin of this software must not be misrepresented; you must not
22 * claim that you wrote the original software. If you use this software
23 * in a product, an acknowledgment in the product documentation would be
24 * appreciated but is not required.
25 * 2. Altered source versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software.
27 * 3. This notice may not be removed or altered from any source distribution.
28 *
29 ******************************************************************************/
30
31 #ifndef EM_DBG_H
32 #define EM_DBG_H
33
34 #include <stdbool.h>
35 #include "em_device.h"
36
37 #if defined(CoreDebug_DHCSR_C_DEBUGEN_Msk)
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /***************************************************************************//**
44 * @addtogroup dbg
45 * @{
46 ******************************************************************************/
47
48 /*******************************************************************************
49 ******************************** ENUMS ************************************
50 ******************************************************************************/
51
52 /** Lock modes */
53 typedef enum {
54 dbgLockModeAllowErase = 1UL, /**< Lock debug access. */
55 #if !defined(_SILICON_LABS_32B_SERIES_0)
56 dbgLockModePermanent = 2UL /**< Lock debug access permanently. */
57 #endif
58 } DBG_LockMode_TypeDef;
59
60 /*******************************************************************************
61 ***************************** PROTOTYPES **********************************
62 ******************************************************************************/
63
64 #if defined(GPIO_ROUTE_SWCLKPEN) \
65 || defined(GPIO_ROUTEPEN_SWCLKTCKPEN) \
66 || defined(GPIO_DBGROUTEPEN_SWCLKTCKPEN)
67 /***************************************************************************//**
68 * @brief
69 * Check if a debugger is connected (and debug session activated).
70 *
71 * @details
72 * Used to make run-time decisions depending on whether or not a debug session
73 * has been active since last reset, i.e., using a debug probe or similar. In
74 * some cases, special handling is required in that scenario.
75 *
76 * @return
77 * True if a debug session is active since last reset, otherwise false.
78 ******************************************************************************/
DBG_Connected(void)79 __STATIC_INLINE bool DBG_Connected(void)
80 {
81 return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? true : false;
82 }
83 #endif
84
85 #if defined(GPIO_ROUTE_SWOPEN) \
86 || defined(GPIO_ROUTEPEN_SWVPEN) \
87 || defined(GPIO_TRACEROUTEPEN_SWVPEN)
88 void DBG_SWOEnable(unsigned int location);
89 #endif
90
91 #if defined (EMU_CTRL_EM2DBGEN)
92 /***************************************************************************//**
93 * @brief
94 * Enable or disable debug support while in EM2 mode.
95 *
96 * @warning
97 * Disabling debug support in EM2 will reduce current consumption with 1-2 uA,
98 * but some debuggers will have problems regaining control over a device which
99 * is in EM2 and has debug support disabled.
100 *
101 * To remedy this, set the WSTK switch next to the battery holder to USB
102 * (powers down the EFR). Execute Simplicity Commander with command line
103 * parameters:
104 * "./commander.exe device recover"
105 * and then immediately move the switch to the AEM position. An additional
106 * "./commander.exe device masserase"
107 * command completes the recovery procedure.
108 *
109 * @param[in] enable
110 * Boolean true enables EM2 debug support, false disables.
111 ******************************************************************************/
DBG_EM2DebugEnable(bool enable)112 __STATIC_INLINE void DBG_EM2DebugEnable(bool enable)
113 {
114 if (enable) {
115 EMU->CTRL_SET = EMU_CTRL_EM2DBGEN;
116 } else {
117 EMU->CTRL_CLR = EMU_CTRL_EM2DBGEN;
118 }
119 }
120 #endif
121
122 /** @} (end addtogroup dbg) */
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif /* defined( CoreDebug_DHCSR_C_DEBUGEN_Msk ) */
129
130 #endif /* EM_DBG_H */
131