Skip to content

Micropython on FPGAs

Tim Ansell edited this page Nov 22, 2016 · 1 revision

In the lm32 branch of this repository is a basic port to the litex SoC with a lm32 CPU. So far only the litex uart is supported.

The port currently assumes you are running on the opsis-soc, targeted for the minispartan6. You can adjust this by replacing the include/generated directories with the ones from your litex soc in both Qemu and Micropython.

Building

Cross compiler

This port requires a lm32 cross compiler with libgcc enabled.

I built a GCC 6.2 toolchain with newlib. A Dockerfile and build script which does this is available here:

https://github.com/shenki/lm32-build-scripts

Qemu

While lm32 support is upstream, the litex machine mode is not. key2 has a (rough port](https://bitbucket.org/key2/qemu) which I added the opsis-soc generated headers to.

  $ git clone https://github.com/shenki/qemu-litex
  $ cd qemu-litex
  $ ./configure --target-list=lm32-softmmu
  $ make

Micropython

  $ cd micropython/lm32
  $ CROSS_COMPILE=/opt/lm32/bin/lm32-elf- make deploy

This produces an elf at lm32/build/firmware.elf.

Running

Run in Qemu

  ./lm32-softmmu/qemu-system-lm32 -M litex -nographic -nodefaults \
   -serial stdio -kernel ~/dev/micropython/lm32/build/firmware.elf
   MicroPython v1.8.6-12-g674efbf5680a on 2016-11-20; litex with lm32
   Type "help()" for more information.
   >>>

Debug in Qemu

  ./lm32-softmmu/qemu-system-lm32 -M litex -nographic -nodefaults \
   -serial stdio -kernel ~/dev/micropython/lm32/build/firmware.elf \
   -S -s -monitor pty
  char device redirected to /dev/pts/12 (label compat_monitor0)

This requires a lm32 GDB:

  $ conda/bin/lm32-elf-gdb build/firmware.elf -ex 'target remote localhost:1234'
  Reading symbols from build/firmware.elf...done.
  Remote debugging using localhost:1234
  0x40000000 in _start ()
  (gdb) c
  Continuing.

You can attach to the monitor to view the lm32 registers that are not exposed by qemu:

  screen /dev/pts/12
  (qemu) QEMU 2.7.50 monitor - type 'help' for more information
  (qemu) info registers
  IN: PC=40000000
  ie=00000000 (IE=0 EIE=0 BIE=0) im=00000000 ip=00000000
  eba=00000000 deba=00000000

Clone this wiki locally