2023-06-21 10:06 AM - edited 2023-12-07 05:40 AM
This article describes the steps that are needed in Keil®'s µvision configuration to ensure proper time measurement value is given when using the event recorder.
In this example, we use the STM32L746 Nucleo board. The directions may be applied to any other STMicroelectronics board as well. We use 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.
3. Under the project manager tab, choose a project location and project name in the project settings.
4. Select the toolchain / IDE for Keil® by selecting "MDK-ARM" in the project settings.
5. Click on [file] then select [save project].
6. Next select [generate code] to generate the code and launch the Kiel IDE.
1. In Keil® highlight the project name in the project window then select [project] [options for Target '<project name>'], next select the [Debug] tab. Select the [settings] button just right of the use 'ST-LINK Debugger' to bring up the Target Driver Setup window.
2. Select the [Trace] tab. Then adjust the Core Clock to the correct frequency, 24Mhz in our example. Select [Trace Enable]. Deselect the [EXCTRC: Exception Tracing]. Click OK
3. Bring up the Manage Run-Time Environment by selecting [project] -> [manage] -> [Run-Time Environment]. Expand the compiler options and select the event recorder via the DAP. Select OK
4. Under the project window find the compiler listing and double click on the 'EvenRecorderConf.h' file. Click on the [Configuration Wizard] at the bottom of the EventRecorder.h viewing window.
5. In the configuration wizard, expand the event recorder listing and enter the frequency of the HCLK you have set for your design. 24000000 Hz for our example.
6. Click the [Text Editor] tab to open the text editor for the EventrecorderConf.h, Confirm the setting for the EVENT_TIMESTAMP_FREQ is updated correctly from using the wizard. Save the file.
1. Add the event recorder header file to the include section of main.c file; between the User Code includes section.
#include "EventRecorder.h
As shown below:
2. Initialize and start the event recorder by adding the following two lines at the beginning of main().
EventRecorderInitialize(EventRecordAll,1);
EventRecorderStart();
As shown below:
3. Use the EventRecord2() function found in EventRecorder.c file to mark the beginning and the end of the code segment you want to measure. We will use an identifier value of '1' and '2' in the events to mark the begging and the end respectively. A simple loop is used for this exercise to be timed.
For example:
/* USER CODE BEGIN 2 */
EventRecord2(0,0,1);
for(uint32_t idx=0; idx < 10000; idx++)
{
__asm("NOP");
}
EventRecord2(0,0,2);
/* USER CODE END 2 */
As shown below:
1. Build the project and then select the spy glass to debug the application.
1. Turn on the analysis window for the event recorder. Select [View] [Analysis Windows] and then [Event Recorder].
2. With the event recorder 'Enable' box checked, select the 'Start Code Execution' icon button.
3. The results should be displayed in a few moments showing the time event when marker 1 and 2 happened. The time difference between the two events indicates the time needed to execute code between the two EventRecord2() commands.
For this example, finding the difference between the two time events results in 2.09730 mS.
Further details on using the event recorder can be found on Keil®'s website here:
https://www.keil.com/pack/doc/compiler/EventRecorder/html/er_use.html