LPC Microcontroller Graphics Output to a HDMI Monitor

All this work and documentation was been done by Marian. Thank you very much for your contribution. – Robert

(A) Download LPC binary and .deb package

If you want to just try demo without dealing with steps (B) and (C), use following links: spi_game.elf.bin openrex_spi_canvas.deb

(B) How to compile ‘openrex_spi_canvas’ on PC

Please add “openrex-spi-canvas” into your local.conf to include example in linux image.

IMAGE_INSTALL_append += "openrex-spi-canvas"

The recipe itself is locate at “sources/meta-openrex/recipes-examples/openrex-spi-canvas/openrex-spi-canvas.bb” with all source files inside “files” subdirectory.

If you don’t want to rebuild whole image, just the example, you need to run

bitbake openrex-spi-canvas

and copy output binary from “<build>/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/openrex-spi-canvas/1.0-r0/build/” to sdcard.

(C) How to compile LPC ‘spi_game’ application on PC

1) Download cross compiled GCC from

https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q2-update/+download/gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2

and unpack the archive. If you don’t mind to use ‘~/.bin’ directory for this purpose, please follow these commands:

mkdir -p ~/.bin
tar -xf gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2 -C ~/.bin
export CROSS_COMPILE="${HOME}/.bin/gcc-arm-none-eabi-5_4-2016q2/bin/arm-none-eabi-"

Last line is essential. The CROSS_COMPILE is used by build system to locate your toolchain.

2) Install git and cmake.

If you are using ubuntu, you can use following commands

sudo apt-get install cmake git make

3) Clone repository

git clone https://github.com/FEDEVEL/openrex-lpc.git

When it finishes, move to ‘openrex-lpc/examples/spi_game’ and run ‘source build.sh’
It fires build process and when it succeed you should see among last lines:
“[100%] Generating spi_game.elf.bin”

4) Application is located in “build” sub-directory and has two forms.

“spi_game.elf” – is a ‘container’ that keeps binary data separated into segments. To place binary data into LPC address space you have to use GDB (with JTAG/SWD probe) or bootloader.

“spi_game.elf.bin” – is a file that holds a raw binary data. You can consider it to be a “snapshot” of some address space range. We are going to use the binary form.

5) Upload “spi_game.elf.bin” to Openrex Linux. Secure copy command might be useful.

scp spi_game.elf.bin root@xxx.xxx.xxx.xxx:/home/root/

when you replace xxx.xxx.xxx.xxx with your Openrex IP address

(D) Assemble buttons

The demo requires to use external buttons connected to connector J1, positions 11 (player 1 button) 12 (player 2 button) 13 (start/stop button). All three push-buttons are active in high level, so one pin must be connected to GPIO signal, the other one to VCC (J1, position 7). Depending on connections, conditions and type of your buttons, you might want to use external pull-down resistors.

OLYMPUS DIGITAL CAMERA

(E) Run demo on IMX

1) Flash the binary to LPC

openrex-isp-handler.sh spi_game.elf.bin

2) Run “openrex_spi_canvas” with arguments

openrex_spi_canvas -s /dev/spidev2.0 -t /dev/tty1 -f /dev/fb0 -b 400000

3) Now if you press ‘start/stop’ button you should see the ball moving to right edge of monitor. Pres player2′s button to make ‘plate’ move down to bounce the ball.

Note: All LPC examples use LED 24 (the one next to power connector) for assertion. If the LED blinks, it means that something is seriously wrong and application is forced to run in save infinite loop.

(F) How does it work on Linux

Linux is acting as SPI master that reads data from SPI bus.  Most of SPI peripherals are designed the way that one transfer consists of one read and one write at the same time. In other words, if you want to read a byte, you have send a byte at the same moment. So, “reading” means that we have to send the same amount of “dummy” data in return. The dummy data are then dropped on slave. Since we are using the 8bit transfer, the dummy pattern is set as 0xFF. The SPI transfer happens (generates clock) when master performs transmit.

Some received data are recognized as commands following by serialized objects. The command denotes the type of object and performs specific action. For instance, if SPI master receive 0×4 (CANVAS_CMD_CIRCLE), it expects then receive data of circle object (struct cmd_circle) which is then drew to framebuffer.

(G) How does it work on LPC

… however you want, the application is result of your creativity. But from SPI point of view the LPC is acting as SPI slave – which means that LPC needs to provide the data for Linux all the time. When your application does not have any commands (with objects) to send, the IRQ handler prepares dummy data instead and they are dropped on Linux site.

(H) Improvements

1) Change SPI roles. The LPC should be SPI master and Linux SPI slave. Reason? It’s the LPC who makes all independent decisions. Linux then doesn’t have to poll bus all the time. However it’s not the easiest job to persuade Linux to behave as SPI slave with  API available in user-space.

2) Use two (active/inactive) framebuffers, to eliminate “blinking” effect. Data would be drawn to inactive framebuffer and when finishes, it will just swap the buffers … I have to dig deeper into IPU documentation.

Please don’t consider the applications as a real solutions. They are just a demos to demonstrate Openrex capabilities.