Search code examples
ada

Tasking support in CortexM4-based board


I am experimenting with tasking in a Cortex M4 based board (specifically a stm32f429I one) but it looks like the runtime I'm using doesn't allow task hierarchy (which kind of make sense). To give a bit more context, I've written the following procedure:

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;

(and there would be client tasks calling these entries). My gprbuild file looks like that:

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;

And when I try to build, I get the following errors:

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

I tried looking into my GNAT installation for any clues for available runtimes and found a number of directories under 2021-arm-elf/arm-eabi/lib/gnat/ which I think correspond to the available runtimes that can be specified in the build file? These all fall under two main categories i.e. ravenscar* and zfp* ones (I assume these are the ones with floating-point support?) and as, as far as I know, the Ravenscar ones don't support task hierarchies, I gave some of the zfp ones a try but got similar errors (there seem to be some more generic Cortex-M4 and some board-specific ones).

So, I was wondering how available runtimes can be discovered and if there're any tips on how to go about finding a runtime (if one exists) that supports multi-tasking for this board. - Thanks


Solution

  • I would suggest you to read the documentation. For GNAT GPL Edition 2021 you can find it in the installation folder <INSTALL>/share/doc/gnat-cross/html/gnat_ugx/gnat_ugx.html. See "Chapter 4 The Predefined Profiles". ZFP is Zero Footprint Profile. It has no support for tasking. Ravenscar has some tasking support, but you should move tasks to a package of the library level.

    AdaCore changed runtime names recently (see documentation). It could be simpler for you to install GNAT 13.2 or GNAT 12.2 using alire and start with it then relearn after GNAT GPL 2021.