mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_Silicon_Labs/TARGET_EFM32/emlib/src/em_dbg.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
- Parent:
- 179:b0033dcd6934
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /***************************************************************************//** |
<> | 144:ef7eb2e8f9f7 | 2 | * @file em_dbg.c |
<> | 144:ef7eb2e8f9f7 | 3 | * @brief Debug (DBG) Peripheral API |
AnnaBridge | 179:b0033dcd6934 | 4 | * @version 5.3.3 |
<> | 144:ef7eb2e8f9f7 | 5 | ******************************************************************************* |
AnnaBridge | 179:b0033dcd6934 | 6 | * # License |
<> | 150:02e0a0aed4ec | 7 | * <b>Copyright 2016 Silicon Laboratories, Inc. http://www.silabs.com</b> |
<> | 144:ef7eb2e8f9f7 | 8 | ******************************************************************************* |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Permission is granted to anyone to use this software for any purpose, |
<> | 144:ef7eb2e8f9f7 | 11 | * including commercial applications, and to alter it and redistribute it |
<> | 144:ef7eb2e8f9f7 | 12 | * freely, subject to the following restrictions: |
<> | 144:ef7eb2e8f9f7 | 13 | * |
<> | 144:ef7eb2e8f9f7 | 14 | * 1. The origin of this software must not be misrepresented; you must not |
<> | 144:ef7eb2e8f9f7 | 15 | * claim that you wrote the original software. |
<> | 144:ef7eb2e8f9f7 | 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
<> | 144:ef7eb2e8f9f7 | 17 | * misrepresented as being the original software. |
<> | 144:ef7eb2e8f9f7 | 18 | * 3. This notice may not be removed or altered from any source distribution. |
<> | 144:ef7eb2e8f9f7 | 19 | * |
<> | 144:ef7eb2e8f9f7 | 20 | * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no |
<> | 144:ef7eb2e8f9f7 | 21 | * obligation to support this Software. Silicon Labs is providing the |
<> | 144:ef7eb2e8f9f7 | 22 | * Software "AS IS", with no express or implied warranties of any kind, |
<> | 144:ef7eb2e8f9f7 | 23 | * including, but not limited to, any implied warranties of merchantability |
<> | 144:ef7eb2e8f9f7 | 24 | * or fitness for any particular purpose or warranties against infringement |
<> | 144:ef7eb2e8f9f7 | 25 | * of any proprietary rights of a third party. |
<> | 144:ef7eb2e8f9f7 | 26 | * |
<> | 144:ef7eb2e8f9f7 | 27 | * Silicon Labs will not be liable for any consequential, incidental, or |
<> | 144:ef7eb2e8f9f7 | 28 | * special damages, or any other relief, or for any claim by any third party, |
<> | 144:ef7eb2e8f9f7 | 29 | * arising from your use of this Software. |
<> | 144:ef7eb2e8f9f7 | 30 | * |
<> | 144:ef7eb2e8f9f7 | 31 | ******************************************************************************/ |
<> | 144:ef7eb2e8f9f7 | 32 | |
<> | 144:ef7eb2e8f9f7 | 33 | #include "em_dbg.h" |
<> | 144:ef7eb2e8f9f7 | 34 | |
AnnaBridge | 179:b0033dcd6934 | 35 | #if defined(CoreDebug_DHCSR_C_DEBUGEN_Msk) |
<> | 144:ef7eb2e8f9f7 | 36 | |
<> | 144:ef7eb2e8f9f7 | 37 | #include "em_assert.h" |
<> | 144:ef7eb2e8f9f7 | 38 | #include "em_cmu.h" |
<> | 144:ef7eb2e8f9f7 | 39 | #include "em_gpio.h" |
<> | 144:ef7eb2e8f9f7 | 40 | |
<> | 144:ef7eb2e8f9f7 | 41 | /***************************************************************************//** |
<> | 150:02e0a0aed4ec | 42 | * @addtogroup emlib |
<> | 144:ef7eb2e8f9f7 | 43 | * @{ |
<> | 144:ef7eb2e8f9f7 | 44 | ******************************************************************************/ |
<> | 144:ef7eb2e8f9f7 | 45 | |
<> | 144:ef7eb2e8f9f7 | 46 | /***************************************************************************//** |
<> | 144:ef7eb2e8f9f7 | 47 | * @addtogroup DBG |
<> | 144:ef7eb2e8f9f7 | 48 | * @brief Debug (DBG) Peripheral API |
<> | 150:02e0a0aed4ec | 49 | * @details |
<> | 150:02e0a0aed4ec | 50 | * This module contains functions to control the DBG peripheral of Silicon |
<> | 150:02e0a0aed4ec | 51 | * Labs 32-bit MCUs and SoCs. The Debug Interface is used to program and debug |
<> | 150:02e0a0aed4ec | 52 | * Silicon Labs devices. |
<> | 144:ef7eb2e8f9f7 | 53 | * @{ |
<> | 144:ef7eb2e8f9f7 | 54 | ******************************************************************************/ |
<> | 144:ef7eb2e8f9f7 | 55 | |
<> | 144:ef7eb2e8f9f7 | 56 | /******************************************************************************* |
<> | 144:ef7eb2e8f9f7 | 57 | ************************** GLOBAL FUNCTIONS ******************************* |
<> | 144:ef7eb2e8f9f7 | 58 | ******************************************************************************/ |
<> | 144:ef7eb2e8f9f7 | 59 | |
AnnaBridge | 179:b0033dcd6934 | 60 | #if defined(GPIO_ROUTE_SWOPEN) || defined(GPIO_ROUTEPEN_SWVPEN) |
<> | 144:ef7eb2e8f9f7 | 61 | /***************************************************************************//** |
<> | 144:ef7eb2e8f9f7 | 62 | * @brief |
<> | 144:ef7eb2e8f9f7 | 63 | * Enable Serial Wire Output (SWO) pin. |
<> | 144:ef7eb2e8f9f7 | 64 | * |
<> | 144:ef7eb2e8f9f7 | 65 | * @details |
<> | 144:ef7eb2e8f9f7 | 66 | * The SWO pin (sometimes denoted SWV, serial wire viewer) allows for |
<> | 144:ef7eb2e8f9f7 | 67 | * miscellaneous output to be passed from the Cortex-M3 debug trace module to |
<> | 144:ef7eb2e8f9f7 | 68 | * an external debug probe. By default, the debug trace module and pin output |
<> | 144:ef7eb2e8f9f7 | 69 | * may be disabled. |
<> | 144:ef7eb2e8f9f7 | 70 | * |
<> | 144:ef7eb2e8f9f7 | 71 | * Since the SWO pin is only useful when using a debugger, a suggested use |
<> | 144:ef7eb2e8f9f7 | 72 | * of this function during startup may be: |
<> | 144:ef7eb2e8f9f7 | 73 | * @verbatim |
<> | 144:ef7eb2e8f9f7 | 74 | * if (DBG_Connected()) |
<> | 144:ef7eb2e8f9f7 | 75 | * { |
<> | 144:ef7eb2e8f9f7 | 76 | * DBG_SWOEnable(1); |
<> | 144:ef7eb2e8f9f7 | 77 | * } |
<> | 144:ef7eb2e8f9f7 | 78 | * @endverbatim |
<> | 144:ef7eb2e8f9f7 | 79 | * By checking if debugger is attached, some setup leading to higher energy |
<> | 144:ef7eb2e8f9f7 | 80 | * consumption when debugger is attached, can be avoided when not using |
<> | 144:ef7eb2e8f9f7 | 81 | * a debugger. |
<> | 144:ef7eb2e8f9f7 | 82 | * |
<> | 144:ef7eb2e8f9f7 | 83 | * Another alternative may be to set the debugger tool chain to configure |
<> | 144:ef7eb2e8f9f7 | 84 | * the required setup (similar to the content of this function) by some |
<> | 144:ef7eb2e8f9f7 | 85 | * sort of toolchain scripting during its attach/reset procedure. In that |
<> | 144:ef7eb2e8f9f7 | 86 | * case, the above suggested code for enabling the SWO pin is not required |
<> | 144:ef7eb2e8f9f7 | 87 | * in the application. |
<> | 144:ef7eb2e8f9f7 | 88 | * |
<> | 144:ef7eb2e8f9f7 | 89 | * @param[in] location |
<> | 144:ef7eb2e8f9f7 | 90 | * Pin location used for SWO pin on the application in use. |
<> | 144:ef7eb2e8f9f7 | 91 | ******************************************************************************/ |
<> | 144:ef7eb2e8f9f7 | 92 | void DBG_SWOEnable(unsigned int location) |
<> | 144:ef7eb2e8f9f7 | 93 | { |
<> | 144:ef7eb2e8f9f7 | 94 | int port; |
<> | 144:ef7eb2e8f9f7 | 95 | int pin; |
<> | 144:ef7eb2e8f9f7 | 96 | |
<> | 144:ef7eb2e8f9f7 | 97 | EFM_ASSERT(location < AFCHANLOC_MAX); |
<> | 144:ef7eb2e8f9f7 | 98 | |
AnnaBridge | 179:b0033dcd6934 | 99 | #if defined (AF_DBG_SWO_PORT) |
<> | 144:ef7eb2e8f9f7 | 100 | port = AF_DBG_SWO_PORT(location); |
<> | 144:ef7eb2e8f9f7 | 101 | pin = AF_DBG_SWO_PIN(location); |
AnnaBridge | 179:b0033dcd6934 | 102 | #elif defined (AF_DBG_SWV_PORT) |
<> | 144:ef7eb2e8f9f7 | 103 | port = AF_DBG_SWV_PORT(location); |
<> | 144:ef7eb2e8f9f7 | 104 | pin = AF_DBG_SWV_PIN(location); |
<> | 144:ef7eb2e8f9f7 | 105 | #else |
<> | 144:ef7eb2e8f9f7 | 106 | #warning "AF debug port is not defined." |
<> | 144:ef7eb2e8f9f7 | 107 | #endif |
<> | 144:ef7eb2e8f9f7 | 108 | |
<> | 144:ef7eb2e8f9f7 | 109 | /* Port/pin location not defined for device? */ |
AnnaBridge | 179:b0033dcd6934 | 110 | if ((pin < 0) || (port < 0)) { |
<> | 144:ef7eb2e8f9f7 | 111 | EFM_ASSERT(0); |
<> | 144:ef7eb2e8f9f7 | 112 | return; |
<> | 144:ef7eb2e8f9f7 | 113 | } |
<> | 144:ef7eb2e8f9f7 | 114 | |
<> | 144:ef7eb2e8f9f7 | 115 | /* Ensure auxiliary clock going to the Cortex debug trace module is enabled */ |
<> | 144:ef7eb2e8f9f7 | 116 | CMU_OscillatorEnable(cmuOsc_AUXHFRCO, true, false); |
<> | 144:ef7eb2e8f9f7 | 117 | |
<> | 144:ef7eb2e8f9f7 | 118 | /* Set selected pin location for SWO pin and enable it */ |
<> | 144:ef7eb2e8f9f7 | 119 | GPIO_DbgLocationSet(location); |
<> | 144:ef7eb2e8f9f7 | 120 | GPIO_DbgSWOEnable(true); |
<> | 144:ef7eb2e8f9f7 | 121 | |
<> | 144:ef7eb2e8f9f7 | 122 | /* Configure SWO pin for output */ |
<> | 144:ef7eb2e8f9f7 | 123 | GPIO_PinModeSet((GPIO_Port_TypeDef)port, pin, gpioModePushPull, 0); |
<> | 144:ef7eb2e8f9f7 | 124 | } |
<> | 144:ef7eb2e8f9f7 | 125 | #endif |
<> | 144:ef7eb2e8f9f7 | 126 | |
<> | 144:ef7eb2e8f9f7 | 127 | /** @} (end addtogroup DBG) */ |
<> | 150:02e0a0aed4ec | 128 | /** @} (end addtogroup emlib) */ |
<> | 144:ef7eb2e8f9f7 | 129 | #endif /* defined( CoreDebug_DHCSR_C_DEBUGEN_Msk ) */ |