提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
昨天我将freeRTOS移植到了stm32F103ZET6,今天我打算将FreeRTOS移植到STM32F427VIT6上面。在和我的lvgl联动。相比于lvgl,FreeRTOS移植还是很简单的
一、移植FreeRTOS
老步骤在我上一节就说了,现在移植到F427上面只需要改点程序
首先第一步是替换include文件里面的FreeRTOSConfig.h文件。新的FreeRTOSConfig.h文件在demo里面找如下面第二张图
然后就是第二步修改FreeRTOSConfig.h文件
改成
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif
然后改一下FreeRTOSConfig.h下面的宏定义和注释掉第126行的代码,ok这样FreeRTOSConfig.h就配置完成了
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
//#define xPortSysTickHandler SysTick_Handler
然后我使用了静态的栈所以还要打开FrRTOSconfig.h文件将下面标志开启
然后在main.c或者自己另外写一个文件写两个源文件,我是在main.c里面添加的
StackType_t xIdle3Static[1500];
StaticTask_t xIdleTCB;
StackType_t xITimeStatic[1500];
StaticTask_t xITimeTCB;
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,StackType_t ** ppxIdleTaskStackBuffer,uint32_t * pulIdleTaskStackSize ){
*ppxIdleTaskTCBBuffer=&xIdleTCB;
*ppxIdleTaskStackBuffer=xIdle3Static;
*pulIdleTaskStackSize=1500;
}
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize ){
* ppxTimerTaskTCBBuffer=&xITimeTCB;
* ppxTimerTaskStackBuffer=xITimeStatic;
* pulTimerTaskStackSize =1500;
}
然后在修改usart.c文件,因为我串口一是用的正点原子的hal库,这里需要修改第六行的代码
#if SYSTEM_SUPPORT_OS
#include "FreeRTOS.h" //os ʹԃ
#endif
最后在stm32f4xx_it.h文件添加下面代码
#include "FreeRTOS.h"
#include "task.h"
void SysTick_Handler(void)
{
#if (INCLUDE_xTaskGetSchedulerState == 1 )
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
{
#endif
xPortSysTickHandler();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
}
#endif
}
这就完成了
二、成果展示
1.图片展示
这是我学习lvgl后自己做的第一个实战项目,主要涉及到->lvgl+freeRTOS+TCP连接+ILI9488显示驱动
2.部分代码展示
main.h文件因为是今天才写完还没抽时间把有些代码封装成库,main.c有点乱,等有时间我在把他封装成库
代码如下(示例):
#include "main.h"
#include "gpio.h"
#include "USART.h"
#include "Delay.h"
#include "i2c.h"
#include "AHT10_S.h"
#include "lcd.h"
#include "stdio.h"
#include "touch.h"
#include "tim.h"
#include "lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
#include "ADC.h"
#include "WIFI.h"
#include "usart2.h"
#include "cJSON.h"
#include "lvgl_text.h"
#include "jonsson.h"
#include "time10.h"
#include "FreeRTOS.h"
#include "task.h"
void GET_Time();
void GET_DATA();
int64_t st_time;
int64_t end_time;
int64_t st_data;
int64_t end_data;
char HUMI[64];
char TEMP[64];
uint8_t cp_time_buff[1024];
char* time_p;
char* weed_p;
cJSON* TIME;
cJSON* result;
cJSON* DAT;
char* one_p;
char* tow_p;
char* three_p;
int16_t temp1;
int16_t humi1;
StackType_t xTask3Static[1500];
StaticTask_t xTaskTCB;
StackType_t xIdle3Static[1500];
StaticTask_t xIdleTCB;
StackType_t xITimeStatic[1500];
StaticTask_t xITimeTCB;
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,StackType_t ** ppxIdleTaskStackBuffer,uint32_t * pulIdleTaskStackSize ){
*ppxIdleTaskTCBBuffer=&xIdleTCB;
*ppxIdleTaskStackBuffer=xIdle3Static;
*pulIdleTaskStackSize=1500;
}
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize ){
* ppxTimerTaskTCBBuffer=&xITimeTCB;
* ppxTimerTaskStackBuffer=xITimeStatic;
* pulTimerTaskStackSize =1500;
}
void Task1Funtion(void* param){
for(;;){
}
}
void Task2Funtion(void* param){
AT_GET_Weather_dat();
JSON_CP_Dat(Rxbuff);
printf("--------------------------------------------------------\r\n");
AT_GET_API_TIME();
for(;;)
{
vTaskDelay(20000);
GET_DATA();
GET_Time();
//GET_Time();
//vTaskDelay(1);
}
}
void Task3Funtion(void* param){
LCD_Init();
tp_dev.init();
lv_init();
lv_port_disp_init();
lv_port_indev_init();
lvgl_dome();
//解析时间
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(data);
lv_label_set_text(label_days,one_dat);
one_p=one_dat+6;
tow_p=tow_dat+6;
three_p=three_dat+6;
lv_label_set_text(Time_one,one_p);
lv_label_set_text(Time_tow,tow_p);
lv_label_set_text(Time_three,three_p);
//解析温度
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(high);
sprintf(TEMP,"%sC",one_dat);
int temp_dat=atoi(one_dat);
lv_label_set_text(temp_label,TEMP);
//解析湿度
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(humidity);
sprintf(HUMI,"%s%%",one_dat);
int humi_dat=atoi(one_dat);
lv_label_set_text(humi_label,HUMI);
lvgl_Indoor_humi_temp_display(temp_dat,humi_dat);
chart_display_now(temp_dat,humi_dat);
//解析天气
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(code_day);
int weather=atoi(one_dat);
int weather_tow=atoi(tow_dat);
int weather_three=atoi(three_dat);
lvgl_Right_display_weather(weather);
lvgl_weather_one_display(weather);
lvgl_weather_tow_display(weather_tow);
lvgl_weather_three_display(weather_three);
//解析时间
TIME=cJSON_Parse((char*)Rxbuff);
result=cJSON_GetObjectItem(TIME,"result");
//cJSON* Date=cJSON_GetArrayItem(result,0);
DAT=cJSON_GetObjectItem(result,"datetime_1");
time_p=DAT->valuestring+11;
printf("\r\nTIME=%s\r\n",time_p);
lv_label_set_text(label_time,time_p);
cJSON_Delete(TIME);
//解析星期
TIME=cJSON_Parse((char*)Rxbuff);
result=cJSON_GetObjectItem(TIME,"result");
DAT=cJSON_GetObjectItem(result,"week_1");
weed_p=DAT->valuestring;
printf("WEED=%s\r\n",weed_p);
int weed=atoi(weed_p);
lvgl_Right_display_weed(weed);
lvgl_Weed_display(weed);
cJSON_Delete(TIME);
uint32_t i;
while(1){
tp_dev.scan(0);
lv_task_handler();
}
}
int main(void)
{
TaskHandle_t xTask;
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
Delay_init(180);
ADC_Config();
uart_init(115200);
printf("begin...\r\n");
USART_config();
MX_TIM8_Init();
xTaskCreate(Task1Funtion,"Task1",1500,NULL,1,&xTask);
xTaskCreate(Task2Funtion,"Task2",1500,NULL,1,NULL);
xTaskCreateStatic(Task3Funtion,"Task3",1500,NULL,1,xTask3Static,&xTaskTCB);
vTaskStartScheduler();
while (1)
{
// GET_DATA(20000);
// GET_Time(600000);
//atoi();//字符串转整形
// tp_dev.scan(0);
// lv_task_handler();
}
}
//**********************刷新时间
void GET_DATA(){
AT_WIFIMODE(STA);
printf("\n");
AT_CONNECT_WIFI(ssid,pass);
printf("\n");
AT_Connect_TCP(TCP_IP_TIME);
printf("\n");
AT_SET_TCPMODE(PT);
printf("\n");
AT_SEND_TCP();
AT_SEND_MES(TCP_GET_TIMES);
AT_BAKE_SEND();
//解析时间
cJSON* TIME=cJSON_Parse((char*)Rxbuff);
cJSON* result=cJSON_GetObjectItem(TIME,"result");
//cJSON* Date=cJSON_GetArrayItem(result,0);
cJSON* DAT=cJSON_GetObjectItem(result,"datetime_1");
time_p=DAT->valuestring+11;
printf("\r\nTIME=%s\r\n",time_p);
cJSON_Delete(TIME);
lv_label_set_text(label_time,time_p);
//解析星期
TIME=cJSON_Parse((char*)Rxbuff);
result=cJSON_GetObjectItem(TIME,"result");
DAT=cJSON_GetObjectItem(result,"week_1");
weed_p=DAT->valuestring;
printf("\r\nWEED=%s\r\n",weed_p);
int weed=atoi(weed_p);
lvgl_Right_display_weed(weed);
lvgl_Weed_display(weed);
cJSON_Delete(TIME);
}
//************************************刷新温湿度和日期
void GET_Time(){
AT_GET_Weather_dat();
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(data);
lv_label_set_text(label_days,one_dat);
one_p=one_dat+6;
tow_p=tow_dat+6;
three_p=three_dat+6;
lv_label_set_text(Time_one,one_p);
lv_label_set_text(Time_tow,tow_p);
lv_label_set_text(Time_three,three_p);
//解析温度
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(high);
sprintf(TEMP,"%sC",one_dat);
int temp_dat=atoi(one_dat);
lv_label_set_text(temp_label,TEMP);
//解析湿度
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(humidity);
sprintf(HUMI,"%s%%",one_dat);
int humi_dat=atoi(one_dat);
lv_label_set_text(humi_label,HUMI);
lvgl_Indoor_humi_temp_display(temp_dat,humi_dat);
chart_display_now(temp_dat,humi_dat);
//解析天气
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(code_day);
int weather=atoi(one_dat);
int weather_tow=atoi(tow_dat);
int weather_three=atoi(three_dat);
lvgl_Right_display_weather(weather);
lvgl_weather_one_display(weather);
lvgl_weather_tow_display(weather_tow);
lvgl_weather_three_display(weather_three);
}
总结
lvgl+freeRTOS的项目历经我几天时间终于完成一半,有个雏形了。还是可以。后面慢慢优化
不经一番寒彻骨,怎得梅花扑鼻香。