【F769IDISCOVERY评测】评测九 FREERTOS(增补篇)
STM32CubeMX(STM32官网)中已经集成了FREERTOS,这给我们使用RTOS带来不少方便。本评测在STM32CubeMX下建立一个新工程,启用FREERTOS,运行3个任务。项目中添加了STM32Cube_FW_V1.50中的STM32F769I Discovery LCD_DSI驱动,在开发板上的3个任务以不同频率各自点亮/熄灭LED,同时在LCD屏幕上将工作状态实时显示出来。启用FREERTOS
配置系统时钟216MHZ
配置LED的GPIO为输出
FREERTOS配置,添加3个任务
把STM32Cube_FW_F7_V1.5.0\Drivers\BSP\STM32F769I-Discovery 文件夹复制到项目的文件夹内,把STM32Cube_FW_F7_V1.5.0\Drivers\BSP\Components\otm8009a 文件夹复制到项目的文件夹内, 添加LCD驱动
添加驱动的路径
添加相关的STM32F7XX_HAL_Driver
LCD初始化在main()函数中#include "main.h"
#include "stm32f7xx_hal.h"
#include "cmsis_os.h"
#include "usart.h"
#include "gpio.h"
static void LCD_Config(void);
void SystemClock_Config(void);
void Error_Handler(void);
void MX_FREERTOS_Init(void);
int main(void)
{
SCB_EnableICache();
SCB_EnableDCache();
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
LCD_Config();
MX_FREERTOS_Init();
osKernelStart();
while (1)
{
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
{
Error_Handler();
}
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_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
{
Error_Handler();
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
}
static void LCD_Config(void)
{
uint32_tlcd_status = LCD_OK;
lcd_status = BSP_LCD_Init();
while(lcd_status != LCD_OK);
BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
BSP_LCD_SetFont(&Font12);
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 20, (uint8_t *)"Copyright (c) STMicroelectronics 2016", CENTER_MODE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 120);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_SetFont(&Font24);
BSP_LCD_DisplayStringAt(0, 20, (uint8_t *)"STM32F769I Discovery FreeRTOS Demo", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, 50, (uint8_t *)"This example shows how to run ", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, 80, (uint8_t *)"FREERTOS STM32F769I-DISCOVERY applications ", CENTER_MODE);
BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
BSP_LCD_DisplayStringAt(150, 200, (uint8_t *)"Task1",LEFT_MODE);
BSP_LCD_DisplayStringAt(350, 200, (uint8_t *)"Task2",LEFT_MODE);
BSP_LCD_DisplayStringAt(550, 200, (uint8_t *)"Task2",LEFT_MODE);
BSP_LCD_SetFont(&Font24);
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM7) {
HAL_IncTick();
}
}
修改freertos.c中的任务
<div>include "stm32f7xx_hal.h"
#include "gpio.h"</div><div>
</div><div>voidTask1(void const * argument)
{static uint8_t i=0;
for(;;)
{i++;
LD_USER1_Torggle();
if(i&0x01)
{
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
}
else
{
BSP_LCD_SetTextColor(LCD_COLOR_RED);
}
BSP_LCD_FillCircle(200,300,50);
osDelay(100);
}
}
voidTask2(void const * argument)
{static uint8_t j=0;
for(;;)
{j++;
LD_USER2_Torggle();
if(j&0x01)
{
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
}
else
{
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
}
BSP_LCD_FillCircle(400,300,50);
osDelay(200);
}
}
void Task3(void const * argument)
{static uint8_t k=0;
for(;;)
{k++;
LD_USER3_Torggle();
if(k&0x01)
{
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
}
else
{
BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
}
BSP_LCD_FillCircle(600,300,50);
osDelay(1000);
}
}
</div></div>
GPIO.h添加DEF
#define LD_USER1_Pin GPIO_PIN_13
#define LD_USER1_GPIO_Port GPIOJ
#define LD_USER2_Pin GPIO_PIN_5
#define LD_USER2_GPIO_Port GPIOJ
#define LD_USER3_Pin GPIO_PIN_12
#define LD_USER3_GPIO_Port GPIOA
#define LD_USER1_ON() HAL_GPIO_WritePin(LD_USER1_GPIO_Port,LD_USER1_Pin,GPIO_PIN_SET)
#define LD_USER1_OFF() HAL_GPIO_WritePin(LD_USER1_GPIO_Port,LD_USER1_Pin,GPIO_PIN_RESET)
#define LD_USER1_Torggle() HAL_GPIO_TogglePin(LD_USER1_GPIO_Port,LD_USER1_Pin)
#define LD_USER2_ON() HAL_GPIO_WritePin(LD_USER2_GPIO_Port,LD_USER2_Pin,GPIO_PIN_SET)
#define LD_USER2_ON() HAL_GPIO_WritePin(LD_USER2_GPIO_Port,LD_USER2_Pin,GPIO_PIN_SET)
#define LD_USER2_Torggle() HAL_GPIO_TogglePin(LD_USER2_GPIO_Port,LD_USER2_Pin)
#define LD_USER3_ON() HAL_GPIO_WritePin(LD_USER3_GPIO_Port,LD_USER3_Pin,GPIO_PIN_SET)
#define LD_USER3_ON() HAL_GPIO_WritePin(LD_USER3_GPIO_Port,LD_USER3_Pin,GPIO_PIN_SET)
#define LD_USER3_Torggle() HAL_GPIO_TogglePin(LD_USER3_GPIO_Port,LD_USER3_Pin)
http://player.youku.com/player.php/sid/XMTg2NDM4NTYwNA==/v.swf建一个FREERTOS工程在这里原来是这么简单!填充画圆是最慢的,在视频中可以看出,STM32F769I多任务处理多个填充画圆是很轻松的。
谢谢分享 jackten 发表于 2016-12-14 17:43
谢谢分享
:).......... 谢谢分享,写的真详细,不错的教程 leo121_3006061 发表于 2016-12-14 17:47
谢谢分享,写的真详细,不错的教程
:).......... 不错,点灯大法~~~ 谢谢分享
页:
[1]