1 /***************************************************************************//**
2 * @file
3 * @brief Debug (DBG) Peripheral API
4 * @author Energy Micro AS
5 * @version 3.0.0
6 *******************************************************************************
7 * @section License
8 * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
9 *******************************************************************************
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 *
21 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
22 * obligation to support this Software. Energy Micro AS is providing the
23 * Software "AS IS", with no express or implied warranties of any kind,
24 * including, but not limited to, any implied warranties of merchantability
25 * or fitness for any particular purpose or warranties against infringement
26 * of any proprietary rights of a third party.
27 *
28 * Energy Micro AS will not be liable for any consequential, incidental, or
29 * special damages, or any other relief, or for any claim by any third party,
30 * arising from your use of this Software.
31 *
32 ******************************************************************************/
33 #include "em_assert.h"
34 #include "em_dbg.h"
35 #include "em_cmu.h"
36 #include "em_gpio.h"
37
38 /***************************************************************************//**
39 * @addtogroup EM_Library
40 * @{
41 ******************************************************************************/
42
43 /***************************************************************************//**
44 * @addtogroup DBG
45 * @brief Debug (DBG) Peripheral API
46 * @{
47 ******************************************************************************/
48
49 /*******************************************************************************
50 ************************** GLOBAL FUNCTIONS *******************************
51 ******************************************************************************/
52
53 /***************************************************************************//**
54 * @brief
55 * Enable Serial Wire Output (SWO) pin.
56 *
57 * @details
58 * The SWO pin (sometimes denoted SWV, serial wire viewer) allows for
59 * miscellaneous output to be passed from the Cortex-M3 debug trace module to
60 * an external debug probe. By default, the debug trace module and pin output
61 * may be disabled.
62 *
63 * Since the SWO pin is only useful when using a debugger, a suggested use
64 * of this function during startup may be:
65 * @verbatim
66 * if (DBG_Connected())
67 * {
68 * DBG_SWOEnable(1);
69 * }
70 * @endverbatim
71 * By checking if debugger is attached, some setup leading to higher energy
72 * consumption when debugger is attached, can be avoided when not using
73 * a debugger.
74 *
75 * Another alternative may be to set the debugger tool chain to configure
76 * the required setup (similar to the content of this function) by some
77 * sort of toolchain scripting during its attach/reset procedure. In that
78 * case, the above suggested code for enabling the SWO pin is not required
79 * in the application.
80 *
81 * @param[in] location
82 * Pin location used for SWO pin on the application in use.
83 ******************************************************************************/
DBG_SWOEnable(unsigned int location)84 void DBG_SWOEnable(unsigned int location)
85 {
86 int port;
87 int pin;
88
89 EFM_ASSERT(location < AFCHANLOC_MAX);
90
91 port = AF_DBG_SWO_PORT(location);
92 pin = AF_DBG_SWO_PIN(location);
93
94 /* Port/pin location not defined for device? */
95 if ((pin < 0) || (port < 0))
96 {
97 EFM_ASSERT(0);
98 return;
99 }
100
101 /* Ensure auxiliary clock going to the Cortex debug trace module is enabled */
102 CMU_OscillatorEnable(cmuOsc_AUXHFRCO, true, false);
103
104 /* Set selected pin location for SWO pin and enable it */
105 GPIO_DbgLocationSet(location);
106 GPIO_DbgSWOEnable(true);
107
108 /* Configure SWO pin for output */
109 GPIO_PinModeSet((GPIO_Port_TypeDef)port, pin, gpioModePushPull, 0);
110 }
111
112 /** @} (end addtogroup DBG) */
113 /** @} (end addtogroup EM_Library) */
114