报这个错怎么办(assert failed: prvInitialiseNewTask tasks.c:1061 (uxPriority < ( 25 )) Backtrace: 0x403759ca:0x3fc99a90 0x4037a9a1:0x3fc99ab0 0x40380e51:0x3fc99ad0 0x4037c373:0x3fc99bf0 0x4037db54:0x3fc99c20 0x420083fe:0x3fc99c60 0x4201e5a7:0x3fc99c90 0x4037b3c5:0x3fc99cc0)
开发ESP32串口通信时报错。错误程序如下:
#include <stdio.h>
#include <inttypes.h>
#include "hardware/led/bsp_led.h"
#include "hardware/key/bsp_key.h"
//导入FREERTOS的任务调度
#include "freertos/FreeRTOS.h" //vTaskDelay
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h" //导入ESP32的日志输出功能
#include "driver/gpio.h"//导入GPIO设备库
#include "hardware/uart/bsp_uart.h"
void app_main(void)
{
LedGpioConfig();
Led10On();
printf("www.lckfb.com");
//初始化串口1 TX=GPIO17 RX=GPIO18
uart_init_config(UART_NUM_1, 115200, 17, 18);
//创建串口1接收任务
xTaskCreate(uart1_rx_task, "uart1_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL);
//通过串口1发送字符串 start uart demo
uart_write_bytes(UART_NUM_1, (const char*)"start uart demo", strlen("start uart demo"));
while(1)
{
//串口1发送数据
uart_write_bytes(UART_NUM_1, (const char*)"Task running : main", strlen("Task running : main"));
//ESP32S3的日志输出数据
ESP_LOGI("main", "Task running : main\r\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
更改后程序如下:
#include <stdio.h>
#include <inttypes.h>
#include "hardware/led/bsp_led.h"
#include "hardware/key/bsp_key.h"
//导入FREERTOS的任务调度
#include "freertos/FreeRTOS.h" //vTaskDelay
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h" //导入ESP32的日志输出功能
#include "driver/gpio.h"//导入GPIO设备库
#include "hardware/uart/bsp_uart.h"
void app_main(void)
{
LedGpioConfig();
Led10On();
printf("www.lckfb.com");
//初始化串口1 TX=GPIO17 RX=GPIO18
uart_init_config(UART_NUM_1, 115200, 17, 18);
//创建串口1接收任务
xTaskCreate(uart1_rx_task, "uart1_rx_task", 2048, NULL, 10, NULL);
//通过串口1发送字符串 start uart demo
uart_write_bytes(UART_NUM_1, (const char*)"start uart demo", strlen("start uart demo"));
while(1)
{
//串口1发送数据
uart_write_bytes(UART_NUM_1, (const char*)"Task running : main", strlen("Task running : main"));
//ESP32S3的日志输出数据
ESP_LOGI("main", "Task running : main\r\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
或将
xTaskCreate(uart1_rx_task, "uart1_rx_task", 2048, NULL, configMAX_PRIORITIES, NULL);
更改为:
xTaskCreate(uart1_rx_task, "uart1_rx_task", 2048, NULL, configMAX_PRIORITIES-1, NULL);
这个错误信息表明在FreeRTOS(或者类似的实时操作系统)中,尝试初始化一个新任务时遇到了一个断言(assert
)失败。具体失败的原因是在tasks.c
文件的第1061行,其中检查了一个条件uxPriority < ( 25 )
。这个条件通常用于确保任务的优先级没有超出系统所允许的范围。
在FreeRTOS中,任务优先级是一个整数,通常是从0(最高优先级)到某个最大值(例如,在配置为32个优先级的系统中,这个值就是31)。如果你的系统配置了一个较小的优先级范围,而尝试创建一个优先级过高的任务,就会触发这个断言。
根据给出的回溯(Backtrace),可以看到一系列的函数调用,但它们的具体含义取决于系统配置和FreeRTOS的版本。不过,通常这些调用会指向任务创建或初始化的相关函数。
为了解决这个问题,可以:
- 检查任务优先级:确保尝试创建的任务的优先级没有超出系统所允许的范围。
- 检查FreeRTOS配置:查看你的FreeRTOS配置文件(通常是
FreeRTOSConfig.h
),确认是否设置了正确的优先级数量。 - 检查代码:检查的代码中任务创建的部分,确保没有错误地设置了任务的优先级。
- 使用调试器:如果有一个调试器连接到你的系统,你可以使用它来单步执行代码,并查看在断言失败时各个变量的值。
- 查看文档:查阅FreeRTOS的官方文档,了解关于任务优先级和断言失败的更多信息。
希望这些信息能帮助你解决问题!