rogerclarkmelbourne / Arduino_STM32

Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
Other
2.52k stars 1.26k forks source link

SPI in async mode will leave IRQ enabled #823

Closed mean00 closed 3 years ago

mean00 commented 3 years ago

When using the SPI IRQ in async mode, the SPI IRQ will be left enabled The dma_detach_function will not disable it, with comment / Don't use nvic_irq_disable()! Think about DMA2 channels 4 and 5. / The problem is when alternating between blocking SPI send and async SPI Send, the irq is left enabled and non managed interrupt will happen. Additionnaly if that happens the dma_irq_handler will loop as it does not clear the interrupt if no handler is present.

Crude hack is to do that in the SPI itself , i.e. in SPIClass::onTransmit & SPIClass::EventCallback i.e. explicitely call nvic_irq_disable.

It works, but is there a better way ?

(The same problem probably exists with transfer, but i'm only dealing with transmit)

stevstrong commented 3 years ago

Which device? F1 or F4? Do you have a simple example sketch which shows the problem?

mean00 commented 3 years ago

Hi I'm using the F1 (f103 actually) i can try creating a simple use case, it might take a bit of time as i'm using a very different environment than the arduino one, with a lot of dependencies.

But the gist of it is :

You'll run into the 1st problem, i.e. it loops in dma_irq_handler when the spi.dmaSend() is over because the nvic irq is still enabled. The asymetry in dma_detach_interrupt / dma_attach_interrupt is the root cause i believe

mean00 commented 3 years ago

Hi Please find attached a tar ball with 2 files :

Thank you

spiTest.tar.gz

mean00 commented 3 years ago

ping ?

stevstrong commented 3 years ago

I just committed a fix for this, I have tested and it works correctly now for me. Please check it and reopen the issue if the problem still persists.

mean00 commented 3 years ago

seems to work fine Thanks a lot!