bsp_trace.c

Go to the documentation of this file.
00001 /**************************************************************************/
00035 #include <stdbool.h>
00036 #include "em_device.h"
00037 #include "em_gpio.h"
00038 #include "em_cmu.h"
00039 #include "bsp_trace.h"
00040 #include "bsp.h"
00041 
00042 #if defined(BSP_ETM_TRACE) && defined( ETM_PRESENT )
00043 /**************************************************************************/
00047 void BSP_TraceEtmSetup(void)
00048 {
00049   /* Enable peripheral clocks */
00050   CMU->HFCORECLKEN0 |= CMU_HFCORECLKEN0_LE;
00051   CMU->HFPERCLKEN0  |= CMU_HFPERCLKEN0_GPIO;
00052   CMU->OSCENCMD      = CMU_OSCENCMD_AUXHFRCOEN;
00053 
00054   /* Wait until AUXHFRCO clock is ready */
00055   while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
00056 
00057   /* Enable Port D, pins 3,4,5,6 for ETM Trace Data output */
00058   GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE3_MASK) | GPIO_P_MODEL_MODE3_PUSHPULL;
00059   GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE4_MASK) | GPIO_P_MODEL_MODE4_PUSHPULL;
00060   GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE5_MASK) | GPIO_P_MODEL_MODE5_PUSHPULL;
00061   GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE6_MASK) | GPIO_P_MODEL_MODE6_PUSHPULL;
00062 
00063   /* Enable Port D, pin 7 for DBG_TCLK */
00064   GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE7_MASK) | GPIO_P_MODEL_MODE7_PUSHPULL;
00065 
00066   /* Configure trace output for alternate location */
00067   GPIO->ROUTE = GPIO->ROUTE | GPIO_ROUTE_TCLKPEN | GPIO_ROUTE_TD0PEN | GPIO_ROUTE_TD1PEN
00068                 | GPIO_ROUTE_TD2PEN | GPIO_ROUTE_TD3PEN
00069                 | GPIO_ROUTE_ETMLOCATION_LOC0;
00070 }
00071 #endif
00072 
00073 /**************************************************************************/
00079 void BSP_TraceSwoSetup(void)
00080 {
00081   /* Enable GPIO clock */
00082   CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
00083 
00084   /* Enable Serial wire output pin */
00085   GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
00086 
00087   /* Set correct location */
00088   GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | BSP_TRACE_SWO_LOCATION;
00089 
00090   /* Enable output on correct pin. */
00091   TRACE_ENABLE_PINS();
00092 
00093   /* Enable debug clock AUXHFRCO */
00094   CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
00095 
00096   /* Wait until clock is ready */
00097   while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
00098 
00099   /* Enable trace in core debug */
00100   CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
00101 
00102   /* Enable PC and IRQ sampling output */
00103   DWT->CTRL = 0x400113FF;
00104 
00105   /* Set TPIU prescaler to 16. */
00106   TPI->ACPR = 0xf;
00107 
00108   /* Set protocol to NRZ */
00109   TPI->SPPR = 2;
00110 
00111   /* Unlock ITM and output data */
00112   ITM->LAR = 0xC5ACCE55;
00113   ITM->TCR = 0x10009;
00114 }
00115 
00116 
00117 /**************************************************************************/
00123 bool BSP_TraceProfilerSetup(void)
00124 {
00125   volatile uint32_t *userData = (uint32_t *) USER_PAGE;
00126 
00127   /* Check magic "trace" word in user page */
00128   if (*userData == 0x00000000UL)
00129   {
00130     return false;
00131   }
00132   else
00133   {
00134     BSP_TraceSwoSetup();
00135     return true;
00136   }
00137 }