cancel
Showing results for 
Search instead for 
Did you mean: 

Change SPI baud rate on the fly: issue with DMA

Guillaume FERLIN
Associate II
Posted on October 09, 2017 at 11:04

Hi,

I am using SPI1 peripheral as master at 16 MHz on STM32L443, I can send and receive data correctly using DMA.

My application requires to speed down SPI to 1MHz during a moment so I changed SPI baud rate on the fly (by writing SPI_CR1 register). Using SPI polling API this is working fine but using DMA I noticed that SPI speed is still 16MHz.

I tried to:

- DeInit()/Init() DMA configuration

- Relink DMA to SPI

- DeInit()/Init() SPI with new baud rate

but result is the same.

For some reason it looks like first SPI configuration is permanent for DMA.

Did I miss something to reconfigure?

Thanks,

#dma #spi #baud-rate
8 REPLIES 8
Posted on October 09, 2017 at 11:16

Read out the SPI  registers before and after the change and compare (or post them).

JW

Posted on October 09, 2017 at 11:36

Only BR field from CR1 has changed, the register value changed from 0x0000034C to 0x0000036C. It looks consistent to change from prescaler 4 to 64.

Posted on October 09, 2017 at 11:47

And after this change, you see increase on the SPI clock  from 16MHz to 20MHz?

How exactly do you observe the respective SPIx_SCK pin? Which pin is it?

JW

Posted on October 09, 2017 at 11:57

Don't you have I2S enabled by any chance?

JW

Posted on October 09, 2017 at 12:02

After this change I see SPI clock updated correctly to 1MHz using HAL_SPI_Receive(), but is still 16MHz using HAL_SPI_Receive_DMA().

I probe SPI communication using logic analyzer.

Pin configuration is:

    PA8     ------> SPI1_NSS as GPIO

    PA5     ------> SPI1_SCK

    PA6     ------> SPI1_MISO

    PA7     ------> SPI1_MOSI
Posted on October 09, 2017 at 12:03

No

Posted on October 09, 2017 at 12:22

but is still 16MHz using HAL_SPI_Receive_DMA()

And *after* using HAL_SPI_Receive_DMA(), what's the content of SPI control registers?

JW

Posted on October 09, 2017 at 14:04

OK I found my mistake: SPI was configured to 1MHz then back to 16MHz after SPI Transmit function return. In DMA mode the function will return while transmission is on going. Waiting TX complete callback to reconfigure SPI back to 16MHz solve the issue.

Thanks,