Zynq SPI slave stepper motor driver
The Linux SPI slave device driver is to enable user access to SPI slave stepper motor FPGA design in my other post http://souktha.github.io/hardware/zybo-spi-stepper . This is the software part of that implementation on the Zybo Zynq7000. I reuse the original SPI slave I wrote earlier and expand its functionality a little bit more so that I can send the step count to the stepper motor.
SPI slave driver implementation
I try to make it as simple as possible so that writing and reading the SPI interface does not require to have any application be written for it. I choose to use the proc file system as the access mechanism since it will work out well with just shell script.
All that is needed for this task is adding proc file system to the driver and provide the entry points where the step count can be written and where the status can be read. My interface will have /proc/stepper/steps for writing step counts and /proc/stepper/status for reading the status of the motor.
In summary, for this design:
-
Add proc FS for user acess to the driver to allow writing of step count and reading stepper status.
Add proc file write handler for writing stepper count.
Add proc file read handler for reading stepper status.
On handling the step count write operation, the proc write handler takes the step count input from user and send it out to Zynq SPI master (PS) to the SPI slave stepper hardware (PL).
I use Linux sequential file as an interface for reading the status of the stepper motor operation. This is to capitalize on the existing proc file interface.
Testing the design with the SPI slave driver
The SPI slave device has to brought in to existence first before loading the SPI slave driver. This is simply done using cat the bitstream to Xilinx PL configuration device (line 1). Once the FPGA bitstrem is loaded to the Zynq, the SPI slave can be loaded (line 2). On loading of the SPI slave driver, the Zynq SPI master probes the SPI device attached to SPI0 using the read id (0x1d) command. My SPI slave FPGA responds to the read ID command with its ID, 0xa5. This is indicated that the device that SPI slave is written for existed. Once the SPI slave stepper motor driver is detected, the proc/stepper file is then created and become accessible to user. This is when the step count and status can be read. Positive step count is for stepping in forward direction while the negative count is for the opposite direction. The step count is 8bit signed integer. The motor status for running or idle is returned in the LSB of the read status (0xea) command.
Conclusion
This simple exercise instantiates the SPI slave device on the programmable logic side of the Zynq7000 having the Linux SPI slave driver works in conjunction with that design. It is complete hardware and software interface for the simple SPI slave stepper motor driver.