Raspberry Pi 2, how to disable device_tree to enable SPI? - linux

I have a Raspberry Pi 2, Model B, and I'd like to use the SPI to talk to another Pi (for later using it for more SPI-devices). I'd also like to use WiringPi for C-coding my program.
I thought I would ensure I had everything I needed, so i ran a full upgrade:
sudo apt-get update && sudo apt-get upgrade -y
I installedWiringPi, and enabling SPI to be loaded from raspi-config, but I still can't do a gpio load SPI without the following error:
gpio: Unable to load/unload modules as this Pi has the device tree enabled.
You need to run the raspi-config program (as root) and select the
modules (SPI or I2C) that you wish to load/unload there and reboot.
There is more information here:
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314
I then tried what the link suggested:
... add "device_tree=" to your config.txt and reboot.
$ nano sudo /boot/config.txt
# Go to last line
# Add 'device_tree='
# Save, and exit
$ sudo reboot
Then I tried gpio load spi, but I still get the same error.
SPI is enabled in /boot/config.txt:
$ cat /boot/config.txt | grep spi
dtparam=spi=on
Have any of you suggestions to, what I can try to enable my SPI?

According to this thread,gpio load spi is deprecated.

Related

socketcan alternative / add can0 to /dev/

I am currently working with CAN-BUS Systems.
I make the CAN Interface available using
sudo modprobe can
sudo modprobe can-raw
sudo modprobe mttcan
sudo ip link set can0 type can bitrate 250000
sudo ip link set up can0
It now shows up in ifconfig and works fine in my python code.
Since I am working with aws greengrass I need the device to show up in /dev/ in order to access it. Is there any way to use something different than socketcan? If so, how do I use it?
I have no idea how linux handles can interfaces.

PWM using bcm2835 library as non-root in Raspberry Pi

I need to control some DC motors using PWM. I have been trying to use the bcm2835 library, but I need root access to run my program. I need to avoid this, as this program is part of a ROS package, which gives problems if run as root. I have tried to follow the instructions that appear in the section "Running as root", but I haven't been successful. I have done the following.
First, I have installed libcap2 and libcap-dev and added my user to the kmem group.
sudo apt-get install libcap2 libcap-dev
sudo adduser ubuntu kmem
Then, I have installed the version latest version of bcm2835 library.
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.67.tar.gz
tar zxvf bcm2835-1.67.tar.gz
cd bcm2835-1.67
./configure
make
sudo make check
sudo make install
After that, I uncommented the #define BCM2835_HAVE_LIBCAP line in bcm2835.h, which I found in /usr/local/include/.
I allowed write access to /dev/mem by members of kmem group.
echo 'SUBSYSTEM=="mem", KERNEL=="mem", GROUP="kmem", MODE="0660"' | sudo tee /etc/udev/rules.d/98-mem.rules
sudo reboot
And finally, I compiled my program (called l298n) and run the following command.
sudo setcap cap_sys_rawio+ep l298n
After doing all this, my program is still not able to provide PWM control unless I run it as root.
Have I done anything wrong? Is there any other way around this? As far as I know, other libraries would run into the same problem, as it depends on the access level of /dev/mem.
I am running Ubuntu 20.04 LTS in a Raspberry Pi 3B+.
What you did wrong:
You edited the wrong bcm2835.h, you need to edit bcm2835.h where ever you unpacked bcm2835-1.67.tar.gz, not /usr/local/include.
You didn't recompile the library to actually have the added feature in it.
Also, if you're just accessing the GPIO pins and don't need non-root access to /dev/mem then there's no need to do anything more than adding access rights to /dev/gpiomem to your non-root user.
Have you tried version 68 already ?
There where made some changings concerning 'BCM2835_HAVE_LIBCAP'.

How to set up the baud rate for i2c-bus in Linux?

I have an ARM-computer which is based on the riko-3288 processor.
I also have the Ubuntu image for the device with a custom kernel (without the module system).
I am currently trying to set a baud rate of up to 100KHz for the i2c-bus.
I'm not an expert in Linux and I don't know what I have to do for it.
The i2c-bus works with higher baud rate, I think it's more than 1MHz.
I've read that I must write a command like this "dtparam=i2c_arm=on,i2c_arm=on_baudrate=100000" in the boot-loading file.
My boot-loading file bellow:
{boot-partition}/extlinux/extlinux.conf
label kernel-4.4
kernel /zImage
fdt /rk3288-miniarm.dtb
append earlyprintk console=tty1 console=ttyS2,115200n8 rw root=/dev/mmcblk1p7 rootfstype=ext4 init=/sbin/init
I tried past the command to the append string and I tried some different commands for it, but nothing works.
Could you tell me how I can change the baud rate for the i2c-bus?
P.S. And does someone know how to get the baud rate in the operation system?
I found the easy solution here.
http://www.chip-community.org/index.php/Troubleshooting#I2C_.2F_TWI_problems
For my cause:
sudo apt update
sudo apt install device-tree-compiler
sudo mount /dev/mmcblk1p6 /mnt # {boot-partition}
sudo cp /mnt/rk3288-miniarm.dtb /boot/rk3288-miniarm.dtb.bak
sudo fdtput --type u /mnt/rk3288-miniarm.dtb i2c4 clock-frequency 50000
sudo systemctl reboot

XRUSB raspberry pi

I'm working with a raspberry pi connected with xrusb to a controller using python.I use make file to Compile and install the common usb serial driver module and it works fine. After reboot i have problem. The driver is lost. I have to install the module again using this
modprobe usbserial
insmod ./xr_usb_serial_common.ko
Any idea?
Now my answer might be off because of the way you say "install the driver". I bet the make script most likely just loaded the driver just like you did via modprobe.
In order to get the module to be loaded at boot time, you need to tell udev what to load/do during bootup. And tell the kernel to load your driver.. Otherwise it assumes you don't want it to be loaded at boot time.
Either you can do a automatic module handling via:
#nano /etc/modules-load.d/usbserial.conf
usbserial
or, you can specify options:
#nano /etc/modprobe.d/usbserial.conf
options usbserial parameter_name=parameter_value
Here's some documentation on how this works:
http://man7.org/linux/man-pages/man5/modules-load.d.5.html
https://wiki.archlinux.org/index.php/kernel_modules
(Even if you're not running Arch on your RPi, they still have one of the best documentation websites for Linux out there. User friendly, in depth etc. So apply the information there to your Distribution, they should be very much the same this day and age)
I found maybe a temporary solution so i can finish my project and look for the best way later.
I make a script to run after reboot to load the driver.
use:
sudo crontab -e
then go to the bottom and write
#reboot bash /your/path/script/script.sh
`

How to install Wireshark on Linux and capture USB traffic?

I have encountered numerous problems in the installation of Wireshark, and the capture of USB traffic, especially due to user permissions.
How to install Wireshark on Linux and capture USB traffic?
Tested on Ubuntu 14.04, but probably works on other distributions since none of the steps are specific to Ubuntu.
The first time you follow the tutorial, do all the steps 1 -> 7.
When you restart your computer, you have to repeat steps 6 and 7 to see the USB interfaces in Wireshark.
Install Wireshark and libpcap:
sudo apt-get install wireshark libpcap0.8
For Debian, Ubuntu and other Debian derivatives, continue to step 3.
For other Linux based systems or other installation methods, see the Wireshark Wiki, then go to step 6.
Reconfigure wireshark to allow non-superusers to track packets:
sudo dpkg-reconfigure wireshark-common
Select <Yes> in the prompt
Add your username to the "wireshark" usergroup:
sudo usermod -a -G wireshark <your_username>
You can verify if it’s done correctly by displaying the groups your username is part of:
groups <your_username>
If not, you can add the group "wireshark" manually:
groupadd wireshark
And then add your username to the group (see above)
Important: Logout of your session, then log back in.
This step depends on the kernel version that is installed on your machine. To know the version of your kernel, type:
uname -r
For versions of the kernel prior to 2.6.21, if debugfs is not already mounted on /sys/kernel/debug, ensure that it is mounted there by issuing the following command:
sudo mount -t debugfs / /sys/kernel/debug
For kernel version 2.6.21 and later, load the loadable module usbmon in the Kernel:
`sudo modprobe usbmon`
See [Wireshark Wiki](https://wiki.wireshark.org/CaptureSetup/USB#Linux) for more information about this differentiation.
If the usbmon interfaces don't appear in Wireshark, look for interfaces using dumpcap (the command-line tool of Wireshark):
sudo dumpcap -D
You should see the usbmon* interfaces. Now display the permissions of the usbmon interfaces:
ls -l /dev/usbmon*
If the usbmon* files have 'crw-------', then it's normal that Wireshark cannot read them because it's not run as root. Do not execute wireshark in root mode, it may damage files. Instead, you can give it regular users privileges :
sudo setfacl -m u:$USER:r /dev/usbmon*
Now the usbmon interfaces should appear in Wireshark.
Sources:
https://wiki.wireshark.org/CaptureSetup/USB#Linux
https://wiki.wireshark.org/CaptureSetup/CapturePrivileges#Most_UNIXes
https://unix.stackexchange.com/questions/55722/wireshark-couldnt-run-usr-sbin-dumpcap-in-child-process
http://anonscm.debian.org/viewvc/collab-maint/ext-maint/wireshark/trunk/debian/README.Debian?view=markup

Resources