Event Recoder调试组件在stm32上的使用

Event Recoder调试组件在stm32上的使用

本文目标:Event Recoder调试组件在stm32上的使用

按照本文的描述,应该可以在你所处的硬件上跑通代码。

先决条件:装有编译和集成的开发环境,比如:Keil uVision5。

板子硬件要求:无,属于调试功能。

起因

因为做产品开发,设计东西有时候考虑得多,mcu的并没有多余的串口供使用调试,在调试一些初期进行验证时,必要的调试的打印信息是需要的。

Event Recoder调试组件简介

嵌入式的Event Recoder调试组件是一种可以在MDK开发环境下使用的高级调试工具,它可以记录软件运行的一些标志信息,并以图形化的形式显示出来。它可以帮助你了解和分析内部操作,支持Keil RTX操作系统调试以及MDK自带的中间件的调试。它还可以测量代码运行的时间和功耗。它不需要占用芯片的外设资源,也不会影响代码的执行速度。

Event Recoder调试组件是MDK开发环境的一部分,官网是https://www.keil.com/。可以在这里找到更多关于Event Recoder调试组件的信息,比如使用教程,API文档,示例代码等。

使用

第1步:准备好一个工程模板,这里我使用的stm32cubemx生成的工程,大致配置如下:

在这里插入图片描述

第2步:使用MDK打开工程,创建RTE环境,并勾选对应Event Recoder功能的,如下:

在这里插入图片描述

第3步:工程添加的文件 EventRecorderConf.h,按照如下进行配置:

在这里插入图片描述

第4步:编写必要的代码进行验证

这里我在main.c中编写一些必要代码,代码片段如下:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"

#include "EventRecorder.h"
#include "EventRecorderConf.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
//int fputc( int ch, FILE *f )
//{
//	USART_TypeDef* USARTx = USART1;
//	while ((USARTx->SR & (1<<7)) == 0);
//	USARTx->DR = ch;
//	return ch;
//}

void Get_ChipID(uint32_t *ChipUniqueID)
{
	ChipUniqueID[0] = *(__IO uint32_t *)(0X1FFFF7F0); // 高字节
	ChipUniqueID[1] = *(__IO uint32_t *)(0X1FFFF7EC); // 
	ChipUniqueID[2] = *(__IO uint32_t *)(0X1FFFF7E8); // 低字节
}

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
	uint32_t ChipUniqueID[3] = {0};
  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
	EventRecorderInitialize(EventRecordAll, 1U);
	EventRecorderStart();
	Get_ChipID(ChipUniqueID);
	printf("\r\n芯片的唯一ID为: \r\n");
	
//	SEGGER_RTT_printf(0,"#define id_buff_0 0X%08X\r\n#define id_buff_1 0X%08X \r\n#define id_buff_2 0X%08X\r\n",
//	        ChipUniqueID[2],ChipUniqueID[1],ChipUniqueID[0]);
//	SEGGER_RTT_printf(0,"\r\n芯片flash的容量为: %dK \r\n", *(__IO uint16_t *)(0X1FFFF7E0));
	
	printf("#define id_buff_0 0X%08X\r\n#define id_buff_1 0X%08X \r\n#define id_buff_2 0X%08X\r\n",
	        ChipUniqueID[2],ChipUniqueID[1],ChipUniqueID[0]);
	printf("系统时钟:%d\r\n",SystemCoreClock);
 /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	HAL_Delay(500);
	HAL_GPIO_TogglePin(LED_B_GPIO_Port,LED_B_Pin);

  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */

  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{ 
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

实验结果

按照代码的逻辑,使用MDK自带的仿真功能,已经可以在调试的窗口中出现实验现象了,我这里主要是测试了一下必要的打印,上面的代码片段现象如下:

在这里插入图片描述

注意事项:

工程代码中不应该有对硬件串口的重映射,因为这里输出的内容是在控制台,而不是真实的串口。我在代码片段中就屏蔽了相关代码

//int fputc( int ch, FILE *f )
//{
//	USART_TypeDef* USARTx = USART1;
//	while ((USARTx->SR & (1<<7)) == 0);
//	USARTx->DR = ch;
//	return ch;
//}

我这里MDK的版本是5.28,如果版本太低的话,可能也没有实验现象,建议MDK的版本在5.22以上来跑,Compiler组件要在1.4.0以上。测试了一下,使用Jlink、CMSIS-DAP下载器均有实验现象,ST-Link理论上也支持,没测试。

本文完!感谢关注!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独处东汉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值