stm32f0xx-hal
stm32f0xx-hal copied to clipboard
How do I run an SPI controller in slave mode?
I am currently working on a design involving an STM32F042 microcontroller that involves the use of both SPI controllers, one operating as a master and one operating as a slave. While this HAL does offer facilities for driving an SPI controller in master mode, I do not see any code for abstracting over a slave controller. How would I go about that, if I were to use this library to handle other aspects of the microcontroller?
@robbie01 👋
As you've noticed there's currently no code to implement the slave part. My SPI slave knowledge is unfortunately rather limited so I'm not sure that we already have the necessary parts in embedded-hal
to produce a generic abstraction. That would problably the first thing to check.
The second thing would be the slave implementation. We can probably refactor some of the initialisation code of the master out to more generic functions and then have a separate init function for the slave implementation like spiX_slave()
which provides either a generic abstraction or a custom one (depending on the outcome of the first step above) to receive data a word at a time.
The third step would probably be making it really efficient by using a DMAed buffer.
If you feel comfortable taking a stab at that I'd be happy to support you along the way.