The spidev_test.c program from the Exploring BeagleBone by Derek Molloy (chp08) tests the SPI port by setting the SPI parameters and then writing out a test block. The text diagnostics I’ve added show what the macro was that is sent as part of the ioctl call. Trying to break down the macro through multiple files turned into a dead end and I’m not exactly sure what the 32 bit word means other than byte count and I believe message type.
The program starts out by sending 6 ioctl messages that configure mode, size and speed.
Here’s the call that returns the 0x4006B00 and below the result of the message.
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
debian@ebb:~/exploringBB/chp08/spi/spidev_test$ ./spidev_test
SPI_IOC_WR_MODE = 40016B01
SPI_IOC_RD_MODE = 80016B01
SPI_IOC_WR_BITS_PER_WORD = 40016B03
SPI_IOC_RD_BITS_PER_WORD = 80016B03
SPI_IOC_WR_MAX_SPEED_HZ = 40046B04
SPI_IOC_RD_MAX_SPEED_HZ = 80046B04
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
SPI_IOC_MESSAGE(1) = 40206B00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00
Now. Switch over to a part of the DisplaySPI program in the Lazarus Free Pascal pxl library the function call looks the same as do the SPI initialization calls to fpioctl. They are in a different order from the C program.
Res := fpioctl(FHandle, SPI_IOC_MESSAGE(1), @Data);
Six of the ioctl function calls do not return an error. The main one to send data has the correct
SPI_IOC_MESSAGE(1) value yet it fails.
debian@ebb:~/lazarus/pxl/Samples/FreePascal/SingleBoard/Generic/DisplaySPI$ ./DisplaySPI
UpdateFrequency – SPI_IOC_WR_MAX_SPEED_HZ is 40046B04
UpdateFrequency – SPI_IOC_RD_MAX_SPEED_HZ is 80046B04
UpdateBitsPerWord – SPI_IOC_WR_BITS_PER_WORD is 40016B03
UpdateBitsPerWord – SPI_IOC_RD_BITS_PER_WORD is 80016B03
UpdateRWMode – SPI_IOC_WR_MODE is 40016B01
UpdateRWMode – SPI_IOC_RD_MODE is 80016B01
SPI_IOC_MESSAGE(1) is 40206B00
An unhandled exception occurred at $000330A8:
ESysfsSPITransfer: Cannot transfer <1> data byte(s) through SPI bus.
$000330A8 TSYSFSSPI__TRANSFER, line 263 of /home/debian/lazarus/pxl/Source/PXL.Sysfs.SPI.pas
$00032F54 TSYSFSSPI__WRITE, line 241 of /home/debian/lazarus/pxl/Source/PXL.Sysfs.SPI.pas
Is there some documentation out there on the ioctl call and what the actual parameter means in detail with respect to the BeagleBone processor? The man page states that command is specific to the device.
https://man7.org/linux/man-pages/man2/ioctl.2.html
I’m having trouble figuring out why it fails or more specifically where to look next. I can’t step the machine code past the ioctl system call so I’d like to know what is actually going on inside the OS with this call inside the Beagle.
Thanks
John
“ELS! Nothing else works as well for your Lathe”
Automation Artisans Inc.
www dot autoartisans dot com