Sign in Join
Wiki copytemporary

micro:bit

The micro:bit is a small embedded system equipped with a Nordic Semiconductor nRF51822 controller based on the Cortex-M0 architecture. With FPC trunk, it is possible to build programs for it. Follow the instructions at Embedded ARM to setup FPC for the target arm-embedded. However, do not use the provided command line to build and install FPC but use

text
 make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv6m

instead to build FPC for the controller used by the micro:bit.

Now enter the following program:

pascal
  const
    GPIO_PIN_CNF_INPUT_Disconnect = 1;
    GPIO_PIN_CNF_DIR_Output = 1;
    microbit_led_col1 = 4;
    microbit_led_row1 = 13;
  var
    i : longint;
  begin
    GPIO.PIN_CNF[microbit_led_col1]:=(GPIO_PIN_CNF_INPUT_Disconnect shl 1) or GPIO_PIN_CNF_DIR_Output;
    GPIO.PIN_CNF[microbit_led_row1]:=(GPIO_PIN_CNF_INPUT_Disconnect shl 1) or GPIO_PIN_CNF_DIR_Output;
    while true do
      begin
        GPIO.OUTSET:=1 shl microbit_led_row1;
        GPIO.OUTCLR:=1 shl microbit_led_col1;
        for i:=1 to 500000 do
          asm
            nop
          END;
        GPIO.OUTCLR:=1 shl microbit_led_row1;
        for i:=1 to 500000 do
          asm
            nop
          END;
      end;
  end.

save it as example.pp and compile it with:

text
 fpc -Parm -Tembedded -Wpnrf51822_xxaa example -Cparmv6m

When connecting a micro:bit to PC, it identifies itself as an USB drive. Find out where this drive is located and copy the resulting example.hex to this drive.

If everything worked fine, the upper left LED will blink.


From the Free Pascal wiki, page "micro:bit", as it stood on 2019-12-17 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.