Silicon Labs a leading provider of microcontroller, sensing and wireless connectivity solutions for the Internet of Things (IoT).

Enabling Energy Profiler code correlation on mbed applications exported to Simplicity

07 Dec 2015

The problem of integrating the BSP trace setup request from a mbed imported project is that the mbed and bsp libraries do not appear to be compatible as of 12/3/2015. The fix to enable code correlation of an imported mbed project is the following:

1. switch the standard mbed libraries with the mbed-src libraries: - go to the https://developer.mbed.org/handbook/mbed-SDK - Scroll down until you find mbed-src on the right and the “Import Library” on the right - Click on “Import Library” - Change Import Name form “mbed-src” to “mbed” - Select the Target Path to your project name and click on “Import”

2. Next, add the following code at the top of your application. The below code was provided by Silicon Labs. I added it after #include "mbed.h"

/**************//

  • @brief Configure trace output for energyAware Profiler
  • @note Enabling trace will add 80uA current for the EFM32_Gxxx_STK.
  • DK's needs to be initialized with SPI-mode:
  • @verbatim BSP_Init(BSP_INIT_DK_SPI); @endverbatim
    • / void BSP_TraceSwoSetup(void) { /* Enable GPIO clock */ CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;

/* Enable Serial wire output pin */ GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;

/* Set correct location */ /* This location is valid for GG, LG and WG! */ GPIO->ROUTE = (GPIO->ROUTE & (_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC0;

/* Enable output on correct pin. */ /* This pin is valid for GG, LG and WG! */ GPIO->P[5].MODEL &= (_GPIO_P_MODEL_MODE2_MASK); GPIO->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;

/* Enable debug clock AUXHFRCO */ CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;

/* Wait until clock is ready */ while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;

/* Enable trace in core debug */ CoreDebug->DHCSR |= CoreDebug_DHCSR_C_DEBUGEN_Msk; CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

/* Enable PC and IRQ sampling output */ DWT->CTRL = 0x400113FF;

/* Set TPIU prescaler to 16. */ TPI->ACPR = 15;

/* Set protocol to NRZ */ TPI->SPPR = 2;

/* Disable continuous formatting */ TPI->FFCR = 0x100;

/* Unlock ITM and output data */ ITM->LAR = 0xC5ACCE55; ITM->TCR = 0x10009;

/* ITM Channel 0 is used for UART output */ ITM->TER |= (1UL << 0); }

3. The next step is to initialize the Swo port for code correlation. Place the following instruction as the first instruction of your main routine: - BSP_TraceSwoSetup(); 4. When you import your program into Simplicity, insure that you are using the "Debug" code configuration. 5. You should now be able to use the Energy Profiler with Code Correlation the next time you build and run the program under Profiler