tearing down spi connection before stop1 breaks flash write on stm32u375
That pretty much says it all. Any attempt to tear down the connection (disable spi, disable dma, etc) before (long before) stop1 causes flash write after (many instructions after) the wfi to fail with PGSERR error. Not tearing down the connection, flash write works, but standby doesn’t without additional work. To be concrete
dma3ChannelFreeI(spip->dmatx);
if (spip->state == SPI_READY) {
/* Just in case this has been called uncleanly.*/
(void) spi_lld_stop_abort(spip);
spip->spi->CFG1 &= ~(SPI_CFG1_RXDMAEN | SPI_CFG1_TXDMAEN);
spip->spi->CR1 &= ~SPI_CR1_SPE;
/* Releasing DMA channels.*/
dma3ChannelFreeI(spip->dmarx);
dma3ChannelFreeI(spip->dmatx);
Those two lines -- spip->spi→… are what break flash write. Clearly there is an undocumented interaction between peripherals and the clock and data transfer system, but the documentation for the part is shockingly incomplete on important details such as this.
Leaving those lines out means standby doesn’t work unless I hit spi with a reset hammer. Stop2 doesn’t work at all.
