如何不大更改原本的程式碼與Code,改成FreeRTOSv11 & SystemView Tool v3.52a
Step1: 下載FreeRTOSv11
Step2: 將新的FreeRTOS更新到Project上
上面已經替換好FreeRTOS跟SystemView的話,就不用Patch文件去做補強,繼續昨天的課程~
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
#include "SEGGER_SYSVIEW_FreeRTOS.h" //adding
#endif /* FREERTOS_CONFIG_H */
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetIdleTaskHandle 1 //adding, 設為1代表build時候會一併建構,設為0則不會
#define INCLUDE_pxTaskGetStackStart 1 //adding, same as above
/* Cortex-M specific definitions. */
改為:
#ifndef SEGGER_SYSVIEW_CORE
#define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3
#endif
#endif
改為:為RTT Buffer增加size,讓內存可以收集更多事件
#ifndef SEGGER_SYSVIEW_RTT_BUFFER_SIZE
#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE (1024 * 4)
#endif
改為:
// The application name to be displayed in SystemViewer
#define SYSVIEW_APP_NAME "FreeRTOS Hello World Application"
// The target device name
#define SYSVIEW_DEVICE_NAME "STM32F407-DISC-1"
This is required to maintain the time stamp information of application events.
SystemView will use the Cycle counter register value to keep the time stamp information of the events.
SWT_CYCCNT register of ARM Cortex M3/M4 processor stores the number of clock cycles that happened after the processor's reset.
By default, this register is disabled.
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
#define DWT_CTRL (*(volatile uint32_t*)0xE0001000) //adding
/* USER CODE END PV */
use it
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
DWT_CTRL |= (1 << 0); //adding
文件解釋:
To start the recordings of your FreeRTOS application, call the below SEGGER APIs.
SEGGER_SYSVIEW_Conf();
SEGGER_SYSVIEW_Start();
The segger systemview events recording starts only when you call SEGGER_SYSVIEW_Start().
We will call this from main.c
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
DWT_CTRL |= (1 << 0);
SEGGER_SYSVIEW_Conf(); //adding
SEGGER_SYSVIEW_Start(); //adding
../ThirdParty/SEGGER/SEGGER/SEGGER_RTT.h:60:10: fatal error: SEGGER_RTT_Conf.h: No such file or directory
Build當中遇見的錯誤:
#define traceTASK_SWITCHED_IN() { \
if(prvGetTCBFromHandle(NULL) == xIdleTaskHandle) { \
SEGGER_SYSVIEW_OnIdle(); \
} else { \
SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB); \
} \
}
From: https://github.com/sifive/example-freertos-blinky-systemview/blob/master/SEGGER_SYSVIEW_FreeRTOS.h
2. 原本Hello World新增的Code有誤undefined reference to MPU_xTaskCreate'
將在mpu_wrapper
中的#define xTaskCreate MPU_xTaskCreate
改為 #define xTaskCreate xTaskCreate
即可
終於! 成功Build過去了!
SEGGER_SYSVIEW_Start()
之後才執行Scheduler,要修改一下Core\Src\stm32f4xx_hal_msp.c一下,讓Scheduler在msrpc中手動初始化,而非到vTaskStartScheduler();
才初始化/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
#include "FreeRTOS.h" //adding
/* USER CODE END Includes */
/* System interrupt init*/
/* USER CODE BEGIN MspInit 1 */
//vInitPrioGroupValue();//原始課程推薦使用此api,但發現他來自patch file,但是使用新的FreeRTOS又不需要patch file(而且我用patch file會報錯)
NVIC_SetPriorityGrouping(0); // google 而來的解法,不確定可不可以
/* USER CODE END MspInit 1 */
0x200196ec
並記住WrOff大小178
這樣就產出這次事件的紀錄,明天開始用SYSVIEW來看記錄了甚麼事件吧~~