trace.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**************************************************************************//**
  2. * @file
  3. * @brief API for enabling SWO or ETM trace on DK3750 board
  4. * @author Energy Micro AS
  5. * @version 1.2.2
  6. ******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2011 Energy Micro AS, http://www.energymicro.com</b>
  9. ******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. *****************************************************************************/
  28. /***************************************************************************//**
  29. * @addtogroup BSP
  30. * @{
  31. ******************************************************************************/
  32. #include "efm32.h"
  33. #include "efm32_gpio.h"
  34. #include "efm32_cmu.h"
  35. /**************************************************************************//**
  36. * @brief Configure EFM32GG990F1024 for DK3750 ETM trace output
  37. * @note You need to configure ETM trace on on kit config menu as well!
  38. *****************************************************************************/
  39. void TRACE_ETMSetup(void)
  40. {
  41. /* Enable peripheral clocks */
  42. CMU->HFCORECLKEN0 |= CMU_HFCORECLKEN0_LE;
  43. CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
  44. CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
  45. /* Wait until AUXHFRCO clock is ready */
  46. while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
  47. /* Enable Port D, pins 3,4,5,6 for ETM Trace Data output */
  48. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE3_MASK) | GPIO_P_MODEL_MODE3_PUSHPULL;
  49. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE4_MASK) | GPIO_P_MODEL_MODE4_PUSHPULL;
  50. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE5_MASK) | GPIO_P_MODEL_MODE5_PUSHPULL;
  51. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE6_MASK) | GPIO_P_MODEL_MODE6_PUSHPULL;
  52. /* Enable Port D, pin 7 for DBG_TCLK */
  53. GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE7_MASK) | GPIO_P_MODEL_MODE7_PUSHPULL;
  54. /* Configure trace output for alternate location */
  55. GPIO->ROUTE = GPIO->ROUTE | GPIO_ROUTE_TCLKPEN | GPIO_ROUTE_TD0PEN | GPIO_ROUTE_TD1PEN
  56. | GPIO_ROUTE_TD2PEN | GPIO_ROUTE_TD3PEN
  57. | GPIO_ROUTE_ETMLOCATION_LOC0;
  58. }
  59. /**************************************************************************//**
  60. * @brief Configure EFM32GG990F1024 for DK3750 SWO trace output
  61. *****************************************************************************/
  62. void TRACE_SWOSetup(void)
  63. {
  64. /* Debug logic registers */
  65. volatile uint32_t *dwt_ctrl = (uint32_t *) 0xE0001000;
  66. volatile uint32_t *tpiu_prescaler = (uint32_t *) 0xE0040010;
  67. volatile uint32_t *tpiu_protocol = (uint32_t *) 0xE00400F0;
  68. /* Enable GPIO clock */
  69. CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
  70. /* Enable Serial wire output pin */
  71. GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
  72. /* Set location 0 */
  73. GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC0;
  74. /* Enable output on pin - GPIO Port F, Pin 2 */
  75. GPIO->P[5].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK);
  76. GPIO->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;
  77. /* Enable debug clock AUXHFRCO */
  78. CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
  79. /* Wait until clock is ready */
  80. while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
  81. /* Enable trace in core debug */
  82. CoreDebug->DHCSR |= 1;
  83. CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
  84. /* Enable PC and IRQ sampling output */
  85. *dwt_ctrl = 0x400113FF;
  86. /* Set TPIU prescaler to 16. */
  87. *tpiu_prescaler = 0xf;
  88. /* Set protocol to NRZ */
  89. *tpiu_protocol = 2;
  90. /* Unlock ITM and output data */
  91. ITM->LAR = 0xC5ACCE55;
  92. ITM->TCR = 0x10009;
  93. }
  94. /** @} (end group BSP) */