cancel
Showing results for 
Search instead for 
Did you mean: 

How to measure elapsed time in your STM32 application using an EventOut pin and an oscilloscope

Laurids_PETERSEN
Community manager
Community manager

Summary

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.

STM32CubeMX Setup

In this example, we use the STM32L746 Nucleo board.  The directions may be applied to any other STMicroelectronics board as well.  We use the STM32CubeMX to create the project.
1. Create a new project using STM32CubeMX and select the MCU part number in the selector window.

a. Double-click on the STM32L476RGT3 part number to begin a new project.

2. Under the Clock Configuration tab, adjust the value of HCLK to 24MHz.

24.png
  

3. Under the Pinout & Configuration select one pin to be the EVENTOUT function.  In this example, choose pin PC8.  

pin pc8.png

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]  

generate code.png

Code Setup

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 */

Results

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. 
 

shown below.png

Version history
Last update:
‎2024-01-03 09:16 AM
Updated by: