LinuxCNC-RIO - RealtimeIO for LinuxCNC based on FPGA (ICE40 / ECP5)

More
1 year 10 months ago #316359 by Zayoo
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:
Code:
/*     interface: SPI */

INSERT CODE:
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:
Code:
int interface_init(void)  {      spi_init(); } /*    hal functions */


Find and add:
Code:
//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.
 
The following user(s) said Thank You: meister

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #316381 by meister
Many thanks Zayoo !

i have add the code to the dev branch for testing.

if you want to use it, you can add
Code:
"rpi5": true,
to your json config

like this:
Code:
{ "name": "IceShield", "description": "RIO-IceShield on Raspberry PI5", "boardcfg": "IceShield", "protocol": "SPI", "rpi5": true, ....
The following user(s) said Thank You: digiex_chris

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #316438 by Zayoo
I'm trying to get the gowin toolchain up and running on rpi5. It gives me an error when execute making all.
Code:
cnc@raspberrypi:~/riocore/Output/TangNano9K_spi_rpi5/Gateware$ make clean rm -rf rio.fs rio.json rio_pnr.json rio.tcl abc.history impl cnc@raspberrypi:~/riocore/Output/TangNano9K_spi_rpi5/Gateware$ make all gw_sh rio.tcl /opt/gowin/IDE/bin/gw_sh: 2: Syntax error: Unterminated quoted string make: *** [Makefile:34: impl/pnr/project.fs] Error 2 cnc@raspberrypi:~/riocore/Output/TangNano9K_spi_rpi5/Gateware$ 
I see you've already mentioned this error. I downloaded and cloned the dev version and it still doesn't work. Any tips...

I see there is another option 'generic_spi'. I will test that on rpi5 too just to get that toolchain working. I don't want to take the TN9 out of the device and program on windows anymore.

 

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #316451 by meister
on my system, the gowin makefile works fine, are you sure gowin is running on arm64 cpu's ?
The following user(s) said Thank You: Zayoo

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago - 1 year 10 months ago #316458 by MirkoCNC
Last edit: 1 year 10 months ago by MirkoCNC.

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #316459 by MirkoCNC
@ Zayoo: I have the same problem with the toolchain on the Pi5.

However, you can use the IDE on a Windows PC. Just copy the files from Gateware and open the project file with the IDE rio.gprj. 

By the way, I am wondering what the maximum SPI speed on the pin headers of the Raspberary looks like to ensure transfer without errors. These are not suitable for very high frequency. Hence, even if the hardware can run very high frequency, the pin headers are the limiting factor.

What is the required SPI frequency to run the Iceshield?

Please Log in or Create an account to join the conversation.

Time to create page: 0.246 seconds
Powered by Kunena Forum