基于Cortex-M4的STM32F429I板任务调度适配问题咨询
在STM32F429I(Cortex-M4)上的Ada任务调度问题
我正在基于Cortex-M4架构的STM32F429I开发板做任务调度实验,但当前使用的运行时不支持任务层级结构,编译报错。以下是详细信息:
Ada程序代码
procedure Flash_LED_With_Randevouz is type LED_Colour is (Red, Green); task type LED_Controller(LC: LED_Colour) is entry Turn_LED_On; entry Turn_LED_Off; end LED_Controller; task body LED_Controller is begin -- Setup port clock, pin mode etc here based on "LC" value loop accept Turn_LED_On do null; end Turn_LED_On; accept Turn_LED_Off do null; end Turn_LED_Off; end loop; end LED_Controller; RC: LED_Controller(Red); GC: LED_Controller(Green); begin null; end Flash_LED_With_Randevouz;
gprbuild配置文件
project Embedded is for Languages use ("Ada", "Asm"); for Main use ("flash_led_with_randevouz.adb"); for Source_Dirs use ("src/**"); for Object_Dir use "obj"; for Target use "arm-eabi"; for Runtime ("Ada") use "ravenscar-full-stm32f429disco"; package Compiler is for Default_Switches ("Ada") use ("-O0", "-g", "-gnatwa", "-gnatQ", "-gnatw.X"); end Compiler; package Builder is for Default_Switches ("Ada") use ("-g"); for Global_Configuration_Pragmas use "gnat.adc"; end Builder; package Ide is for Connection_Tool use "st-util"; for Program_Host use "localhost:4242"; for Communication_Protocol use "remote"; end Ide; end Embedded;
编译错误信息
Compile [Ada] flash_led_with_randevouz.adb flash_led_with_randevouz.adb:5:04: warning: objects of this type will violate "No_Task_Hierarchy" [enabled by default] flash_led_with_randevouz.adb:7:07: error: violation of implicit restriction "Max_Task_Entries = 0" flash_led_with_randevouz.adb:18:10: error: construct not allowed in configurable run-time mode flash_led_with_randevouz.adb:18:10: error: file s-tasren.ads not found flash_led_with_randevouz.adb:18:10: error: entity "System.Tasking.Rendezvous.Exceptional_Complete_Rendezvous" not available flash_led_with_randevouz.adb:28:04: error: violation of restriction "No_Task_Hierarchy" flash_led_with_randevouz.adb:28:04: error: from profile "Jorvik" at system.ads:42 flash_led_with_randevouz.adb:29:04: error: violation of restriction "No_Task_Hierarchy" flash_led_with_randevouz.adb:29:04: error: from profile "Jorvik" at system.ads:42 gprbuild: *** compilation phase failed
我查看GNAT安装目录,2021-arm-elf/arm-eabi/lib/gnat/下只有ravenscar*和zfp*两类运行时,更换zfp系列后仍有类似错误。想请教:
- 如何查询当前GNAT版本支持的可用运行时?
- 是否存在支持该开发板多任务(包含任务条目、会合机制)的运行时?
解答
1. 查询可用运行时
使用GNAT的gnatls工具可以列出当前目标平台下的所有可用运行时,执行命令:
gnatls -v --target=arm-eabi
该命令会输出目标平台的运行时列表,以及每个运行时的详细特性与限制说明。
2. 适配STM32F429I的多任务运行时
你当前使用的ravenscar-full-stm32f429disco属于Ravenscar精简实时profile,默认限制了任务层级、禁用了任务会合(Max_Task_Entries=0),而你的代码使用了任务条目和会合机制,因此触发错误。针对这个问题,有以下几种解决方向:
- 寻找兼容的Ravenscar变种运行时:部分GNAT版本提供了
ravenscar-full(不带板级后缀)的通用运行时,或针对STM32F4的ravenscar-tasking类运行时,这类运行时通常支持任务条目和会合机制。 - 自定义运行时配置:如果现有运行时不满足需求,可以基于GNAT的可配置运行时(CRT)框架修改配置:复制现有运行时的配置文件,修改
system.ads中的限制pragma(比如取消No_Task_Hierarchy限制、设置Max_Task_Entries为大于0的值),再用gnatmake重新编译生成适配的运行时库。 - 升级GNAT版本:你使用的是2021版GNAT,较新版本的GNAT(如2023+)针对STM32系列提供了更丰富的运行时选项,可能包含支持会合机制的板级专用运行时。
另外,若暂时无法更换运行时,可修改代码绕过No_Task_Hierarchy限制——将任务定义为独立的顶级任务,而非任务类型:
procedure Flash_LED_With_Randevouz is task Red_LED_Controller is entry Turn_LED_On; entry Turn_LED_Off; end Red_LED_Controller; task body Red_LED_Controller is begin -- 红色LED初始化代码 loop accept Turn_LED_On do null; end Turn_LED_On; accept Turn_LED_Off do null; end Turn_LED_Off; end loop; end Red_LED_Controller; task Green_LED_Controller is entry Turn_LED_On; entry Turn_LED_Off; end Green_LED_Controller; task body Green_LED_Controller is begin -- 绿色LED初始化代码 loop accept Turn_LED_On do null; end Turn_LED_On; accept Turn_LED_Off do null; end Turn_LED_Off; end loop; end Green_LED_Controller; begin null; end Flash_LED_With_Randevouz;
但这种修改仅能绕过任务层级限制,无法解决会合机制被禁用的问题,因为Max_Task_Entries=0的限制依然存在。
内容的提问来源于stack exchange,提问作者Sidisyom
相关产品推荐
相关产品推荐

