trace.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**************************************************************************//**
  2. * @file
  3. * @brief SWO Trace API (for eAProfiler)
  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. #include <stdbool.h>
  36. #include "efm32.h"
  37. #include "trace.h"
  38. /***************************************************************************//**
  39. * @addtogroup BSP
  40. * @{
  41. ******************************************************************************/
  42. /**************************************************************************//**
  43. * @brief Configure trace output for energyAware Profiler
  44. *****************************************************************************/
  45. void TRACE_SWOSetup(void)
  46. {
  47. uint32_t *dwt_ctrl = (uint32_t *) 0xE0001000;
  48. uint32_t *tpiu_prescaler = (uint32_t *) 0xE0040010;
  49. uint32_t *tpiu_protocol = (uint32_t *) 0xE00400F0;
  50. /* Enable GPIO clock */
  51. CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
  52. /* Enable Serial wire output pin */
  53. GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
  54. /* Set location 1 */
  55. GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC1;
  56. /* Enable output on pin */
  57. GPIO->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
  58. GPIO->P[2].MODEH |= GPIO_P_MODEH_MODE15_PUSHPULL;
  59. /* Enable debug clock AUXHFRCO */
  60. CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
  61. /* Wait until clock is ready */
  62. while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
  63. /* Enable trace in core debug */
  64. CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
  65. /* Enable PC and IRQ sampling output */
  66. *dwt_ctrl = 0x400113FF;
  67. /* Set TPIU prescaler to 16. */
  68. *tpiu_prescaler = 0xf;
  69. /* Set protocol to NRZ */
  70. *tpiu_protocol = 2;
  71. /* Unlock ITM and output data */
  72. ITM->LAR = 0xC5ACCE55;
  73. ITM->TCR = 0x10009;
  74. }
  75. /**************************************************************************//**
  76. * @brief Profiler configuration
  77. * @return true if energyAware Profiler/SWO is enabled, false if not
  78. * @note If first word of the user page is zero, this will not
  79. * enable SWO profiler output, see trace.h
  80. *****************************************************************************/
  81. bool TRACE_ProfilerSetup(void)
  82. {
  83. volatile uint32_t *userData = (uint32_t *) USER_PAGE;
  84. /* Check magic "trace" word in user page */
  85. if(*userData == 0x00000000UL)
  86. {
  87. return false;
  88. }
  89. else
  90. {
  91. TRACE_SWOSetup();
  92. return true;
  93. }
  94. }
  95. /** @} (end group BSP) */