AdaCore / startup-gen

A startup code generator for embedded projects
28 stars 9 forks source link

crt0.S won't compile #43

Closed rogermc2 closed 7 months ago

rogermc2 commented 7 months ago

OSX 13.4.1 GNAT 12.2.0 Xcode 15.1 Target: STM32F030R8 which gprbuild
/opt/GNAT/2020/bin/gprbuild gprbuild --version GPRBUILD Community 2020 (20200429) (x86_64-apple-darwin17.7.0)`

This is my first attempt to build an Ada bare metal project. After solving many problems I have got to a stage where I am unable to find the source of the following problem. gprbuild -P bare_metal_hello.gpr --config=bm_config.cgpr fails with numerous unknown directive errors:

Compile
   [Asm_Cpp]      crt0.s
/System/Volumes/Data/Ada_Projects/bare_metal_ada/bma_1/src/crt0.S:23:2: error: unknown directive
 .syntax unified

and many more, It looks like something is changing crt0.S to crt0.s? Please help

Fabien-Chouteau commented 7 months ago

Hello @rogermc2,

What target architecture did you set in the project? Which run-time are you using?

rogermc2 commented 7 months ago

My gpr file has for Runtime ("Ada") use "zfp-cortex-m0"; for CPU_Name use "ARM Cortex-M0";

From Config file: for Target use "arm-eabi"; for Canonical_Target use "x86_64-darwin"; Originally Target was "x86_64-darwin" but I changed it to "arm-eabi". I also tried "arm-none-eabi", "arm-none-eabi-gcc" but same problem for each. my /opt/ARM/bin has numerous "arm-eabi" versions.

I also tried changing for Canonical_Target use "x86_64-darwin"; to "arm-eabi".

Gpr file: project Bare_Metal_Hello is for Languages use ("Ada", "Asm_Cpp"); -- ASM_CPP to compile the startup code for Source_Dirs use ("src"); for Object_Dir use "obj"; for Main use ("bm_hello.adb");

for Target use "arm-eabi";

-- generic ZFP run-time compatible with our MCU for Runtime ("Ada") use "zfp-cortex-m0";

package Linker is -- Linker script generated by startup-gen for Switches ("Ada") use ("-T", Project'Project_Dir & "/src/link.ld"); end Linker;

 package Device_Configuration is

  --  Name of the CPU core on the STM32F030
  for CPU_Name use "ARM Cortex-M0";

  for Float_Handling use "hard";

  --  Number of interrupt lines on the STM32F030
  for Number_Of_Interrupts use "48";

  --  List of memory banks on the STM32F030
  for Memories use ("SRAM", "FLASH", "CCM");

  --  Specify from which memory bank the program will load
  for Boot_Memory use "FLASH";

  --  Specification of the SRAM
  for Mem_Kind ("SRAM") use "ram";
  for Address ("SRAM") use "0x20000000";
  for Size ("SRAM") use "8K";

  --  Specification of the FLASH
  for Mem_Kind ("FLASH") use "rom";
  for Address ("FLASH") use "0x08000000";
  for Size ("FLASH") use "64K";

  --  Specification of the CCM RAM
  for Mem_Kind ("CCM") use "ram";
  for Address ("CCM") use "0x1FFFEC00";
  for Size ("CCM") use "4096";

end Device_Configuration;

end Bare_Metal_Hello;

Fabien-Chouteau commented 7 months ago

You should have for Target use "arm-eabi"; in your bare_metal_hello.gpr project file,

It's not recommended to use a custom config gpr file --config=bm_config.cgpr. Any specific reason for doing this?

rogermc2 commented 7 months ago

I used --config=bm_config.cgpr (possibly incorrectly) to overcome the following error; gprbuild -P bare_metal_hello.gpr gprconfig: can't find a toolchain for the following configuration: gprconfig: language 'ada', target 'arm-eabi', runtime 'zfp-cortex-m0' bare_metal_hello.gpr:1:09: no compiler for language "Asm_Cpp", cannot compile "crt0.s" gprbuild: *** compilation phase failed

How can I overcome this error?

I tried to attach bm_config.cgpr.zip but it doesn't show in this answer. If it is attached (possibly three times), the only change I made was to Target. Thanks for your support.

Fabien-Chouteau commented 7 months ago

Which compiler version are you using? The zfp-cortex-m0 run-time was renamed light-cortex-m0 a few versions ago.

rogermc2 commented 7 months ago

`Roger@Rogers-Mac-mini bma_1 % which gnat

/opt/GNAT/gnat-x86_64-darwin-12.2.0-1/bin/gnat Roger@Rogers-Mac-mini bma_1 % GNAT --version GNAT 12.2.0 Copyright (C) 1996-2022, Free Software Foundation, Inc.`

Fabien-Chouteau commented 7 months ago

Hi @rogermc2 , this is not an arm cross compiler so you won't be able to compile startup-gen generated code with it.

If you are using Alire, add a dependency on gnat_arm_elf.

rogermc2 commented 7 months ago

Many thanks, I thought that was the case but so far hadn't found a solution. I'll close this issue now and raise another if I get stuck later. Your help is greatly appreciated.