STM32G0学习手册——FreeRTOS软件定时器
Posted SCCELE
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32G0学习手册——FreeRTOS软件定时器相关的知识,希望对你有一定的参考价值。
1.创建好带有printf-stdarg.c的FreeRTOS的工程
2.修改main.c文件
/* USER CODE BEGIN Includes */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include <stdio.h>
#include <string.h>
/* USER CODE END Includes */
/* USER CODE BEGIN PV */
static TaskHandle_t AppTask_Handle = NULL;
static TimerHandle_t Timer1_Handle = NULL;
extern int f_printf(const char *format, ...);
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
static void AppTaskCreate(void);
static void TimerCallback(void);
/* USER CODE END PFP */
int main(void)
/*
*
*/
/* USER CODE BEGIN WHILE */
UBaseType_t xReturn = pdFALSE;
xReturn = xTaskCreate((TaskFunction_t)AppTaskCreate,
(const char *) "APPTASKCREATE",
(uint16_t) 128,
(void *) NULL,
(UBaseType_t) 1,
(TaskHandle_t *)&AppTask_Handle);
if(xReturn != NULL)
f_printf("Task Create PASS.\\r\\n");
vTaskStartScheduler();
while (1)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
/* USER CODE BEGIN 4 */
static void AppTaskCreate(void)
BaseType_t xReturn = pdFALSE;
Timer1_Handle = xTimerCreate( (const char *) "TIMER1",(TickType_t)1000,
pdTRUE, (void*) 1,(TimerCallbackFunction_t)TimerCallback);
if( Timer1_Handle !=NULL)
f_printf("Timer1 Create PASS.\\r\\n");
xReturn = xTimerStart(Timer1_Handle,0);
if(xReturn != pdFALSE)
f_printf("Timer1 START.\\r\\n");
vTaskDelete(AppTask_Handle);
static void TimerCallback(void)
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_1);
/* USER CODE END 4 */
以上是关于STM32G0学习手册——FreeRTOS软件定时器的主要内容,如果未能解决你的问题,请参考以下文章