Sunday, December 3, 2023

Programming The Mizar32 Board in Lisp Programming Language

By Raman Gopalan

- Advertisement -

Let us now see two examples:

Toggling LED. A simple PicoLisp program (led.l) is listed below that toggles an LED using a user button on Mizar32 board. Quoted symbols PB_29 and PX_16 are PicoLisp symbols that correspond to pin 29 on Port B and pin 16 on Port X, respectively. Parsing of these values is done in the generic PIO Lisp module (via hardware-abstraction layer). Transient symbols *pio-output* and *pio-input* are used to set directions to the port pins. A simple infinite loop reads the button on the input pin and toggles the LED if pressed.

 [stextbox id=”grey”]# A sample for user-buttons.
# Declare pins
(setq led ‘PB_29 button ‘PX_16)
# A simple delay function
(de delay (t)
(tmr-delay 0 t) )
# Make sure the LED starts in
# the “off” position and enable
# input/output pins
(de init-pins ()
(pio-pin-sethigh led)
(pio-pin-setdir *pio-output* led)
(pio-pin-setdir *pio-input* button) )
# And now, the main loop
(de prog-loop ()
(if (= 0 (pio-pin-getval button))
(pio-pin-setlow led)
(delay 100000)
(pio-pin-sethigh led)
(delay 100000) ) ) )

- Advertisement -

Reaction timer. This program (timer1.l) measures the time taken to press a key on the keyboard after the program is run. Time will be displayed on the terminal. Try it a few times and then see results. Also compare results with others who have tried this before you:
[stextbox id=”grey”]# A reaction timer in picolisp
(de reaction-timer ()
(prinl “Welcome to the reaction timer.
When I say Go!, enter a character.”)
(prinl “Press q [Enter] to quit.”)
timer *tmr-sys-timer*
answer “” )
(until (=T answer)
(println “Ready?”)
# Wait for a random time
from 2 to 5 seconds
(tmr-delay timer (+ 2000000 (rand 1
(println “Go!”)
start-time (tmr-read timer)
answer (read) # wait for them to
enter any character
end-time (tmr-read timer) )
(println “You reacted in “ (tmr-
gettimediff timer start-time
“ microseconds”) ) )[/stextbox]

Testing the examples (Lisp Programming)

We have stored the above two source codes (led.l and timer1.l) in a memory card as explained in this section. To test these two examples, you need Hempl software along with gcc, SCons, dfu-programmer and minicom software running on your Linux system. For this, follow the steps given below:

Installing Hemple software. Get the latest Hempl distribution from github. Make a working directory, say, hacking, for this on your Linux machine (Ubuntu version 13.04)
[stextbox id=”grey”]$ cd hacking
$ git clone
$ cd hempl[/stextbox]

Now, you should be in Hempl directory.

Installing gcc for AVR32. We require a gcc for AVR32 device. Get that from Select Install an AVR32 cross-compiler/Fetching and unpacking the toolchain. Follow the instructions and get the toolchain installed.

Place the toolchain in home directory. It could be something like:
[stextbox id=”grey”]/home/avr32-gnu-toolchain-linux_x86/[/stextbox]

From Hempl directory, make sure the toolchain is in the environment path. Now, do a simple export PATH.
[stextbox id=”grey”]$export PATH=$PATH:HOME/raman/avr32-gnu-toolchain-linux_x86/bin[/stextbox]

And to check if gcc is running:
[stextbox id=”grey”]$avr32-gcc –version[/stextbox]
It will show the version of gcc.

Installing SCons. Install SCons using the following command:
[stextbox id=”grey”]$ sudo apt-get install scons[/stextbox]

Compiling and generating hex codes. From Hempl directory, do the following to compile the code base. For compiling AT32UC3A0256 device, enter the following command:
[stextbox id=”grey”]$ scons cpu=at32uc3a0256 board=mizar32
toolchain=avr32-gcc prog[/stextbox]

This step will produce the machine code for running PicoLisp on Mizar32 board. The compilation will take a few minutes. When done, a hex file called hempl_at32uc3a0256.hex will be generated. This hex file will be burnt into the MCU on Mizar32 board. To understand how to flash the program, refer

Installing dfu-programmer software. Use a program called dfu-programmer. The MCU on Mizar32 board comes with dfu bootloader. It occupies 8kB on the MCU’s flash memory. Please note that a switch (SW2) is required to put the chip in program mode. As soon as we give the following command, program starts running.
[stextbox id=”grey”]$ sudo dfu-programmer at32uc3a0256 start[/stextbox]

Note. Before Lisp programming the device, power on Mizar32 board (or press reset button SW1) while holding the user button (SW2) depressed. For details, refer Mizar32 quick-start guide available on the Internet.


Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components