Hi,
I have try the https://wiki.radxa.com/Rockpi4/dev/libmraa
This works : mraa-gpio list
But i can’t initialize SPI.
On DietPi with buster.
Do you have any advize ?
Thanks a lot.
Rock PI 4C Failed to initialize SPI
Hello! I have reproduced your question.
This seems to be the reason for the inconsistent image configuration.
When I open spi1 in Dietpi, the device is /dev/spidev1.0,
but mraa needs to identify is /dev/spidev32765.0.
New Ihave found the solution as follow:
When using spi 1:
1.Modify the /boot/armbianEnv.txt
verbosity=4
bootlogo=false
overlay_prefix=rockchip
fdtfile=rockchip/rk3399-rock-pi-4b.dtb
rootdev=UUID=dfa3ab95-cede-4159-9841-4e31bafe853e
overlays=spi-spidev
param_spidev_spi_bus=1
rootfstype=ext4
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
docker_optimizations=off
2.Create a soft link
ln -sf /dev/spidev1.0 /dev/spidev32765.0
3.Modify spi.c
/* SPI declaration */
#define SPI_BUS 1
4.Compilation and run
gcc spi.c -o spi -lmraa
./spi
0xaa
0xaa
0xaa
when using spi 2, it must be
overlays=spi-spidev
param_spidev_spi_bus=2
ln -sf /dev/spidev2.0 /dev/spidev32766.0
/* SPI declaration */
#define SPI_BUS 0
Thank you for your help, but have i make a wrong thing :
root@DietPi:/# nano /boot/armbianEnv.txt
root@DietPi:/# ln -sf /dev/spidev1.0 /dev/spidev32765.0
root@DietPi:/# ln -sf /dev/spidev2.0 /dev/spidev32766.0
root@DietPi:/# nano spi.c
root@DietPi:/# gcc spi.c -o spi -lmraa
root@DietPi:/# ./spi
Failed to initialize SPI
root@DietPi:/# nano spi.c
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
/* mraa header */
#include “mraa/spi.h”
/* SPI declaration */
#define SPI_BUS 1
/* SPI frequency in Hz /
#define SPI_FREQ 400000
int
main(int argc, char* argv)
{
mraa_result_t status = MRAA_SUCCESS;
mraa_spi_context spi;
int i, j;
/* initialize mraa for the platform (not needed most of the times) */
mraa_init();
//! [Interesting]
/* initialize SPI bus */
spi = mraa_spi_init(SPI_BUS);
if (spi == NULL) {
fprintf(stderr, "Failed to initialize SPI\n");
mraa_deinit();
return EXIT_FAILURE;
}
/* set SPI frequency */
status = mraa_spi_frequency(spi, SPI_FREQ);
if (status != MRAA_SUCCESS)
goto err_exit;
/* set big endian mode */
status = mraa_spi_lsbmode(spi, 0);
if (status != MRAA_SUCCESS) {
goto err_exit;
}
while(1) {
printf("0x%x\n",mraa_spi_write(spi, 0xaa));
}
err_exit:
mraa_result_print(status);
/* stop spi */
mraa_spi_stop(spi);
/* deinitialize mraa for the platform (not needed most of the times) */
mraa_deinit();
return EXIT_FAILURE;
}
root@DietPi:/# nano /boot/armbianEnv.txt
verbosity=4
bootlogo=false
overlay_prefix=rockchip
fdtfile=rockchip/rk3399-rock-pi-4b.dtb
rootdev=UUID=dfa3ab95-cede-4159-9841-4e31bafe853e
overlays=spi-spidev
param_spidev_spi_bus=1
overlays=spi-spidev
param_spidev_spi_bus=2
rootfstype=ext4
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
docker_optimizations=off
console=serial
root@localhost:/# cat boot/hw_intfc.conf
Hardware Interface Config
For more details, check https://wiki.radxa.com/Rockpi4/hardware/devtree_overlays.
Set “on” to enable the optional hardware interfaces while set “off” to disable.
intfc:pwm0=off
intfc:pwm1=off
intfc:uart2=off
intfc:uart4=off
intfc:spi1=on
intfc:spi2=on
intfc:i2c2=off
intfc:i2c6=off
intfc:i2c7=off
Devicetree Overlay Enable, uncomment to enable .dtbo under /boot/overlays/.
EEPROM on I2C2
#intfc:dtoverlay=at24c02
Serial console on UART2
#intfc:dtoverlay=console-on-ttyS2
Serial console on UART4
#intfc:dtoverlay=console-on-ttyS4
Dummy spi device on SPI1 for test. Need set: intfc:spi1=on
intfc:dtoverlay=devspi1
Dummy spi device on SPI2 for test. Need set: intfc:spi2=on
intfc:dtoverlay=devspi2
PCIE running on GEN2 mode
#intfc:dtoverlay=pcie-gen2
ALLNET 4duino B10/B11 two-coloe-led module on 40-pin Header Pin#35 and Pin#36
#intfc:dtoverlay=two-color-led
waveshare 3.5inch lcd (B v2) on SPI1. Need set: intfc:uart4=off intfc:spi1=on
#intfc:dtoverlay=spi1-waveshare35b-v2
waveshare 3.5inch lcd © on SPI1. Need set: intfc:uart4=off intfc:spi1=on
#intfc:dtoverlay=spi1-waveshare35c
spi flash on SPI1. Need set: intfc:uart4=off intfc:spi1=on
#intfc:dtoverlay=spi1-flash
#hifiberry-dac
#intfc:dtoverlay=hifiberry-dac
#hifiberry-dacplus on I2C7. Need set: intfc:i2c7=on
#intfc:dtoverlay=hifiberry-dacplus
#enable raspberry pi official 7 inch LCD support
#intfc:dtoverlay=raspberrypi-7-inch-lcd
#enable gt9xx touchpanel
#intfc:dtoverlay=gt9xx
setting cpu frequency over-2GHz
#intfc:dtoverlay=cpufreq
Add imx219 camera module support. Need disabled ov5647 camera module.
#intfc:dtoverlay=imx219
Add ov5647 camera module support. Need disabled imx219 camera module.
#intfc:dtoverlay=ov5647
Add w1 on GPIO4_D6 to support devices such as DS18B20.
#intfc:dtoverlay=w1-gpio4-30
can function of waveshare rs485 can hat on SPI1. Need set: intfc:uart4=off intfc:spi1=on
#intfc:dtoverlay=spi1-mcp2515-can0
If you set overlay like this, only spi bus 2 is enabled.
Can you remove these two lines and test SPI-1 again?
overlays=spi-spidev
param_spidev_spi_bus=2
Thanks, this is good now when i make this :
root@DietPi:/# ls dev/spi*
dev/spidev1.0
But, i always have :
root@DietPi:/# ./spi
Failed to initialize SPI
root@DietPi:/# ./a.out
Failed to initialize SPI
hello!
When you run this commands:
sudo apt-get install -y rockchip-overlay && sudo apt-get install -y rockpi4-dtbo
the overlay config file /boot/hw_intfc.conf will be generated, but it just can be use in Radxa RockPi’s image like ubuntu system and debian system.
DietPi is a Armbian system, it’s overlay config file is /boot/armbianEnv.txt.
And these two spi devices cannot be used at the same time.
Ok, what can i do for initialize spi in armbian/debian OS ?
You can like this to initialize spi device.
Thanks, i will try this. Another question, if i have a software that use spi, do i have to make soft link, or can i use SPI 1.0 ?
Does your software require the use of libmraa?
If not, you can try no to make soft link, to test you conjecture.
I don’t think it use it. Many thanks, i try this.
It seems the application works whith spidev1.0
But now, i have to upsize the buffer of this spidev
i have this :
déc. 17 13:10:26 DietPi DuetControlServer[3093]: [warn] Kernel SPI buffer size i
s smaller than RepRapFirmware buffer size (4096 configured vs 8192 required)
Can you tell me how to do with dietpi ?
Thanks.
Hi, did you ever figure out how to increase the buffer size? I’ve stumble on the same problem.
No, i don’t. let me know if you have a solution.
With this approach and the /boot/armbianEnv.txt file - can I have both SPI 1 and 2 working?
Hello, i am also wondering about enabling both SPI as i try get a 2x CAN-HATMCP2515 module to work with the RockPi 4se board.