简体   繁体   English

(STM32L476RG)标志设置(osThreadFlagsSet)在中断(GPIO EXTI)中执行时使微控制器崩溃

[英](STM32L476RG) Flag setting (osThreadFlagsSet) crashes microcontroller when executed in an Interrupt (GPIO EXTI)

I am currently learning CMSIS-RTOS v2 and I have an issue that is bugging me and I can't find the answer I need.我目前正在学习 CMSIS-RTOS v2,但我遇到了一个困扰我的问题,我找不到我需要的答案。

I am using the STM32L476-Disco board and the joystick center button as an interrupt.我使用 STM32L476-Disco 板和操纵杆中心按钮作为中断。 I have a very simple Interrupt callback for my center joystick interrupt:我的中心操纵杆中断有一个非常简单的中断回调:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
    //osEventFlagsSet(evt_id,0x0001);
    HAL_GPIO_TogglePin(LD5_GPIO_Port,LD5_Pin);
    osThreadFlagsSet(ThId_Led_Blink,0x0001);
}

When I call osThreadFlagsSet, the microcontroller freezes and nothing else happen.当我调用 osThreadFlagsSet 时,微控制器冻结,没有其他任何事情发生。 This is why I've put the HAL_GPIO_TogglePin: to see if the mcu was still responding or not.这就是我放置 HAL_GPIO_TogglePin: 以查看 mcu 是否仍在响应的原因。

I know that my interrupt resets correctly because when I only put my pin toggle, I can toggle the Led correctly.我知道我的中断正确重置,因为当我只拨动引脚时,我可以正确切换 LED。

ThId_Led_Blink is a ThreadId ThId_Led_Blink 是一个 ThreadId

osThreadId ThId_Led_Blink;

I've checked that the ID is set correctly in my debugger and it is (it's not null).我已经检查了我的调试器中的 ID 设置是否正确并且它是(它不为空)。

As you can see, I've tried with osEvenFlagsSet and I have the same result.如您所见,我已经尝试过使用 osEvenFlagsSet 并且得到了相同的结果。

When I check the CMSIS_RTOS v2 documentation, it does specify that osThreadFlagsSet can be called from an ISR, but I am not sure if I need to do something else in that case for the Flags to be set correctly and resolve the issue when the ISR is hanging.当我检查 CMSIS_RTOS v2 文档时,它确实指定可以从 ISR 调用 osThreadFlagsSet,但我不确定在这种情况下我是否需要做其他事情才能正确设置标志并解决 ISR 时的问题绞刑。

Thanks for your help谢谢你的帮助

So after frustrating hours of searching, I finally fixed my issue.因此,经过数小时的令人沮丧的搜索后,我终于解决了我的问题。

As described in this website: https://www.freertos.org/RTOS-Cortex-M3-M4.html , for STM32 microprocessor, you need to set the NVIC Group Priority to 4. If you look on freeRTOS, they are talking about putting this line in your code:如本网站所述: https://www.freertos.org/RTOS-Cortex-M3-M4.html ,对于 STM32 微处理器,您需要将 NVIC Group Priority 设置为 4。如果您查看 freeRTOS,他们正在说话关于将这一行放入您的代码中:

NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

However, the STM32 has it's own library for the NVIC and the correct function to set the priority group is:但是,STM32 有自己的 NVIC 库,正确的 function 设置优先级组是:

HAL_NVIC_SetPriorityGrouping(4);

Why go with the same name when you can change everything?当您可以更改所有内容时,为什么 go 具有相同的名称?

So make sure to call this function before your kernel initialization if you are using nested interrupts with FreeRTOS/CMSIS RTOS.因此,如果您在 FreeRTOS/CMSIS RTOS 中使用嵌套中断,请确保在 kernel 初始化之前调用此 function。

Also, make sure that your nested interrupt priority is in the range of configured interrupt priority for your FreeRTOS, otherwise, the osThreadFlagsSet function will fail automatically.此外,请确保您的嵌套中断优先级在 FreeRTOS 配置的中断优先级范围内,否则 osThreadFlagsSet function 将自动失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM