Event Recoder調(diào)試組件在stm32上的使用
本文目標(biāo):Event_Recoder調(diào)試組件在stm32上的使用
按照本文的描述,應(yīng)該可以在你所處的硬件上跑通代碼。
先決條件:裝有編譯和集成的開(kāi)發(fā)環(huán)境,比如:Keil uVision5。
板子硬件要求:無(wú),屬于調(diào)試功能。
起源
因?yàn)樽霎a(chǎn)品開(kāi)發(fā),設(shè)計(jì)東西有時(shí)候考慮得多,mcu的并沒(méi)有多余的串口供使用調(diào)試,在調(diào)試一些初期進(jìn)行驗(yàn)證時(shí),必要的調(diào)試的打印信息是需要的。
Event Recoder調(diào)試組件簡(jiǎn)介
嵌入式的Event_Recoder調(diào)試組件是一種可以在MDK開(kāi)發(fā)環(huán)境下使用的高級(jí)調(diào)試工具,它可以記錄軟件運(yùn)行的一些標(biāo)志信息,并以圖形化的形式顯示出來(lái)。它可以幫助你了解和分析內(nèi)部操作,支持Keil RTX操作系統(tǒng)調(diào)試以及MDK自帶的中間件的調(diào)試。它還可以測(cè)量代碼運(yùn)行的時(shí)間和功耗。它不需要占用芯片的外設(shè)資源,也不會(huì)影響代碼的執(zhí)行速度。
Event Recoder調(diào)試組件是MDK開(kāi)發(fā)環(huán)境的一部分,官網(wǎng)是https://www.keil.com/。可以在這里找到更多關(guān)于Event Recoder調(diào)試組件的信息,比如使用教程,API文檔,示例代碼等。
使用
第1步:準(zhǔn)備好一個(gè)工程模板,這里我使用的stm32cubemx生成的工程,大致配置如下:
第2步:使用MDK打開(kāi)工程,創(chuàng)建RTE環(huán)境,并勾選對(duì)應(yīng)Event Recoder功能的,如下:
第3步:工程添加的文件 EventRecorderConf.h,按照如下進(jìn)行配置:
第4步:編寫必要的代碼進(jìn)行驗(yàn)證
這里我在main.c中編寫一些必要代碼,代碼片段如下:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* ? Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* 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
#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); // 高字節(jié)
ChipUniqueID[1] = *(__IO uint32_t *)(0X1FFFF7EC); //
ChipUniqueID[2] = *(__IO uint32_t *)(0X1FFFF7E8); // 低字節(jié)
}
/* 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("系統(tǒng)時(shí)鐘:%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****/
實(shí)驗(yàn)結(jié)果
按照代碼的邏輯,使用MDK自帶的仿真功能,已經(jīng)可以在調(diào)試的窗口中出現(xiàn)實(shí)驗(yàn)現(xiàn)象了,我這里主要是測(cè)試了一下必要的打印,上面的代碼片段現(xiàn)象如下:
注意事項(xiàng):
工程代碼中不應(yīng)該有對(duì)硬件串口的重映射,因?yàn)檫@里輸出的內(nèi)容是在控制臺(tái),而不是真實(shí)的串口。我在代碼片段中就屏蔽了相關(guān)代碼
//int fputc( int ch, FILE *f )
//{
// USART_TypeDef* USARTx = USART1;
// while ((USARTx->SR & (1<<7)) == 0);
// USARTx->DR = ch;
// return ch;
//}
我這里MDK的版本是5.28,如果版本太低的話,可能也沒(méi)有實(shí)驗(yàn)現(xiàn)象,建議MDK的版本在5.22以上來(lái)跑,Compiler組件要在1.4.0以上。測(cè)試了一下,使用Jlink、CMSIS-DAP下載器均有實(shí)驗(yàn)現(xiàn)象,ST-Link理論上也支持,沒(méi)測(cè)試。
-
mcu
+關(guān)注
關(guān)注
146文章
17750瀏覽量
358691 -
STM32
+關(guān)注
關(guān)注
2287文章
10988瀏覽量
361564 -
調(diào)試
+關(guān)注
關(guān)注
7文章
603瀏覽量
34436 -
串口
+關(guān)注
關(guān)注
14文章
1580瀏覽量
78413 -
keil
+關(guān)注
關(guān)注
69文章
1218瀏覽量
168668
發(fā)布評(píng)論請(qǐng)先 登錄
【原創(chuàng)專題教程第7期】終極調(diào)試組件Event Recorder,各種Link通吃,支持時(shí)間和功耗測(cè)量,printf打印,RTX5及中間件調(diào)試
Event Recoder是什么
STM32F407的終極調(diào)試組件Event Recorder
介紹終極調(diào)試方案Event Recoder
淺析基于GD32F427適配RTX4+調(diào)試組件Event Recorder
可以將終端控制臺(tái)定向?yàn)?b class='flag-5'>調(diào)試器的Real Time Transfer或Event Recoder嗎?如何操作?
stm32固件庫(kù)在stm3210e-eval開(kāi)發(fā)板上的移植

【STM32F429開(kāi)發(fā)板用戶手冊(cè)】第8章 STM32F429的終極調(diào)試組件Event Recorder

【STM32F407開(kāi)發(fā)板用戶手冊(cè)】第8章 STM32F407的終極調(diào)試組件Event Recorder

【STM32H7教程】第8章 STM32H7的終極調(diào)試組件Event Recorder

STM32 低功耗睡眠模式(SLEEP)事件(EVENT)喚醒實(shí)現(xiàn)及優(yōu)化

評(píng)論