trace.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**************************************************************************//**
  2. * @file
  3. * @brief API for enabling SWO or ETM trace on DK3750 board
  4. * @author Energy Micro AS
  5. * @version 2.0.1
  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. * 4. The source and compiled code may only be used on Energy Micro "EFM32"
  21. * microcontrollers and "EFR4" radios.
  22. *
  23. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  24. * obligation to support this Software. Energy Micro AS is providing the
  25. * Software "AS IS", with no express or implied warranties of any kind,
  26. * including, but not limited to, any implied warranties of merchantability
  27. * or fitness for any particular purpose or warranties against infringement
  28. * of any proprietary rights of a third party.
  29. *
  30. * Energy Micro AS will not be liable for any consequential, incidental, or
  31. * special damages, or any other relief, or for any claim by any third party,
  32. * arising from your use of this Software.
  33. *
  34. *****************************************************************************/
  35. /***************************************************************************//**
  36. * @addtogroup BSP
  37. * @{
  38. ******************************************************************************/
  39. #include <stdbool.h>
  40. #include "efm32.h"
  41. #include "em_gpio.h"
  42. #include "em_cmu.h"
  43. #include "trace.h"
  44. /**************************************************************************//**
  45. * @brief Configure EFM32GG990F1024 for DK3750 ETM trace output
  46. * @note You need to configure ETM trace on on kit config menu as well!
  47. *****************************************************************************/
  48. void TRACE_ETMSetup(void)
  49. {
  50. /* Enable peripheral clocks */
  51. CMU->HFCORECLKEN0 |= CMU_HFCORECLKEN0_LE;
  52. CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
  53. CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
  54. /* Wait until AUXHFRCO clock is ready */
  55. while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
  56. /* Enable Port D, pins 3,4,5,6 for ETM Trace Data output */
  57. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE3_MASK) | GPIO_P_MODEL_MODE3_PUSHPULL;
  58. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE4_MASK) | GPIO_P_MODEL_MODE4_PUSHPULL;
  59. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE5_MASK) | GPIO_P_MODEL_MODE5_PUSHPULL;
  60. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE6_MASK) | GPIO_P_MODEL_MODE6_PUSHPULL;
  61. /* Enable Port D, pin 7 for DBG_TCLK */
  62. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE7_MASK) | GPIO_P_MODEL_MODE7_PUSHPULL;
  63. /* Configure trace output for alternate location */
  64. GPIO->ROUTE = GPIO->ROUTE | GPIO_ROUTE_TCLKPEN | GPIO_ROUTE_TD0PEN | GPIO_ROUTE_TD1PEN
  65. | GPIO_ROUTE_TD2PEN | GPIO_ROUTE_TD3PEN
  66. | GPIO_ROUTE_ETMLOCATION_LOC0;
  67. }
  68. /**************************************************************************//**
  69. * @brief Configure trace output for energyAware Profiler
  70. * @note Kit needs to be initialized with SPI-mode;
  71. * @verbatim DVK_init(DVK_Init_SPI); @endverbatim
  72. *****************************************************************************/
  73. void TRACE_SWOSetup(void)
  74. {
  75. /* Debug logic registers */
  76. volatile uint32_t *dwt_ctrl = (uint32_t *) 0xE0001000;
  77. volatile uint32_t *tpiu_prescaler = (uint32_t *) 0xE0040010;
  78. volatile uint32_t *tpiu_protocol = (uint32_t *) 0xE00400F0;
  79. /* Enable GPIO clock */
  80. CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
  81. /* Enable Serial wire output pin */
  82. GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
  83. /* Set location 0 */
  84. GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC0;
  85. /* Enable output on pin - GPIO Port F, Pin 2 */
  86. GPIO->P[5].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK);
  87. GPIO->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;
  88. /* Enable debug clock AUXHFRCO */
  89. CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
  90. /* Wait until clock is ready */
  91. while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
  92. /* Enable trace in core debug */
  93. CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
  94. /* Enable PC and IRQ sampling output */
  95. *dwt_ctrl = 0x400113FF;
  96. /* Set TPIU prescaler to 16. */
  97. *tpiu_prescaler = 0xf;
  98. /* Set protocol to NRZ */
  99. *tpiu_protocol = 2;
  100. /* Unlock ITM and output data */
  101. ITM->LAR = 0xC5ACCE55;
  102. ITM->TCR = 0x10009;
  103. }
  104. /**************************************************************************//**
  105. * @brief Profiler configuration for EFM32GG990F11024/EFM32GG-DK3750
  106. * @return true if energyAware Profiler/SWO is enabled, false if not
  107. * @note If first word of the user page is zero, this will not
  108. * enable SWO profiler output
  109. *****************************************************************************/
  110. bool TRACE_ProfilerSetup(void)
  111. {
  112. volatile uint32_t *userData = (uint32_t *) USER_PAGE;
  113. /* Check magic "trace" word in user page */
  114. if(*userData == 0x00000000UL)
  115. {
  116. return false;
  117. }
  118. else
  119. {
  120. TRACE_SWOSetup();
  121. return true;
  122. }
  123. }
  124. /** @} (end group BSP) */