STM32 HAL tick hangs after FreeRTOS mutex creation.

huangapple go评论46阅读模式
英文:

STM32 HAL tick hangs after FreeRTOS mutex creation

问题

在创建FreeRTOS互斥量后,HAL Tick定时器不再增加。我使用STM32CubeIDE 1.11.2作为IDE和CubeMX 6.7.0作为代码生成器,测试平台为Nucleo-F767ZI。

复现步骤:

  • 在STM32CubeIDE中创建新的STM32项目,所有设置默认
  • 在MX视角中打开ioc文件,使用CMSIS_V2接口添加FreeRTOS支持
  • 在main.c中,在osKernelInitialize()之后添加
    osMutexId_t mutex = osMutexNew(0);
    HAL_Delay(100);

结果:这段代码应该卡在HAL_Delay()中。
SysTick_Handler再也不会被调用,HAL_GetTick()始终返回相同的值(在我的情况下是10)。

我尝试过使用CMSIS和FreeRTOS互斥体函数,结果都一样。我尝试更改SysTick的时间基准,一样。我尝试使用另一个Nucleo板,也一样。

我错过了什么?

英文:

After creation of a FreeRTOS mutex, the HAL Tick timer is not increasing anymore. I use STM32CubeIDE 1.11.2 as IDE and CubeMX 6.7.0 as code generator, test platform Nucleo-F767ZI.

Reproductibility :

  • New STM32 Project in STM32CubeIDE, everything by default
  • Open the ioc file in MX perspective, add FreeRTOS support with CMSIS_V2 interface
  • In main.c, after osKernelInitialize(), add
    osMutexId_t mutex = osMutexNew(0);
    HAL_Delay(100);

Result : this code should stay stuck in HAL_Delay().
SysTick_Handler is never called anymore, HAL_GetTick() always retrun the same value (10 in my case).

I tried with CMSIS as well as FreeRTOS mutex functions, result is the same. I tried changing the time base for SysTick, same. I tried with another Nucleo, same.

What did I miss?

答案1

得分: 0

你的代码中存在中断优先级问题。如果你更喜欢使用HAL_Delay而不是RTOS延迟,那么我建议你为FreeRTOS内核使用不同的时间基准定时器。你可以使用相同的定时器,但我不建议在启动调度程序之前这样做。我还强烈建议在启动调度程序之前不要调用任何FreeRTOS函数。

英文:

You have interrupts priority problem in your code. If you prefer to use HAL_Delay instead of RTOS delay then I would suggest to use different timebase timer for the freeRTOS kernel. You can use the same but I would not recooment doing it before you start the scheduler. I would also strongly not advice to call any freeRTOS functions before you start the scheduler.

答案2

得分: -1

根据我所了解,在osKernelStart之前放置大量代码,尤其是与FreeRTOS调用相关的所有内容,这是一个不太好的做法。

我将所有的初始化代码移到一个任务中,并使用信号量来在初始化完成后仅启动其他任务的循环,这样所有问题都得到了解决。

英文:

From what I have read, it is rather bad practice to put a lot of code before osKernelStart, especially everything related to FreeRTOS calls.

I moved all my initialization code into one task and used a semaphore to start the loops of the other tasks only after the initializations were done, and all the problems were solved.

答案3

得分: -1

HAL的tick使用系统定时器,当未使用RTOS时。调试器是你的朋友。找到HAL_IncTick被调用的地方,并在调试时设置断点。

英文:

HAL tick uses system timer when RTOS is not used. Debugger is your friend. Find where HAL_IncTick called and place break point while debugging.

huangapple
  • 本文由 发表于 2023年3月9日 23:40:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686862.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定