machine.SPI(): add CS/NSS pin
It would be nice if CS/NSS pin for SPI could be driven by machine.SPI() itself. Manual toggling in user application slows it down.
mimxrt: Add the machine.spi() class to machine.
This class supports both Controller (Master) an Peripheral (Slave) mode. In order to support Peripheral mode, two keyword arguments have been added:
mode=SPI.CONTROLLER or SPI.PERIPHERAL or SPI.MASTER or SPI.SLAVE
timeout=xxxx Timeout to wait for a request. On timeout, an exception is raised
Further options:
drive=n with n being between 1 and 6 or PIN.POWER_1 to PIN.POWER_6. Since the pins used
by the SPI are fixed, no Pin settings can be made. Thus the drive option is added allowing
to control ringing and crosstalk on the connection.
gap=nnnnn The time between sent data items in a frame given in ns. Default is 2 clock cycles.
SPI device numbers start at 0, to comply with the Pin-Out of the Teensy boards.
With the configured clock frequency the fastest baud rate is 33MHz. For messages longer 16 bytes DMA is used. The class uses the existing frame work with extmod/machine_spi.c. I did not want to create a separate class for that.
There are still two dark spots on the implementation:
- Using DMA the data cache is disabled for the short transfer time. Otherwise data access was not reliable. Other less intrusive methods I tried did not work. Suggestions welcome.
- For short messages (<= 16 bytes) in slave mode of the MIMXRT1020_EVK board, write requests by a master are not detected and served in about 1 of 1000 cases, independent from baud rate and request frequency. DMA transfer is reliable. And no problem with the Teensy boards.