初级会员

- 积分
- 196
- 金钱
- 196
- 注册时间
- 2014-10-5
- 在线时间
- 39 小时
|
本帖最后由 stm32新人一枚 于 2020-12-19 17:04 编辑
这个帖子主要用来记录自己在RT-Thread上移植TouchGFX的一些坑。
RT-Thread和TouchGFX,以及相关的模块,都是在STM32CubeMx上配置的。
配置好之后,只需要对TouchGFX的“OSWrappers.cpp”文件进行修改,就可以正常使用了。
CSDN网站中有大神做过移植,详情在这里https://blog.csdn.net/sinat_31039061/article/details/105045469,
CSDN中这个帖子后来需要付费订阅了,但是百度还是能搜到另外一个网站可以看这个帖子:https://www.freesion.com/article/9090379134/
里边记录了OSWrappers.cpp的修改详细方法。
我自己按照帖子的方法移植之后,也能运行,只是有些小细节有问题。
后边贴的图片,是实拍图,红框里的字符会显示不全。而且经过排查,不是单片机运行速度或者RAM读写速度问题。
之后我又用STM32CubeMx重新配了一个FreeRTOS的工程,显示同样的内容,FreeRTOS的工程就很完美。
然后对比两个工程的OSWrappers.cpp,发现了端倪。
主要问题在于void OSWrappers::takeFrameBufferSemaphore()和void OSWrappers::giveFrameBufferSemaphore()中的信号量处理有问题。
这里贴出我修改后的代码(代码中重点修改的内容简单做了标注。其他部分的代码,也有根据FreeRTOS工程略做调整的部分,这里不再着重标注)
修改之后就可以完美运行了!
- /**
- ******************************************************************************
- * File Name : OSWrappers.cpp
- ******************************************************************************
- * @attention
- *
- * <h2><center>© Copyright (c) 2020 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
- /* USER CODE BEGIN target/OSWrappers.cpp */
- #include <cassert>
- #include <touchgfx/hal/HAL.hpp>
- #include <touchgfx/hal/OSWrappers.hpp>
- #include <rtthread.h>
- using namespace touchgfx;
- static rt_sem_t frame_buffer_sem;
- static rt_sem_t vsync_sem;
- /*
- * Initialize frame buffer semaphore and queue/mutex for VSYNC signal.
- */
- void OSWrappers::initialize()
- {
- frame_buffer_sem = rt_sem_create("gfx_sem", 1, RT_IPC_FLAG_PRIO);
- vsync_sem = rt_sem_create("vsync_sem", 1, RT_IPC_FLAG_PRIO);
- }
- /*
- * Take the frame buffer semaphore. Blocks until semaphore is available.
- */
- /////////////////////////////////重点修改的内容/////////////////////////////////
- void OSWrappers::takeFrameBufferSemaphore()
- {
- rt_sem_take(frame_buffer_sem,RT_WAITING_FOREVER);
- }
- /*
- * Release the frame buffer semaphore.
- */
- /////////////////////////////////重点修改的内容/////////////////////////////////
- void OSWrappers::giveFrameBufferSemaphore()
- {
- rt_sem_release(frame_buffer_sem);
- }
- /*
- * Attempt to obtain the frame buffer semaphore. If semaphore is not available, do
- * nothing.
- *
- * Note must return immediately! This function does not care who has the taken the semaphore,
- * it only serves to make sure that the semaphore is taken by someone.
- */
- void OSWrappers::tryTakeFrameBufferSemaphore()
- {
- rt_sem_trytake(frame_buffer_sem);
- }
- /*
- * Release the frame buffer semaphore in a way that is safe in interrupt context. Called
- * from ISR.
- *
- * Release the frame buffer semaphore in a way that is safe in interrupt context.
- * Called from ISR.
- */
- void OSWrappers::giveFrameBufferSemaphoreFromISR()
- {
- rt_sem_release(frame_buffer_sem);
- }
- /*
- * Signal that a VSYNC has occurred. Should make the vsync queue/mutex available.
- *
- * Note This function is called from an ISR, and should (depending on OS) trigger a
- * scheduling.
- */
- void OSWrappers::signalVSync()
- {
- rt_sem_release(vsync_sem);
- }
- /*
- * This function blocks until a VSYNC occurs.
- *
- * Note This function must first clear the mutex/queue and then wait for the next one to
- * occur.
- */
- void OSWrappers::waitForVSync()
- {
- rt_sem_take(vsync_sem,0);
- rt_sem_take(vsync_sem,RT_WAITING_FOREVER);
- }
- /*
- * A function that causes executing task to sleep for a number of milliseconds.
- *
- * A function that causes executing task to sleep for a number of milliseconds.
- * This function is OPTIONAL. It is only used by the TouchGFX in the case of
- * a specific frame refresh strategy (REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL).
- * Due to backwards compatibility, in order for this function to be useable by the HAL
- * the function must be explicitly registered:
- * hal.registerTaskDelayFunction(&OSWrappers::taskDelay)
- *
- * see HAL::setFrameRefreshStrategy(FrameRefreshStrategy s)
- * see HAL::registerTaskDelayFunction(void (*delayF)(uint16_t))
- */
- void OSWrappers::taskDelay(uint16_t ms)
- {
- rt_thread_mdelay(ms);
- }
- /* USER CODE END target/OSWrappers.cpp */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码
|
-
异常实拍图
|