em_dbg.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Debug (DBG) Peripheral API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  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. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #include "em_assert.h"
  34. #include "em_dbg.h"
  35. #include "em_cmu.h"
  36. #include "em_gpio.h"
  37. /***************************************************************************//**
  38. * @addtogroup EM_Library
  39. * @{
  40. ******************************************************************************/
  41. /***************************************************************************//**
  42. * @addtogroup DBG
  43. * @brief Debug (DBG) Peripheral API
  44. * @{
  45. ******************************************************************************/
  46. /*******************************************************************************
  47. ************************** GLOBAL FUNCTIONS *******************************
  48. ******************************************************************************/
  49. /***************************************************************************//**
  50. * @brief
  51. * Enable Serial Wire Output (SWO) pin.
  52. *
  53. * @details
  54. * The SWO pin (sometimes denoted SWV, serial wire viewer) allows for
  55. * miscellaneous output to be passed from the Cortex-M3 debug trace module to
  56. * an external debug probe. By default, the debug trace module and pin output
  57. * may be disabled.
  58. *
  59. * Since the SWO pin is only useful when using a debugger, a suggested use
  60. * of this function during startup may be:
  61. * @verbatim
  62. * if (DBG_Connected())
  63. * {
  64. * DBG_SWOEnable(1);
  65. * }
  66. * @endverbatim
  67. * By checking if debugger is attached, some setup leading to higher energy
  68. * consumption when debugger is attached, can be avoided when not using
  69. * a debugger.
  70. *
  71. * Another alternative may be to set the debugger tool chain to configure
  72. * the required setup (similar to the content of this function) by some
  73. * sort of toolchain scripting during its attach/reset procedure. In that
  74. * case, the above suggested code for enabling the SWO pin is not required
  75. * in the application.
  76. *
  77. * @param[in] location
  78. * Pin location used for SWO pin on the application in use.
  79. ******************************************************************************/
  80. void DBG_SWOEnable(unsigned int location)
  81. {
  82. int port;
  83. int pin;
  84. EFM_ASSERT(location < AFCHANLOC_MAX);
  85. port = AF_DBG_SWO_PORT(location);
  86. pin = AF_DBG_SWO_PIN(location);
  87. /* Port/pin location not defined for device? */
  88. if ((pin < 0) || (port < 0))
  89. {
  90. EFM_ASSERT(0);
  91. return;
  92. }
  93. /* Ensure auxiliary clock going to the Cortex debug trace module is enabled */
  94. CMU_OscillatorEnable(cmuOsc_AUXHFRCO, true, false);
  95. /* Set selected pin location for SWO pin and enable it */
  96. GPIO_DbgLocationSet(location);
  97. GPIO_DbgSWOEnable(true);
  98. /* Configure SWO pin for output */
  99. GPIO_PinModeSet((GPIO_Port_TypeDef)port, pin, gpioModePushPull, 0);
  100. }
  101. /** @} (end addtogroup DBG) */
  102. /** @} (end addtogroup EM_Library) */