Configuring SPI on STM32F4

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Configuring SPI on STM32F4

Post by hkerner »

Hi there,

I'm using an STM32F417 and trying to configure SPI2. From the demos I have deduced that by default CPHA=0, CPOL=0, and MSB first are configured (please correct me if I''m wrong) but I still don't understand how to configure the baud rate. Previously using libopencm3 I set the baud rate to SPI_CR1_BAUDRATE_DIV_64 with a prescaler of 0xff. Can someone please help me with what is needed in the SPIConfig struct for this?

Thank you in advance!
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: Configuring SPI on STM32F4

Post by hkerner »

Would I just pass in SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_I2SPR_I2SDIV ?
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: Configuring SPI on STM32F4

Post by hkerner »

I also need 8-bit DFF, but it looks like this is also default? i.e. including SPI_CR1_DFF in the config would result in 16bit? Thanks so much!!!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Configuring SPI on STM32F4

Post by Giovanni »

Hi,

The mapping in the configuration structure is exactly equal to the CR1 SPI register as documented in the Reference Manual. You must use the bits exactly as documented.

So default is 8 bits, DFF is 16 bits and so on.

I2S-related bits MUST not be used.

Giovanni
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: Configuring SPI on STM32F4

Post by hkerner »

Hi Giovanni,

Thanks for the response. I don't see where this is documented in the reference manual -- could you please point me there? I am looking here: http://chibios.sourceforge.net/html/group___s_p_i.html

Thanks so much!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Configuring SPI on STM32F4

Post by Giovanni »

Ah sorry, I was not clear enough in my answer.

You have to look into the STM32F4 Reference Manual, SPI chapter, CR1 register :)

Many drivers have register images into their configuration structure and must be setup according to the ST documentation.

Giovanni
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: Configuring SPI on STM32F4

Post by hkerner »

Found it! Thanks a ton
Post Reply