1 /**************************************************************************//**
\r
3 * @brief API for enabling SWO and ETM trace.
\r
5 ******************************************************************************
\r
7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * This file is licensed under the Silabs License Agreement. See the file
\r
11 * "Silabs_License_Agreement.txt" for details. Before using this software for
\r
12 * any purpose, you must agree to the terms of that agreement.
\r
14 ******************************************************************************/
\r
18 #include <stdbool.h>
\r
19 #include "em_device.h"
\r
20 #include "em_gpio.h"
\r
22 #include "bsp_trace.h"
\r
25 #if defined( BSP_ETM_TRACE ) && defined( ETM_PRESENT )
\r
26 /**************************************************************************//**
\r
27 * @brief Configure EFM32 for ETM trace output.
\r
28 * @note You need to configure ETM trace on kit config menu as well!
\r
29 *****************************************************************************/
\r
30 void BSP_TraceEtmSetup(void)
\r
32 /* Enable peripheral clocks */
\r
33 CMU->HFCORECLKEN0 |= CMU_HFCORECLKEN0_LE;
\r
34 CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
\r
35 CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
\r
37 /* Wait until AUXHFRCO clock is ready */
\r
38 while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
\r
40 /* Enable Port D, pins 3,4,5,6 for ETM Trace Data output */
\r
41 GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE3_MASK) | GPIO_P_MODEL_MODE3_PUSHPULL;
\r
42 GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE4_MASK) | GPIO_P_MODEL_MODE4_PUSHPULL;
\r
43 GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE5_MASK) | GPIO_P_MODEL_MODE5_PUSHPULL;
\r
44 GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE6_MASK) | GPIO_P_MODEL_MODE6_PUSHPULL;
\r
46 /* Enable Port D, pin 7 for DBG_TCLK */
\r
47 GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE7_MASK) | GPIO_P_MODEL_MODE7_PUSHPULL;
\r
49 /* Configure trace output for alternate location */
\r
50 GPIO->ROUTE = GPIO->ROUTE | GPIO_ROUTE_TCLKPEN | GPIO_ROUTE_TD0PEN | GPIO_ROUTE_TD1PEN
\r
51 | GPIO_ROUTE_TD2PEN | GPIO_ROUTE_TD3PEN
\r
52 | GPIO_ROUTE_ETMLOCATION_LOC0;
\r
56 #if defined( _GPIO_ROUTE_SWOPEN_MASK ) || defined( _GPIO_ROUTEPEN_SWVPEN_MASK )
\r
57 /**************************************************************************//**
\r
58 * @brief Configure trace output for energyAware Profiler
\r
59 * @note Enabling trace will add 80uA current for the EFM32_Gxxx_STK.
\r
60 * DK's needs to be initialized with SPI-mode:
\r
61 * @verbatim BSP_Init(BSP_INIT_DK_SPI); @endverbatim
\r
62 *****************************************************************************/
\r
63 void BSP_TraceSwoSetup(void)
\r
65 /* Enable GPIO clock */
\r
66 #if defined( _CMU_HFPERCLKEN0_GPIO_MASK )
\r
67 CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
\r
68 #elif defined( _CMU_HFBUSCLKEN0_GPIO_MASK )
\r
69 CMU->HFBUSCLKEN0 |= CMU_HFBUSCLKEN0_GPIO;
\r
72 /* Enable Serial wire output pin */
\r
73 #if defined( _GPIO_ROUTE_SWOPEN_MASK )
\r
74 GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
\r
75 #elif defined( _GPIO_ROUTEPEN_SWVPEN_MASK )
\r
76 GPIO->ROUTEPEN |= GPIO_ROUTEPEN_SWVPEN;
\r
79 /* Set correct location */
\r
80 #if defined( _GPIO_ROUTE_SWOPEN_MASK )
\r
81 GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | BSP_TRACE_SWO_LOCATION;
\r
82 #elif defined( _GPIO_ROUTEPEN_SWVPEN_MASK )
\r
83 GPIO->ROUTELOC0 = (GPIO->ROUTELOC0 & ~(_GPIO_ROUTELOC0_SWVLOC_MASK)) | BSP_TRACE_SWO_LOCATION;
\r
86 /* Enable output on correct pin. */
\r
87 TRACE_ENABLE_PINS();
\r
89 /* Enable debug clock AUXHFRCO */
\r
90 CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
\r
92 /* Wait until clock is ready */
\r
93 while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
\r
95 /* Enable trace in core debug */
\r
96 CoreDebug->DHCSR |= CoreDebug_DHCSR_C_DEBUGEN_Msk;
\r
97 CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
\r
99 /* Enable PC and IRQ sampling output */
\r
100 DWT->CTRL = 0x400113FF;
\r
102 /* Set TPIU prescaler to 16. */
\r
105 /* Set protocol to NRZ */
\r
108 /* Disable continuous formatting */
\r
111 /* Unlock ITM and output data */
\r
112 ITM->LAR = 0xC5ACCE55;
\r
113 ITM->TCR = 0x10009;
\r
115 /* ITM Channel 0 is used for UART output */
\r
116 ITM->TER |= (1UL << 0);
\r
121 #if defined( _GPIO_ROUTE_SWOPEN_MASK ) || defined( _GPIO_ROUTEPEN_SWVPEN_MASK )
\r
122 /**************************************************************************//**
\r
123 * @brief Profiler configuration.
\r
124 * @return true if energyAware Profiler/SWO is enabled, false if not
\r
125 * @note If first word of the user page is zero, this will not
\r
126 * enable SWO profiler output.
\r
127 *****************************************************************************/
\r
128 bool BSP_TraceProfilerSetup(void)
\r
130 volatile uint32_t *userData = (uint32_t *) USER_PAGE;
\r
132 /* Check magic "trace" word in user page */
\r
133 if (*userData == 0x00000000UL)
\r
139 BSP_TraceSwoSetup();
\r