AdaCore / bb-runtimes

Source repository for the GNAT Bare Metal BSPs
Other
65 stars 51 forks source link

Adding ZFP support for SAMD21/Arduino Zero #28

Closed abeco closed 4 years ago

CLAassistant commented 4 years ago

CLA assistant check
All committers have signed the CLA.

Fabien-Chouteau commented 4 years ago

Hello @abeco, thanks for your contribution

We are experimenting a different way of supporting the ZFP run-time for ARM cortex-M. The idea is that we provide with GNAT (already in GNAT Community 2020) a set of generic ZFP run-times for every Cortex-M variant (M0, M0+, M3, etc.). And then user only have to add a crt0.S and linker script based on their board/micro-controller. The crt0.S and linker script can be generated with the startup-gen tool: https://github.com/AdaCore/startup-gen

For instance in your case, the project file will look like this:

project Arduino_Zero is

  for Languages use ("Ada", "ASM_CPP");
  for Target use "arm-eabi";
  for Runtime ("Ada") use "zfp-cortex-m0p";
  for Object_Dir use "obj";
  for Create_Missing_Dirs use "True";
  for Source_Dirs use ("src");
  for Main use ("main.adb");

  package Linker is
     for Switches ("Ada") use ("-T", Project'Project_dir & "/src/link.ld");
  end Linker;

  package Device_Configuration is
     for CPU_Name use "ARM Cortex-M0+";

     for Memories use ("flash", "ram");

     for Mem_Kind ("flash") use "rom";
     for Address  ("flash") use "0x00000000";
     for Size     ("flash") use "0x00040000";

     for Mem_Kind ("ram") use "ram";
     for Address  ("ram") use "0x20000000";
     for Size     ("ram") use "0x00008000";

     for Boot_Memory use "flash";
  end Device_Configuration;
end Arduino_Zero;

Create a src directory with a dummy main.adb:

procedure Main is
begin
   null;
end Main;

And you can generate the crt0.S and linker script with this command:

startup-gen -P arduino_zero.gpr  -l src/link.ld -s src/crt0.S

And finally compile the project:

Compile
   [Ada]          main.adb
   [ASM_CPP]      crt0.S
Bind
   [gprbind]      main.bexch
   [Ada]          main.ali
Link
   [archive]      libarduino_zero.a
   [index]        libarduino_zero.a
   [link]         main.adb

With this solution we can have ZFP on every ARM Cortex-M micro-controller, without having to maintain BSP files in this repository. For that reason, we will not merge your pull-request.

Regards,