当前位置:网站首页>[actual combat] STM32 FreeRTOS porting series Tutorial 4: FreeRTOS software timer
[actual combat] STM32 FreeRTOS porting series Tutorial 4: FreeRTOS software timer
2022-06-21 09:13:00 【Huaqing vision it open laboratory】
Write it at the front :
This article is 《STM32MP157 Developing a tutorial FreeRTOS Operating system 》 One in a series , The development platform used by the author is Huaqing vision FS-MP1A Development board (STM32MP157 Development board ).stm32mp157 yes ARM Dual core ,2 individual A7 nucleus ,1 individual M4 nucleus ,A7 You can run on the core Linux operating system ,M4 You can run on the core FreeRTOS、RT-Thread And other real-time operating systems ,STM32MP157 Development board, so you can learn Embedded linux, You can also learn. stm32 Single chip microcomputer .
in the light of FS-MP1A Development board , except FreeRTOS Outside the operating system , There are also many other series of tutorials , Include Cortex-A7 Development of article 、Cortex-M4 Development of article 、 Expansion board driver transplantation 、Linux Application development 、Linux System transplantation 、Linux Driving development 、 Hardware design 、 Artificial intelligence machine vision 、Qt Application programming 、Qt Comprehensive project practice, etc . Welcome to your attention , more stm32mp157 Develop tutorials and videos , Technical exchange can be added Q Group 459754978, Thank you for attention .
FS-MP1A Development board Details :https://item.taobao.com/item.htm?id=622457259672
2.FreeRTOS Software timer
2.1 Introduction to software timer
about MCU for , Its own timer belongs to hardware timer , stay FreeRTOS In the system , In addition, the software timer function is provided . The precision of software timer is not as good as that of hardware timer , But it's enough for less demanding periodic processing tasks .
The software timer can be set for a period of time , When the set time arrives, the callback function is executed , among , The interval between two executions of the callback function is the timer's timing period , That is, the callback function is executed every time the timing period arrives . Because the callback function is executed in the timer service function , Therefore, you must not call the callback function that will block the task API function .
The software timer is divided into two types: cycle timer and single timer . After the cycle timer is started, it will automatically restart after the callback function is executed , So the callback function can be executed periodically , For a single timer , The callback function is executed only once , After execution , The timer will stop , Of course, we can call the function to manually restart again .
2.2 Software timer function
2.2.1 Reset timer
When the timer is running normally , Sometimes we may need to reset the timer , When resetting the software timer , The system will recalculate the time point when the timing period arrives , But this time point is calculated relative to the reset time , It's not the time when the software timer is started for the first time .
In the new FreeRTOS in , There are two API Function to reset the software timer , Apply to tasks and interrupts respectively .
Task level reset software timer function xTimerReset(), This function is a macro , The function prototype is as follows
BaseType_t xTimerReset( TimerHandle_t xTimer,
TickType_t xTicksToWait)
Parameters :
xTimer: Handle of the software timer to be reset .
xTickToWait: Set blocking time .
Return value :
pdPASS: Software timer reset succeeded , That is, the command is successfully sent .
pdFAIL: Software timer reset failed , That is, command sending failed .
Task level reset software timer function xTimerReset(), This function is a macro , The function prototype is as follows
BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
BaseType_t * pxHigherPriorityTaskWoken );
Parameters :
xTimer: Handle of the software timer to be reset .
pxHigherPriorityTaskWoken: Remember whether to switch tasks after exiting this function , The user does not need to set .
Return value :
pdPASS: Software timer reset succeeded , That is, the command is successfully sent .
pdFAIL: Software timer reset failed , That is, command sending failed .
2.2.2 Create software timer
There are two functions for creating software timers , They are as follows :
xTimerCreate(), This function is used to create a software timer , The required memory is allocated through dynamic memory management , After creation, the software timer is in sleep state , The function prototype is as follows :
TimerHandle_t xTimerCreate( const char * const pcTimerName,
TickType_t xTimerPeriodInTicks,
UBaseType_t uxAutoReload,
void * pvTimerID,
TimerCallbackFunction_t pxCallbackFunction )
Parameters :
pcTimerName: Software timer name , It's a string , For debugging use .
xTimerPeriodInTicks: Timer cycle , The unit is the number of clock beats .
uxAutoReload: Set timer mode , Single timer or periodic timer .
pvTimerID: Timer ID Number .
pxCallbackFunction: Timer callback function .
Return value :
NULL: Software timer creation failed .
Other values : Create a successful software timer handle .
xTimerCreateStatic(), This function is also used to create software timers , The required memory is allocated by the user , After creation, the software timer is in sleep state , The function prototype is as follows :
TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
TickType_t xTimerPeriodInTicks,
UBaseType_t uxAutoReload,
void * pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
StaticTimer_t * pxTimerBuffer )
Parameters :
pcTimerName: Software timer name , It's a string , For debugging use .
xTimerPeriodInTicks: Timer cycle , The unit is the number of clock beats .
uxAutoReload: Set timer mode , Single timer or periodic timer .
pvTimerID: Timer ID Number .
pxCallbackFunction: Timer callback function .
pxTimerBuffer: Point to one StaticTimer_t Variable of type , Used to save timer structure .
Return value :
NULL: Software timer creation failed .
Other values : Create a successful software timer handle .
2.2.3 Turn on the software timer
There are also two functions to start the software timer , They are as follows :
Task level start timer function xTimerStart(), This function is a macro , If the software timer is not running, call the function xTimerStart() Will calculate the timer expiration time , If the software timer is running, call the function xTimerStart() The result and xTimerReset() equally , The function prototype is as follows :
BaseType_t xTimerStart( TimerHandle_t xTimer,
TickType_t xTicksToWait )
Parameters :
xTimer: The software timer handle to open .
xTickToWait: Set blocking time .
Return value :
pdPASS: The software timer is turned on successfully , That is, the command is successfully sent .
pdFAIL: Software timer failed to start , That is, command sending failed .
Interrupt level start timer function xTimerStartFromISR(), This function is also a macro , For the function xTimerStart() Broken version of , Can only be used in interrupt service functions , The function prototype is as follows :
BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
BaseType_t * pxHigherPriorityTaskWoken );
Parameters :
xTimer: The software timer handle to open .
pxHigherPriorityTaskWoken: Mark whether to switch tasks after exiting this function .
Return value :
pdPASS: The software timer is turned on successfully , That is, the command is successfully sent .
pdFAIL: Software timer failed to start , That is, command sending failed .
2.2.4 Stop the software timer
It is the same as turning on the software timer , There are also two functions to stop the software timer , They are as follows :
Task level stop timer function xTimerStop(), This function is a macro , The function prototype is as follows :
BaseType_t xTimerStop( TimerHandle_t xTimer,
TickType_t xTicksToWait )
Parameters :
xTimer: Software timer handle to stop .
xTickToWait: Set blocking time .
Return value :
pdPASS: Software timer stopped successfully , That is, the command is successfully sent .
pdFAIL: Software timer stop failed , That is, command sending failed .
Interrupt level stop timer function xTimerStopFromISR(), This function is also a macro , For the function xTimerStop() Broken version of , Can only be used in interrupt service functions , The function prototype is as follows :
BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
BaseType_t * pxHigherPriorityTaskWoken );
Parameters :
xTimer: Software timer handle to stop .
pxHigherPriorityTaskWoken: Mark whether to switch tasks after exiting this function .
Return value :
pdPASS: Software timer stopped successfully , That is, the command is successfully sent .
pdFAIL: Software timer stop failed , That is, command sending failed .
2.3 Operation experiment
2.3.1 Experimental design
This experiment creates two software timers , They are cycle timers CycleTimer_Handle And single timer SingleTimer_Handle, among ,CycleTimer_Handle The timer period of is 1000 Individual clock time ,SingleTimer_Handle The timer period of is 2000 Individual clock time .
May refer to 12.3.2 Chapter to import the existing project , Project storage path 【 Huaqing vision -FS-MP1A Development of information \02- Program source code \ARM Architecture and interface technology \FreeRTOS\4_MP1A-FreeRTOS-TIMER】
Set different commands through key interrupt , In the task, it controls the work of the cycle timer and the single timer according to the received instructions .
The tasks and their functions are as follows :
StartTask02(): control LED3 flashing , Indicates that the system is running .
StartDefaultTask(): Processing instructions , Control the timer to work according to the received instructions .
2.3.2 Experimental process and analysis
First , Configure... According to the previous chapters CubeMX, Configure... According to the previous section “FREERTOS”, Generate code when finished . stay StartDefaultTask() And StartTask02() Add the following code to .

When pressed KEY1 Key time , The single timer works , When the timer time is up, it will call OneShotCallback() function , You will find LED1 The level of is reversed , Then stop running . When pressed KEY2 Key time , The cycle timer works , When the timer time is up, it will call AutoReloadCallback() function , Because the cycle timer doesn't stop , You will find LED2 every other 1 The second level is reversed . When pressed KEY3 Key time , Single timer and cycle timer off ,LED The level of the lamp is no longer changed .
Hardware platform : Huaqing vision FS-MP1A Development board (STM32MP157)
Download some development tutorials : Add QQ Group 459754978, There are in the group file .
Watch some video courses : Personal space of Huaqing vision R & D Center _ Bili, Bili _Bilibili
边栏推荐
- 基于Retrotfit2.1+Material Design+ijkplayer开发的一个APP
- android 数据库升级
- The internal structure of MySQL and how an SQL statement is executed
- Base de données de sauvegarde DumpLiNg
- [Mgt] model Mgt for code interpretation
- Unity development related blog collection
- Six methods of optimizing inventory management in food production industry
- JUnit中的@Transactional消失不见,@Rollback是否能单抗测试回滚的大旗?
- Unity 5 自帶的Mono也可以支持C# 6
- Unity Detailed explanation of meta file function
猜你喜欢

\Processing method of ufeff

Wechat applet

TiDB3.0- 4.0 内存控制/修改日志保存天数/最大索引长度

【实战】STM32 FreeRTOS移植系列教程1:FreeRTOS 二值信号量使用

STL tutorial 3- type conversion static_ cast、dynamic_ cast、const_ cast、reinterpret_ Cast method

leetcode:19. 删除链表的倒数第 N 个结点

Ali has been working for 8 years. This learning note is left when he reaches P8. He has helped his friends get 10 offers

Alibaba cloud OSS uploading and intelligent image recognition garbage recognition

微信小程序

2. the development of the meta universe
随机推荐
It is said that this year gold three silver four has become gold one silver two.
【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器
Stm32mp1 cortex M4 development part 8: LED lamp control experiment of expansion board
如何监听DOM元素尺寸的变化?
Unity Detailed explanation of meta file function
C # implement callback
Dumping backup database
Understanding and use of advanced pointer
Token, cookie and session
Tidb3.0- 4.0 memory control / modification log saving days / maximum index length
stm32mp1 Cortex M4开发篇11:扩展板蜂鸣器控制
Six methods of optimizing inventory management in food production industry
The difference between tuples and lists
Verification code ----- SVG captcha
The most authoritative Lei niukesi in history --- embedded Ai Road line [yyds]
Dumpling備份數據庫
【MGT】代码解读之model-MGT
R language through rprofile Site file, custom configuration of R language development environment startup parameters, shutdown parameters, configuration of R startup output custom text and system time
TiDB3.0- 4.0 内存控制/修改日志保存天数/最大索引长度
Retrofit扩展阅读