There are no shared resources between threads and they won't work unless I reduce the priority of one of them. I also read through some code and it looks to me as though SPI1 and SPI2 are already configured to use different DMA channels so perhaps the entire DMA controller is being monopolized...?
The following is how I am reading via SPI (similar for writing):
Code: Select all
int mpu_readfromspi(SPIDriver *spip, uint8_t headerLength, const uint8_t *headerBuffer, uint8_t readlength, uint8_t *readBuffer){
spiAcquireBus(spip); /* Acquire ownership of the bus. */
spiSelect(spip); /* Slave Select assertion. */
spiSend(spip, headerLength, headerBuffer); /* Slave Register select */
spiReceive(spip, readlength, readBuffer); /* Read operation. */
spiUnselect(spip); /* Slave Select de-assertion. */
spiReleaseBus(spip); /* Ownership release. */
return MPU_SUCCESS;
}
Code: Select all
int dw_readfromspi(SPIDriver *spip, uint16 headerLength, const uint8 *headerBuffer, uint32 readlength, uint8 *readBuffer){
spiAcquireBus(spip); /* Acquire ownership of the bus. */
spiSelect(spip); /* Slave Select assertion. */
spiSend(spip, headerLength, headerBuffer); /* Slave Register select */
spiReceive(spip, readlength, readBuffer); /* Read operation. */
spiUnselect(spip); /* Slave Select de-assertion. */
spiReleaseBus(spip); /* Ownership release. */
return DWT_SUCCESS;
}
I have read some years old comments about also doing spiStart and spiStop within each SPI routine.
I can implement that if it is necessary but I have to rewrite a bunch of code to pass in the speed configuration. I have a different SPI speed configurations for device initialization and main loop. In both cases the same SPI routine is used and I just call an SPI init function to switch the speeds.
All I know about the DMA is that there are two controllers with 8 channels each (stm32f407).
So I am not entirely sure if I should be trying to configure each SPI to use a non-conflicting DMA controller or channel or be trying to make them play nice on the same channel/controller.
I will be moving on to integrating a third device that is on SPI3 so I assume that has to be considered as well.
Am I at least thinking in the right direction here? It is correct there will be DMA collisions if I do not do something about it? And that I need to call spiStop to free up the shared resources?
Also, is avoiding the use of DMA an option (some of the forum thread comments I have read in this regard are years old)?
Cheers
Alex