Alire with microbit v1

Hi,

I’ve spent some (several) hours now to get a trivial example to link for a bbc:microbit card V1.

Google AI was involved but it did not help that much.

I’m on opensuse 16 and have no compiler installed.

In the end, it compile but usually complains on missing memory-map.ld

sattmate@fuji-i3:~/micro_1> alr build
ⓘ Building micro_1=0.1.0-dev/micro_1.gpr...         
Bind
   [gprbind]      micro_1.bexch
   [Ada]          micro_1.ali
Link
   [link]         micro_1.adb
/home/sattmate/.local/share/alire/toolchains/gnat_arm_elf_11.2.4_ba16d45c/bin/../lib/gcc/arm-eabi/11.2.0/../../../../arm-eabi/bin/ld: cannot open linker script file memory-map.ld: No such file or directory
collect2: error: ld returned 1 exit status
gprbuild: link of micro_1.adb failed

it insists of installing gnat 11, and not 15/16 which is odd, but perhaps the crate has note been updated. It is ok for my purpose, but odd.

So - can anyone point me to how I should do - if I have a clean computer - to get a cross compiling environment that can be used via cli, and compile and link to the bbc-micro?

Did you install the BSP? (Board Support Package) Alire - Microbit_bsp

Also, take a look at Alire - Microbit_examples

The missing file is basically what the BSP should provide or you have to write it by hand if you are doing support from scratch.

I hope this helps. Best regards,
Fer

Fer,

yes I did.

The microbit_bsp is the one with dependence on gnat 11.

I also installed the examples crate

looking at my history I did this

  204 wget https://github.com/alire-project/alire/releases/download/v2.1.1/alr-2.1.1-bin-x86_64-linux.zip
  205  ls
  206  mkdir alire
  207  mv alr-2.1.1-bin-x86_64-linux.zip alire/
  208  cd alire/
  209  unzip alr-2.1.1-bin-x86_64-linux.zip 

  225  alr index --update
  226  alr help index
  227  alr index --update-all
  228  alr init --bin my_microbit_app
  229  ls
  230  cd my_microbit_app/
  231  alr get microbit
  232  alr search microbit
  233  alr get microbit_bsp

  243  cd src/
  244  ls
  245  nano my_microbit_app.adb 
  246  cd ..
  247  alr build

googling gives some old info that is not true anymore, like alr index --update, and the crate changed name from microbit to microbit_bsp.

I used to program it using gnat gpl 2018 on macOS with GPS, so many instructions is still from that time.

However - starting fresh - how do I set it up from the beginning

If those are the exact commands you used, then I can see the problem.

While you did almost perfectly, you did not in fact add microbit_bsp as a dependency. The command alr get microbit_bsp downloads the library to a local folder and allows you to inspect and modify the contents, but it does NOT add it as a project dependency. get is a very useful tool from Alire to download packages/libraries, build them independently, make local modification and potentially use those modified libraries as a project dependency. However, I suppose that is not what you are trying to do.

The command that you need is alr with. with adds a dependency to your project and configures the build system to build it and link against it. So the set of commands that you need are:

alr init --bin my_microbit_app
cd my_microbit_app/
alr with microbit_bsp
cd src/
nano my_microbit_app.adb 
cd ..
alr build

Just one tip. You can use alr edit to launch any editor that you may want to with the full setup already done for you (such as Ada LSP). This wont be very useful for nano but it will help a lot with VS Code, (neo)Vim, Emacs, etc.

I hope this helps. Best regards,
Fer

Thanks for the suggestions, however it won’t work.

It targets the native x86_64-linux platform.

How do I get it to cross compile?

This is the log from what I did -

sattmate@fuji-i3:~> alr init --bin my_microbit_app
Enter a short description of the crate: (default: '')
>
Using default: ''


Select a software license for the crate?
  1. MIT OR Apache-2.0 WITH LLVM-exception
  2. MIT
  3. Apache-2.0 WITH LLVM-exception
  4. Apache-2.0
  5. BSD-3-Clause
  6. LGPL-3.0-or-later
  7. GPL-3.0-or-later WITH GCC-exception-3.1
  8. GPL-3.0-or-later
  9. Other...
Enter your choice index (first is default):
>
Enter a comma (',') separated list of tags to help people find your crate: (default: '')
>
Using default: ''
Enter an optional Website URL for the crate: (default: '')
>
Using default: ''
✓ my_microbit_app initialized successfully.
sattmate@fuji-i3:~> cd my_microbit_app/

sattmate@fuji-i3:~/my_microbit_app> alr with microbit_bsp
The index can be periodically refreshed to make available recently published crates.
Do you want Alire to go online without asking in the future?
(You can update manually with `alr index --update-all` at any time.)
[Y] Yes  [N] No  (default is Yes)
Using default: Yes
◴ Updating index... remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 4 (from 1)
Unpacking objects: 100% (6/6), 9.55 KiB | 9.55 MiB/s, done.
From https://github.com/alire-project/alire-index
   d3366dd..9ee60e0  stable-1.4.0 -> origin/stable-1.4.0
Updating d3366dd..9ee60e0
Fast-forward
 index/li/lithophane/lithophane-0.1.0.toml | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 index/li/lithophane/lithophane-0.1.0.toml
Requested changes:

   ✓ microbit_bsp ~0.2.1 (add)

Changes to dependency solution:

   +   adl_middleware      0.1.1  (new,indirect)
   +   cortex_m            0.2.0  (new,indirect)
   +   embedded_components 0.1.0  (new,indirect)
   +📦 gnat_arm_elf        11.2.4 (new,indirect,binary)
   +   hal                 0.1.0  (new,indirect)
   +   microbit_bsp        0.2.1  (new)
   +   nrf5x_hal           0.1.0  (new,indirect)

Do you want to proceed?
[Y] Yes  [N] No  (default is Yes)
Using default: Yes
ⓘ Deploying microbit_bsp=0.2.1...
Cloning into '/home/sattmate/.local/share/alire/releases/alr-1965-csmf.tmp'...
remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (56/56), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 56 (delta 33), reused 45 (delta 26), pack-reused 0 (from 0)
Receiving objects: 100% (56/56), 30.09 KiB | 505.00 KiB/s, done.
Resolving deltas: 100% (33/33), done.
◴ Exploring /home/sattmate/.local/share/alire/releases/microbit_bsp_0.2.1_6e957a◷ Exploring .../src...
sattmate@fuji-i3:~/my_microbit_app> cd src/
sattmate@fuji-i3:~/my_microbit_app/src> ls
my_microbit_app.adb
sattmate@fuji-i3:~/my_microbit_app/src> cd ..
sattmate@fuji-i3:~/my_microbit_app> alr build
◵ Syncing build dir... embedded_components=0.1.0... Syncing embedded_components=                                                                                ⓘ Building my_microbit_app=0.1.0-dev/my_microbit_app.gpr...
kb: info: can't find a toolchain for the following configuration: language 'Ada', target 'x86_64-linux', default runtime
kb: info: can't find a toolchain for the following configuration: language 'Ada', target 'x86_64-linux', default runtime
Setup
   [mkdir]        object directory for project HAL
   [mkdir]        library directory for project HAL
   [mkdir]        object directory for project Cortex_M0
   [mkdir]        library directory for project Cortex_M0
   [mkdir]        object directory for project NRF51
   [mkdir]        library directory for project NRF51
   [mkdir]        object directory for project Adl_Middleware
   [mkdir]        library directory for project Adl_Middleware
   [mkdir]        object directory for project Embedded_Components
   [mkdir]        library directory for project Embedded_Components
   [mkdir]        object directory for project Microbit_Bsp
   [mkdir]        library directory for project Microbit_Bsp
   [mkdir]        object directory for project My_Microbit_App
   [mkdir]        exec directory for project My_Microbit_App
adl_middleware.gpr:3:09: no compiler for language "Ada", cannot compile "logging_with_priority.ads"
gprbuild: *** compilation phase failed
error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/sattmate/my_microbit_app/my_microbit_app.gpr"] exited with code 7
error: Compilation failed.
sattmate@fuji-i3:~/my_microbit_app>


You have to change the default toolchain. Something like alr toolchain --select if I remember well.

I’ve got it work with some changes in the .gpr

with "config/my_microbit_app_config.gpr";
with "microbit_bsp.gpr";
project My_Microbit_App is

   for Source_Dirs use ("src/", "config/");
   for Exec_Dir use "bin";
   for Main use ("my_microbit_app.adb");

   for Runtime ("ada") use MicroBit_BSP'Runtime ("Ada");
   for Target use "arm-eabi";
   for Languages use ("Ada");
   for Object_Dir use "obj";
   for Create_Missing_Dirs use "True";

   package Compiler renames MicroBit_BSP.Compiler;

   package Linker is
      for Default_Switches ("Ada") use
         MicroBit_BSP.Linker_Switches &
         ("-Wl,--print-memory-usage",
          "-Wl,--gc-sections");
      end Linker;

end My_Microbit_App;