cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411 which APBx clock for each SPIx and why no prescaler setup in CubeMX?

eBirdman
Senior

Hello, I searched all the documentation for STM32F4xx MCUs to find the proper source of the clock for each of SPIx peripherals - no result. Please somebody point to a proper document/chapter/page ...

All chapters on SPI in the reference manual talk about "peripheral clock" Pclk without specifying which one APBx is used for clocking each SPIx.

Also related to the above : the manual talks about prescalers for SPI clocking, yet, CubeMX does not provide option to setup prescaler for SPI2. Looks like some of SPIs do have prescaler but others don't . I can add manually the prescaler value into the MX-generated SPI setup but may be I am missing something in CubeMX SPI or clocks department ?

Please help.

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

I've created a new CubeMX project for F411 and it allows to select SPI prescalers.

If you set different APB1 and APB2 prescalers on the Clock config view, you will easily see on which APB is each SPI. For example SPI2 is on APB1 and SPI1 is on APB2.

Not very intuitive, but not too hard when you get used to it.

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

I've created a new CubeMX project for F411 and it allows to select SPI prescalers.

If you set different APB1 and APB2 prescalers on the Clock config view, you will easily see on which APB is each SPI. For example SPI2 is on APB1 and SPI1 is on APB2.

Not very intuitive, but not too hard when you get used to it.

eBirdman
Senior

Thank you Pavel. Indeed your suggested trick gives a hint to what APB bus is used for each SPI.

Normally user would expect the datasheet or a User Manual to tell explicitly what bus is clocking what peripheral if this clocking is in hardware. Meanwhile your hint is helpful.

As for the second part I found my mistake. I configured the SPI2 in the slave mode. But I forgot that in the Slave mode SPI is clocked externally by SPI_SCK clock from the Master - that's why CubeMX does not show setup for the SPI clock in this mode.

0693W00000JM7N2QAL.png0693W00000JM7O0QAL.png0693W00000JM7OFQA1.png 

Even if in slave mode you may not need any particular APB clock to shift the data in, at high SKC-to-APB-clock ratios you won't be able to read the incoming data timely.

JW

eBirdman
Senior

Thank you Jan, your 1st screenshot from the datasheet is the direct answer. I didn't check the MCU block diagram as I didn't expect such level of details for each peripheral. Apparently I underestimated the level of details in STM docs (pun intended). This diagram shows all the clock sources for all the peripherals. Very good.

As for the 2nd screenshot from user manual - I would never expect to look for the peripheral clock sources in the memory map section. Sure, for those who know how MCU is built and how components interconnect internally , this might be obvious, but the app developer who only cares 'bout how to use the features for his application , he will check the peripheral-related chapters to learn how to use that peripheral. For the details of SPI I am reading "SPI" chapter in both datasheet and user manual, not the unrelated "memory map" chapter. I'd hope some day STM will add to their peripheral-specific chapter the table showing the clock source for each peripheral.

As for the 3rd screenshot - I saw that when I did research - it does not answer the posted question, which APB clocks which SPI.

Again thank you very much for the block diagram - very helpful.

Sincerely

Vlad