简介
感谢社区的GUIdemo 活动的开发板,本次申请的板卡为STM32H745I-DISCO 开发板,本次活动计划首先搭建基础开发工程(添加Uart 输出log用于调试,使用freertos),移植适配LVGL,基于LVGL创建仪表显示功能,我们先开始第一步的开发,搭建基础工程。
UART 的配置
开发板上将UART3 连接至了STLINK的虚拟串口,我们可以使用此串口来打印调试信息,对应原理图如下。

根据上述原理图,使用CubeMx 创建工程配置,PB10,PB11为串口功能,对应配置如下。

UART 参数配置为115200 8N1,并开启中断。


参数配置OK 代码中添加 printf 重定向到uart3 的处理,在IAR 中对应的底层IO函数为__write 函数,简单的对接即可实现printf 函数打印输出至uart3的功能。
/* USER CODE BEGIN 0 */
#if defined(__ICCARM__)
size_t __write(int file, unsigned char const *ptr, size_t len)
{
size_t idx;
unsigned char const *pdata = ptr;
for (idx = 0; idx < len; idx++)
{
HAL_UART_Transmit(&huart3, (uint8_t *)pdata, 1, 0xFFFF);
pdata++;
}
return len;
}
#endif /* __ICCARM__ */
适配FreeRtos
STM32 的SDK 中默认把systick 用作HAL库的延时时间基础的timer,FreeRtos 中通常使用systick 来作为系统调度的定时器,这块需要修改下CubeMx 配置,配置TIM6作为HAL库使用的定时器。
CubeMx 使能TIM6

CubeMx SYS timer 选择TIM6

开启FreeRTOS 组件

适配完成后,在生成的默认任务中添加之前适配好的uart printf 打印功能。
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
osDelay(1000);
printf("task1 \r\n");
}
/* USER CODE END 5 */
}
int main(void)
{
/* Init scheduler */
osKernelInitialize();
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
shellTaskHandle = osThreadNew(littleshell_main_entry, NULL, &shellTask_attributes);
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */
/* USER CODE END RTOS_EVENTS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
运行后,在任务内已经可以按照预期的输出打印了,至此GUI demo 的基础工程搭建基本完成,下一步开始LTDC 驱动适配来点亮 开发板的屏幕,为GUI Demo 应用LVGL 做好底层服务。
