2023-06-21 09:41 AM - edited 2024-01-03 09:16 AM
This article describes the steps that are needed to make time measurements of code execution using the GPIO pins 'EVENT OUT' function and a lab oscilloscope. Most of the STM32s GPIOs can be placed in an alternate function of EVENTOUT. In this mode, when the CPU executes the assembly command 'SEV' an output pulse of length equal to one CPU clock period is output onto the pin.
3. Under the Pinout & Configuration select one pin to be the EVENTOUT function. In this example, choose pin PC8.
4. Under the Project Manager tab, choose a project location and project name in the project settings.
5. Select the toolchain / IDE for Keil® by selecting "MDK-ARM" in the project settings.
6. Click on [File] then select [Save Project].
7. Next select [Generate Code]
The following Send Event (SEV) assembly code is used to send a signal out the PC8 pin before and after the desired code to be measured. In this example, a simple loop was created to execute 10,000 NOPs, with a SEV command before and after. When trying to utilize this method we also turned off interrupts in the code just prior to the test loop as not to interfere with the loop timing.
/* USER CODE BEGIN 2 */
__disable_irq();
__asm("SEV");
for(uint32_t idx=0; idx < 10000; idx++)
{
__asm("NOP");
}
__asm("SEV");
/* USER CODE END 2 */
When the code is executed the time measurement between the two pulses from front the SEV assembly commands are measured at pin PC8 on an oscilloscope. The time measured is approximately 2.083ms as shown below.