独处东汉 2023-04-08 15:01 采纳率: 0%
浏览 159
已结题

关于#学习freertos使用时发生中断卡死#的问题,如何解决?

学习消息队列,调用freertos中断API函数时,出现了问题,调试追踪发现卡死在portASSERT_IF_INTERRUPT_PRIORITY_INVALID();这个宏,该如何解决呢。

其中主要是两个中断,配置如下:

HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

HAL_NVIC_SetPriority(EXTI4_IRQn, 7, 0);    // 对应是 CLK_CHECK_Pin 中断
HAL_NVIC_EnableIRQ(EXTI4_IRQn);

HAL_NVIC_SetPriority(EXTI9_5_IRQn, 10, 0); // 对应是 B2A_Pin 中断
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

其中CLK_CHECK_Pin 中断发生时都能正常响应,就是当B2A_Pin 中断来临时出现卡死portASSERT_IF_INTERRUPT_PRIORITY_INVALID();这里,我的系统中实时性高,没法用printf来进行调试,只有通过逻辑分析仪和翻转LED来进行调试,已经尝试更改了B2A_Pin了的优先级设置为


HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0); // 对应是 B2A_Pin 中断
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

还是死机,暂时不晓得咋处理,现在唯一的解决方式在B2A_Pin 中断发生时不使用freertos相关API。来平台主要是想问一下有没有人碰到过类似的事情,如何解决的,同时是方便自己对freertos的理解

相关的业务的代码如下:

#include "business_task.h"
#include "main.h"
#include <stdbool.h>


osThreadId businessTaskHandle;

osMessageQId businessQueueHandle;

// 业务任务的入口函数
void StartBusinessTask(void const * argument)
{
    uint32_t data = 0;
    // 在这里编写任务的代码
    while (1) {
        // 从消息队列中获取数据
        osEvent event = osMessageGet(businessQueueHandle, osWaitForever);
        data = event.value.v;
        // 处理数据并进行相应的操作
        if (data == CLK_CHECK_Pin) {
            do_something();  // 这里需要很长时间来进行处理
        }
        else if(data == B2A_Pin) {
            HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin);
        }
    }
}

// void SetBusinessQueueHandle(osMessageQId queue_id)
// {
//     // 将消息队列句柄保存到全局变量中
//     businessQueueHandle = queue_id;
// }


// 初始化业务任务
void InitBusinessTask(void)
{
    osThreadDef(businessTask, StartBusinessTask, osPriorityRealtime, 0, 128);
    businessTaskHandle = osThreadCreate(osThread(businessTask), NULL);


    osMessageQDef(businessQueue, 16, uint32_t); // 将队列的最大容量设置为 16
    businessQueueHandle = osMessageCreate(osMessageQ(businessQueue), NULL);

    
    // 将业务任务的消息队列句柄传递给中断处理函数
    // SetBusinessQueueHandle(businessQueueHandle);
}



// 向业务任务发送数据
bool SendDataToBusinessTask(uint32_t data)
{
    if (osMessagePut(businessQueueHandle, data, 0) != osOK) {
        return false;
    }
    return true;

}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
    if (GPIO_Pin == CLK_CHECK_Pin) {
        SendDataToBusinessTask(CLK_CHECK_Pin);
    }
    else if (GPIO_Pin == B2A_Pin) {
        // HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin);
        SendDataToBusinessTask(B2A_Pin);
    }
}


FreeRTOSConfig.h的内容如下:


/* USER CODE BEGIN Header */
/*
 * FreeRTOS Kernel V10.0.1
 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */
/* USER CODE END Header */

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * These parameters and more are described within the 'configuration' section of the
 * FreeRTOS API documentation available on the FreeRTOS.org web site.
 *
 * See http://www.freertos.org/a00110.html
 *----------------------------------------------------------*/

/* USER CODE BEGIN Includes */
/* Section where include file can be added */
/* USER CODE END Includes */

/* Ensure definitions are only used by the compiler, and not by the assembler. */
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
  #include <stdint.h>
  extern uint32_t SystemCoreClock;
#endif
#define configUSE_PREEMPTION                     1
#define configSUPPORT_STATIC_ALLOCATION          1
#define configSUPPORT_DYNAMIC_ALLOCATION         1
#define configUSE_IDLE_HOOK                      0
#define configUSE_TICK_HOOK                      0
#define configCPU_CLOCK_HZ                       ( SystemCoreClock )
#define configTICK_RATE_HZ                       ((TickType_t)1000)
#define configMAX_PRIORITIES                     ( 7 )
#define configMINIMAL_STACK_SIZE                 ((uint16_t)128)
#define configTOTAL_HEAP_SIZE                    ((size_t)6144)
#define configMAX_TASK_NAME_LEN                  ( 16 )
#define configUSE_16_BIT_TICKS                   0
#define configUSE_MUTEXES                        1
#define configQUEUE_REGISTRY_SIZE                8
#define configUSE_PORT_OPTIMISED_TASK_SELECTION  1


/* Co-routine definitions. */
#define configUSE_CO_ROUTINES                    0
#define configMAX_CO_ROUTINE_PRIORITIES          ( 2 )

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet            1
#define INCLUDE_uxTaskPriorityGet           1
#define INCLUDE_vTaskDelete                 1
#define INCLUDE_vTaskCleanUpResources       0
#define INCLUDE_vTaskSuspend                1
#define INCLUDE_vTaskDelayUntil             0
#define INCLUDE_vTaskDelay                  1
#define INCLUDE_xTaskGetSchedulerState      1

/* 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) )

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#include "main.h"
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; )HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin);}
/* USER CODE END 1 */

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler    SVC_Handler
#define xPortPendSVHandler PendSV_Handler

/* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
              to prevent overwriting SysTick_Handler defined within STM32Cube HAL */

#define xPortSysTickHandler SysTick_Handler

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
/* USER CODE END Defines */

#endif /* FREERTOS_CONFIG_H */

  • 写回答

4条回答 默认 最新

  • 阿里嘎多学长 2023-04-08 21:03
    关注

    以下内容部分参考ChatGPT模型:


    这个问题可能是由于中断优先级设置不当导致的。您可以尝试将B2A_Pin中断的优先级设置为更高的值,例如6或7。同时,确保您在FreeRTOSConfig.h中正确地设置了configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY和configKERNEL_INTERRUPT_PRIORITY宏。如果这些操作没有解决问题,您可以尝试在HAL_GPIO_EXTI_Callback函数中使用vTaskNotifyGiveFromISR函数代替SendDataToBusinessTask函数,这可能会更好地与FreeRTOS API协同工作。


    如果我的建议对您有帮助、请点击采纳、祝您生活愉快

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月12日
  • 创建了问题 4月8日

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址