linuxcnc for Raspberry Pi with RT_PREEMPT kernel

6th May 2013 first draft of docs, this really needs editing, excuse my rambling mistakes and poor writing

Warning, I am not a linux expert and have never used ARM based machines until I got the rpi, this is a hack job,use at your own risk

This is a very basic outline of the current state of linuxcnc on the raspberry pi.

When I first saw the rpi I immediatly thought about linuxcnc as the rpi would make a great controller for low cost machines (3D printers, mills, lathes, robots, home automation) which should be where the next level of computing must move towards for improving efficiency in real world situations.

The specs looked great as I knew linuxcnc would run on an old pentium2 and rpi has more processing power, the only problem would be getting it to compile, and run in realtime, and access I/O.

First problem was compiling, which as it turned out was fairly simple thanks to linuxcnc being fairly well coded and portable, the only problem was a few compiler switches and finding the correct packages to install to allow './configure' to complete its tests.

The next problem was a bit harder which was finding a realtime kernel, but this now has two option Xenomai (which I have not tried) and RT_PREEMPT which this distro uses.

The final problem of I/O is a bit harder and ties in with realtime performance not being very good, in order to produce software step generation a high speed basethread must be possible (which it is not), so the step generation must be offloaded some how from the main cpu.

I am making a raspbian based SD card image available, but unfortunatly it is not currently tested, so should be considered for experts only.

Download and run

this version is working updated due to file corruption in previous image file 9th may 2013 rpi_linuxcnc.rar

Basically download the image file and write it to your SD card using whatever method you normally use (2Gb card minimum). boot the RPI with the image login as pi, password raspberry. Then type startx, wait a little while for X to load then left click and hold your mouse and a menu should appear click on debian->applications->shells->bash, when the terminal opens cd to the emc directory 'cd emc*' then type './'. The linuxcnc axis system should load into X, you should select the rpi configuration option. then connect your stepper drivers to the relevant pins (outlined in the README in the config diri, and should be shown when you select the rpi configuration)


The rpi is a nice cheap base platform but unfortunately has mediocre realtime performance, most this is due to USB and networking implementation as it seems there are a huge number of interupts that must occur for the USB system to function and also possibly GPU may cause interupts. Interupts have a time cost due to context switching so the shortest possible guaranteed base thread time is increased in length. To get high speed constant regular step pulses other means than direct cpu switching of the GPIO must be used.

The pins should be able to drive standard ttl logc (the high is 3.3volt, but 5v ttl should sense this as a logic high unless there is some extra line drop)

I guess the list below shows what I have considered possible methods but there are probably other ways of doing this I have not considered.

possible ways of constant step pulses

The DMA method (DMA switched GPIO pins directly controlling the step/dir) is what has been settled on as this means no external hardware is required, and the method used is thanks to the code ideas used in RPIO this code made the inspired idea of using the pwm generator to cause DMA to delay writing, thus creating a constant step time.


I should say that this is a work in progress, and I feel that probably a pic32 based daughter card is probably a better way to go, but the DMA stepgen driver may work reasonably for most people if less than 22 I/O pins are required.


Some links of information that I found and may be relevant: