Regarding rpi5 I swap to riocore so there is some changes.
For old rio follow instructions on rio
page 11
Here is changes for riocore:
I have a raspberry pi5 and this is the code of how I started the SPI communication of the RPI5 - TangNano9K. (Not yet machine tested)
OS:
In /boot/broadcom/config.txt check is SPI is enabled (reboot if not)
# uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
In /dev/
Check do you have listed spidev0.0, should be!
Generate output files as for raspberry pi4. When you have generated them, find the file 'riocomp.c' and open it. In general, you need to find and replace the code responsible for rpi4 SPI communication. You need to swap approximately 4200 lines of code with around 60 lines, swap
FROM:
INSERT CODE:
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
int spifd;
static uint8_t mode = SPI_MODE_0;
static uint8_t bits = 8;
static uint32_t speed = 1500000;
int spi_init(void) {
rtapi_print("Info: Initialize SPI5 connection\n");
spifd = open("/dev/spidev0.0", O_RDWR);
if (spifd < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,"Failed to open SPI device\n");
return -1;
}
// Set SPI mode
if (ioctl(spifd, SPI_IOC_WR_MODE, &mode) == -1) {
rtapi_print_msg(RTAPI_MSG_ERR,"Failed to set SPI mode\n");
close(spifd);
return -1;
}
// Set bits per word
if (ioctl(spifd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1) {
rtapi_print_msg(RTAPI_MSG_ERR,"Failed to set bits per word\n");
close(spifd);
return -1;
}
// Set max speed
if (ioctl(spifd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) == -1) {
rtapi_print_msg(RTAPI_MSG_ERR,"Failed to set max speed\n");
close(spifd);
return -1;
}
}
int spi_trx(uint8_t *txBuffer, uint8_t *rxBuffer, uint16_t size) {
struct spi_ioc_transfer tr = {
.tx_buf = (uint64_t)txBuffer,
.rx_buf = (uint64_t)rxBuffer,
.len = size,
.speed_hz = speed,
.delay_usecs = 0,
.bits_per_word = bits,
};
// Perform SPI transfer
if (ioctl(spifd, SPI_IOC_MESSAGE(1), &tr) == -1) {
rtapi_print_msg(RTAPI_MSG_ERR,"Failed to perform SPI transfer\n");
}
return 1;
}
TO:
int interface_init(void) {
spi_init();
}
/*
hal functions
*/
Find and add:
//ADD to rtapi_app_exit ->> close(spifd);
void rtapi_app_exit(void) {
close(spifd);
hal_exit(comp_id);
}
And that's all. This procedure with 'riocomp.c' must be repeated every time the output files are regenerated.