Source: /cirosantilli/program-the-micro-bit-in-c

= Program the Micro Bit in C
{c}
{tag=C (language)}

https://stackoverflow.com/questions/73877965/how-to-compile-c-c-code-into-a-hex-file-for-the-bbc-microbit

Official support is abysmal, very focused on <MicroPython> and their graphical UI.

The setup impossible to achieve as it requires setting up the <Yotta (Build system)>, just like the impossible to setup <Compile MicroPython code for Micro Bit locally on Ubuntu 22.04 with your own firmware> setup.

So we just use https://github.com/lancaster-university/microbit-samples + https://github.com/carlosperate/docker-microbit-toolchain[]:
``
docker pull ghcr.io/carlosperate/microbit-toolchain:latest
git clone https://github.com/lancaster-university/microbit-samples
cd microbit-samples
git checkout 285f9acfb54fce2381339164b6fe5c1a7ebd39d5

# Select a sample, builds one at a time. The default one is the hello world.
cp source/examples/hello-world/* source

# Build and flash.
docker run -v $(pwd):/home --rm ghcr.io/carlosperate/microbit-toolchain:latest yotta build
cp build/bbc-microbit-classic-gcc/source/microbit-samples-combined.hex "/media/$USER/MICROBIT/"
``
.hex file size for the hello world was 447 kB, much better than the <MicroPython> hello world downloaded from the website which was about 1.8 MB!

If you try it again for a second time from a clean tree, it fails with:
``
warning: github rate limit for anonymous requests exceeded: you must log in
``
presumably because after Yotta died it started using GitHub as a registry... sad. When will people learn. Apparently we were at 5000 API calls per hour. But if you don't clean the tree, you will be just fine.