alan-turing-institute / OMicroB

An OCaml generic virtual machine for microcontrollers
Other
0 stars 0 forks source link

Dry run to deploy mbdisplay.ml on microbit2 #1

Open myyong opened 2 months ago

myyong commented 2 months ago

This documents my efforts to deploy mbdisplay.ml on a microbit.

I found that the README is broadly accurate. Here are some issues I encountered when setting up the environment.

  1. Obytelib1.6 has following dependency: ocaml](https://ocaml.org/p/ocaml/latest) >= "4.02.0" & < "4.15.0"

    So I used opam switch create omicrob4.12 4.12.0. ocaml4.14 may work just as well.

  2. I ran into basic linker errors (eg. # include ). Turns out I needed I needed the full arm tool chain as explained here

brew uninstall arm-none-eabi-gcc
brew install --cask gcc-arm-embedded
  1. Commit 38a79fa points arm-none-eabi-gcc to the brew version, not the clang. Note: The arm-none-eabi-gcc is a linker stored at /opt/homebrew/bin/arm-none-eabi-gcc which points to the compiler in /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi.

As a result, the etc/Makefile.conf created by ./configure -target microbit looks like this:

VERSION := 0.1 OCAMLCLEAN := /Users/myong/.opam/omicrob4.12/bin/ocamlclean BINDIR := /usr/local/bin LIBDIR := /usr/local/lib/omicrob LIBEXECDIR := /usr/local/libexec/omicrob INCLUDEDIR := /usr/local/include/omicrob MAN1DIR := /usr/local/man/man1 MAN3DIR := /usr/local/man/man3 GXX := /opt/homebrew/bin/g++-14 AVR_GXX := AVR_OBJCOPY := AVRDUDE := XC32_GXX := XC32_BIN2HEX:= PIC32PROG := ARM_GXX := /opt/homebrew/bin/arm-none-eabi-gcc ARM_OBJCOPY := /opt/homebrew/bin/arm-none-eabi-objcopy OCAMLC := /Users/myong/.opam/omicrob4.12/bin/ocamlc.opt -w A-4-58-70 -warn-error A -safe-string -strict-formats -strict-sequence OCAMLOPT := /Users/myong/.opam/omicrob4.12/bin/ocamlopt.opt -w A-4-58-70 -warn-error A -safe-string -strict-formats -strict-sequence OCAMLDOC := /Users/myong/.opam/omicrob4.12/bin/ocamldoc.opt OCAMLBUILD := /Users/myong/.opam/omicrob4.12/bin/ocamlbuild -cflags -w,A-4-58-70,-warn-error,A,-safe-string,-strict-formats,-strict-sequence -lflags -w,A-4-58-70,-warn-error,A,-safe-string,-strict-formats,-strict-sequence -no-links -classic-display -build-dir .build OCAMLWHERE := /Users/myong/.opam/omicrob4.12/lib/ocaml SRC := /Users/myong/Documents/workspace/OMicroB/src BIN := /Users/myong/Documents/workspace/OMicroB/bin LIB := /Users/myong/Documents/workspace/OMicroB/lib ETC := /Users/myong/Documents/workspace/OMicroB/etc

  1. I removed * open Simul * because it pops up an unused module warning. b0265bd342845c6a468379e4c34a9ac56275ec2d The alternative is to silence the warning by editing -w A-4-58-70 in ocamlc.opt -w A-4-58-70 -warn-error A -safe-string -strict-formats -strict-sequence.

  2. I installed Graphics: opam install Graphics

These got ./configure -target microbit && make && make install to set up environment working.

myyong commented 2 months ago

These are the issues I encountered when running OMicroB/targets/microbit/tests/display/make, to create mbdisplay.hex.

  1. Somewhere, there are system calls resulting in errors like _lseekr.c:(.text._lseek_r+0x14): warning: lseek is not implemented and will always fail. I don't want to implement these, because of here

  2. I encountered the error _unwind-arm.c:(.text.get_eit_entry+0x94): undefined reference to `__exidxend' which prevented creation of hex file. I added the following:

    .ARM.exidx :
    {
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
    } >FLASH

    to the linker targets/microbit/byterun/nRF52833.ld. 602b9fed2cec303f7e7efeb45711901eb614d79b.

Not sure this is a great idea. The error stems from arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -fno-exceptions -fno-unwind-tables -Os -Wall \ -Wl,-Os -fdata-sections -ffunction-sections -Wl,--gc-sections \ -specs=nosys.specs -D__MICROBIT__ \ -T /Users/myong/Documents/workspace/OMicroB/src/byterun/microbit/nRF52833.ld \ -nostartfiles -lnosys mbdisplay.arm_o \ /Users/myong/Documents/workspace/OMicroB/src/byterun/microbit/startup2.o \ /Users/myong/Documents/workspace/OMicroB/src/byterun/microbit/microbian2.a \ -lm -lc -lgcc -o mbdisplay.arm_elf.

Options:

Therefore I think Ensure the linker script properly defines the .ARM.exidx section. is my quickest option. I may be stuck in debugging hell for weeks in future for this.

myyong commented 2 months ago

Flashing the hex to microbit using omicrob -flash <file.hex> -device $DEVICE didn't work for me. I copied the hex file over to the mounted device instead.