25.07.2019

All steps to tun your new rapsberry PI4 into a realtime linuxCNC running board
older version
first timing tests



wget "https://downloads.raspberrypi.org/NOOBS_latest"

mount f32-fomatted sdcard

cd [your-sdcard]
unzip [path_to_your_NOOBS-image]/NOOBS_latest
cd ~
umount [your-sdcard]

insert into raspberry and power on


#install default raspbian full

reboot system


#get kernel source of  4.19.50 

wget https://codeload.github.com/raspberrypi/linux/tar.gz/883a1a5bf14abc9b3a014a3907772cd0b3129c8a


#unpack files

tar -xzvf 883a1a5bf14abc9b3a014a3907772cd0b3129c8a


#change to source-dir

cd linux-883a1a5bf14abc9b3a014a3907772cd0b3129c8a


#install bison, flex & co

sudo apt-get -y install bison flex bc


make bcm2711_defconfig
KERNEL=kernel7l

#####################################
### you may now take the short way
####################################

#now get the RT-patch
#(this one, or the one actual one for the kernel)
wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.50-rt22.patch.xz

# and patch the kernel:
xzcat patch-4.19.50-rt22.patch.xz | patch -p1

make oldconfig

date;make -j4 zImage modules dtbs;date
 
sudo make modules_install
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo cp arch/arm/boot/zImage /boot/$KERNEL.img

####################################################
# continue at "end of long way....."
####################################################





########################################################################################
### or the long way........
########################################################################################

date;make -j4 zImage modules dtbs;date 
# one hour compile time
 
sudo make modules_install
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo cp arch/arm/boot/zImage /boot/$KERNEL.img

# then reboot...
# before:
uname -an
#Linux raspberrypi 4.19.57-v7l+ #1244 SMP Thu Jul 4 18:48:07 BST 2019 armv7l GNU/Linux
 

sudo shutdown -r now

# after:
uname -an
Linux raspberrypi 4.19.50-v7l #1 SMP Thu Jul 25 07:48:09 BST 2019 armv7l GNU/Linux


#now get the RT-patch
#(this one, or the one actual one for the kernel)
wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.50-rt22.patch.xz
 

patch the kernel:
xzcat patch-4.19.50-rt22.patch.xz | patch -p1


make oldconfig

and compile and install the patched kernel:
KERNEL=kernel7l
make -j4 zImage modules dtbs
# another hour compile time
sudo make modules_install
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo cp arch/arm/boot/zImage /boot/$KERNEL.img

#################################################
### end of long way.....
#################################################






reboot and test the RT-kernel:

Linux raspberrypi 4.19.50-rt22-v7l #3 SMP PREEMPT RT Thu Jul 25 10:00:42 BST 2019 armv7l

you're done.....



now install linuxCNC
first get the source

git clone https://github.com/LinuxCNC/linuxcnc.git


get a lot of packages....


sudo apt-get -y install autoconf
sudo apt-get -y install cython
sudo apt-get -y install glib
sudo apt-get -y install glibc
sudo apt-get -y install glibc2
sudo apt-get -y install glib-networking-common   
sudo apt-get -y install gtk2
sudo apt-get -y install intltool
sudo apt-get -y install intltool-extract
sudo apt-get -y install libczmq
sudo apt-get -y install  libczmq3
sudo apt-get -y install  libczmq3-dev 
sudo apt-get -y install  libczmq4 
sudo apt-get -y install libczmq-dev
sudo apt-get -y install libglib
sudo apt-get -y install libglib2.0
sudo apt-get -y install   libglibmm
sudo apt-get -y install  libglib-perl  
sudo apt-get -y install libgtk2.0-dev
sudo apt-get -y install libgtk2.0-dev 
sudo apt-get -y install libncurses-dev
sudo apt-get -y install libpng-devel
sudo apt-get -y install libpng++-dev libpng-dev 
sudo apt-get -y install libpng-tools libpng12-dev libpnglite-dev libpnglite0 tkpng 
sudo apt-get -y install libreadline-gplv2-dev
sudo apt-get -y install  libsystemd-dev 
sudo apt-get -y install libtcl
sudo apt-get -y install libtcl8.6
sudo apt-get -y install libtcl8.6 8.6.9+dfsg-2
sudo apt-get -y install libtcl8.6.9+dfsg-2
sudo apt-get -y install libtk-img
sudo apt-get -y install  libtk-img-dev
sudo apt-get -y install libudev-dev
sudo apt-get -y install linuxcnc
sudo apt-get -y install locate
sudo apt-get -y install locatedb
sudo apt-get -y install mc vim
sudo apt-get -y install package uuid-runtime 
sudo apt-get -y install python-yapps  python3-yapps  yapps2 
sudo apt-get -y install tcl
sudo apt-get -y install tclx
sudo apt-get -y install uuid-runtime 
sudo apt-get -y install  yapps
sudo apt-get -y install yapps2
sudo apt-get -y install  yapps-dev
sudo apt-get -y install  yapps-devel
sudo apt-get -y install debhelper libpth-dev dvipng tcl8.4-dev tk8.4-dev bwidget blt libxaw7-dev libncurses-dev libreadline-dev asciidoc source-highlight dblatex groff python-dev python-tk libglu1-mesa-dev libgl1-mesa-dev libgtk2.0-dev gettext autoconf libboost-python-dev 
sudo apt-get -y install git bc bison flex libssl-dev
sudo apt-get -y install glibc
sudo apt-get -y install glibc-source 
sudo apt-get -y install libmodbus-dev
sudo apt-get -y install libtk-img
sudo apt-get -y install libudev-dev
sudo apt-get -y install libusb-1.0-0-dev
sudo apt-get -y install libreadline-gplv2-dev
sudo apt-get -y install mesa-utils

#(do not care, if a few packages are missing)


#now to linuxCNC:
cd linuxcnc/src
 ./autogen.sh 
./configure
make 
sudo make setuid
cd ..
. ./scripts/rip-environment
 
# start latency-test

latency-test


# start linuxCNC

linuxcnc

# done.... ;-)



if you are missing something drop me a mail


wicki@erste.de


some hours later this day......

How to start linuxCNC in the raspberry PI4 with the GPIO-Interface?
Iportant:
I use the aktual bcm2835-lib here. Also wiringpi/gpio-link points to a wrong version. Be shure, to use wiringpi 2.52!! You can test the GPIO with: gpio mode 0 out;gpio blink 0 Now you should get a square-wave on GPIO0 (Pin 11)
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz
tar -xzvf bcm2835-1.60.tar.gz 
cd bcm2835-1.60/
./configure
make
sudo make check
sudo make install
cd ..



now follow these steps:
http://wiki.linuxcnc.org/cgi-bin/wiki.pl?RPi3BPreemptRT#buildhalgpio

#start in linuxcnc-directory

mkdir hal_gpio
cd hal_gpio/
wget http://wiki.linuxcnc.org/uploads/bcm2835.h
wget http://wiki.linuxcnc.org/uploads/cpuinfo.h
wget http://wiki.linuxcnc.org/uploads/hal_gpio.c
wget http://wiki.linuxcnc.org/uploads/Makefile

# edit hal_gpio.c and insert al line 312:

    case 5:          //FIXME!!!  
      rtapi_print_msg(RTAPI_MSG_INFO, "Raspberry4\n");
      pins = rpi2_pins;
      gpios = rpi2_gpios;
      npins = sizeof(rpi2_pins);
      break;



cp bcm2835.h  cpuinfo.h hal_gpio.c ../src/hal/drivers/
# save original makefile
mv ../src/Makefile ../src/Makefile.sav
cp Makefile ../src/
cd ..
cd src/
make modules


cd ..

# get the demo-config

wget http://wiki.linuxcnc.org/uploads/Geck0-540B3-5-rpi3b-225vel.ini
wget http://wiki.linuxcnc.org/uploads/Gecko_540B3-4-rpi3b-2250vel.hal

# make a link (there is a filename-typo)
ln -s Gecko_540B3-4-rpi3b-2250vel.hal Gecko-540B3-4-rpi3b-225vel.hal

# remove "dir=78855 exclude=3291852" from line 40"
# comment out line 69
# and change the pins to your needs.
# If you use the following, GPIO0 (PIN 11) ist toggled
# while klicking "+" or "-" of Y-axis4


vim Gecko-540B3-4-rpi3b-225vel.hal
#net spindle-cmd <= motion.spindle-speed-out

# i use GPIO 2,3,4 for xtep ystep zstep, thats rpin 3,5,7 resp
net xstep stepgen.0.step => hal_gpio.pin-07-out
net ystep stepgen.1.step => hal_gpio.pin-08-out
net zstep stepgen.2.step => hal_gpio.pin-10-out

# i use GPIO 14,15,18 for xdir ydir zdir, thats rpin 
net xdir  stepgen.0.dir  => hal_gpio.pin-03-out
net ydir  stepgen.1.dir  => hal_gpio.pin-11-out
net zdir  stepgen.2.dir  => hal_gpio.pin-12-out




# and start linuxCNC

linuxcnc Geck0-540B3-5-rpi3b-225vel.ini

now try and change the configs to ypour needs....