延时
配置及中断优先级
FreeRTOS中断优先级配置
stm32cubemx 配置freertos中断优先级
FreeRTOS优先级详解
在ARM Cortex-M内核上运行RTOS
STM32中断,及FreeRTOS中断优先级配置
c – FreeRTOS:osDelay vs HAL_delay
cubemx在使用freertos的时候为何推荐使用除systick以外的timebase
FreeRtos 任务优先级和中断优先级
功能使用
注意事项
在启动FreeRTOS之前,开启了独立看门狗IWDG,3秒报警,但是在FreeRTOS任务中没有喂狗,导致运行3秒后,程序进入HardFault
//MX_IWDG_Init();
FREERTOS_Init();
FREERTOS_Start();
1、HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
2、FreeRTOS强制使用SysTick作为时基,并且将其中断优先级设置为最低。STM32 的HAL库的时基须选择其他定时器
3、建议HAL库的时基使用TIM,便于移植操作系统,也便于从IAP跳转到APP控制(如果使用SysTick,在跳转到APP前,需要关闭SysTick中断 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;//关闭SysTick中断)
void vTaskStartScheduler( void )-->BaseType_t xPortStartScheduler( void )
/* Make PendSV and SysTick the lowest priority interrupts. */
portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI;
portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI;
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4
#endif
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
//在系统中的其他文件中不能在定义 SVC_Handler PendSV_Handler SysTick_Handler
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
/* IMPORTANT: This define is commented when used with STM32Cube firmware, when timebase is systick,
to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
#define xPortSysTickHandler SysTick_Handler
FreeRTOS下载地址:
https://download.csdn.net/download/lyrain2009/12847593
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
/* *** NOTE ***********************************************************
If you find your application is crashing here then likely causes are
listed below. In addition see https://www.freertos.org/FAQHelp.html for
more tips, and ensure configASSERT() is defined!
https://www.freertos.org/a00110.html#configASSERT
1) Stack overflow -
see https://www.freertos.org/Stacks-and-stack-overflow-checking.html
2) Incorrect interrupt priority assignment, especially on Cortex-M
parts where numerically high priority values denote low actual
interrupt priorities, which can seem counter intuitive. See
https://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
of configMAX_SYSCALL_INTERRUPT_PRIORITY on
https://www.freertos.org/a00110.html
3) Calling an API function from within a critical section or when
the scheduler is suspended, or calling an API function that does
not end in "FromISR" from an interrupt.
4) Using a queue or semaphore before it has been initialised or
before the scheduler has been started (are interrupts firing
before vTaskStartScheduler() has been called?).
RTOS编程思想
- 任务优先级分配
1.1. 实时性要求高的,采用中断或者最高优先级,其对应的数据处理任务通过一直等待获取信号量完成信息处理
1.2. 按键和显示任务采用较低优先级,采用任务延时循环运行 - 任务之间的交互
2.1. 对于同一资源或外设的使用,可通过两种方式处理
一种是创建一个专用任务用于处理,其他任务要使用资源或者外设,通过发送信号量或者消息邮箱
一种是对资源或外设采用互斥信号量,保证同一时刻只有一个任务占用
Freertos printf可重入的问题
https://www.eemaker.com/freertos-printf.html
vQueueAddToRegistry
任务堆栈
信号量
互斥信号量
freeRTOS 信号量:二值 计数 互斥 递归互斥
互斥信号量只能在同一个任务中获取和释放,不能在一个任务中获取,在另一个任务中释放。
vTaskDelete 使用
vTaskDelete(NULL)使用注意事项
void vTaskDelete( TaskHandle_t xTaskToDelete )
当xTaskToDelete为 NULL时,表示删除的是当前任务,且vTaskDelete后的代码不再执行
- 任务自己删除自己
....
xTaskToDelete =NULL;
vTaskDelete( xTaskToDelete );
/* 代码运行截至,后面的代码不会执行 */
...balabala
- 在任务A中删除任务B
....
/* 判断任务B的任务指针是否为NULL,防止删除自己 */
if(taskB_handle)
{
vTaskDelete( taskB_handle);
taskB_handle=NULL;
}
/* 后面的代码会继续执行 */
...balabala
看门狗
基于STM32、FreeRTOS实现硬件看门狗+软件看门狗监测多任务的思路
FreeRTOS系统-独立看门狗监测任务执行状态