8 Replies Latest reply on Mar 21, 2017 1:29 PM by Clive One

    SPI speed calculation ?

    h.rick

      Hello everyone,

       

      I have a calculation for SPI :

      Please correct  me :

      hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; //72/8 = 9MHz/ 9 Mbits/S

       

      Is that right ?

      From my STM32CubeMX configuration, PCLK1 = 36 MHz and PCLK1 = 72MHz,

       

      Thanks

        • Re: SPI speed calculation ?
          h.rick

          and for SDIO :

          /* SDIO Data Transfer Frequency */
          /* SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */
          #define SDIO_TRANSFER_CLK_DIV ((uint8_t)0x5)  // ==72/(5+2) = 10.28MHz ?

           

          I have two SDIO clock value on STM32CubeMX, 36MHz and 72MHz, which one is the right one ?

            • Re: SPI speed calculation ?
              Clive One

              The Reference Manual for the part describes the clocking. The SDIO is connected to the AHB, SDIOCLK is nominally 72 MHz

               

              http://www.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/… 

               

              Read The Fine Manual - You might then understand how the part is supposed to work.

              1 of 1 people found this helpful
                • Re: SPI speed calculation ?
                  h.rick

                  So SPI1 based on 36MHz correct?

                    • Re: SPI speed calculation ?
                      Clive One

                      Isn't SPI1 on the APB2 running at 72 MHz?

                        • Re: SPI speed calculation ?
                          h.rick

                          How do you know that from datasheet ?

                            • Re: SPI speed calculation ?
                              Clive One

                              There are several ways to make this determination.

                               

                              The APB clock enable/reset registers in the RCC provide the peripheral/bus relationship

                               

                              The Datasheet has a big graphical diagram, this likely isn't the part you are using, but is illustrative

                               

                              "Figure 1. STM32F103xx performance line block diagram"

                              http://www.st.com/content/ccc/resource/technical/document/datasheet/33/d4/6f/1d/df/0b/4c/6d/CD00161566.pdf/files/CD00161… 

                               

                               

                              The SPL code you use to enable them is also a big tell

                               

                              /**
                                * @brief  Enables or disables the High Speed APB (APB2) peripheral clock.
                                * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
                                *   This parameter can be any combination of the following values:
                                *     @arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB,
                                *          RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,
                                *          RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1,
                                *          RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1,
                                *          RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3,
                                *          RCC_APB2Periph_TIM15, RCC_APB2Periph_TIM16, RCC_APB2Periph_TIM17,
                                *          RCC_APB2Periph_TIM9, RCC_APB2Periph_TIM10, RCC_APB2Periph_TIM11
                                * @param  NewState: new state of the specified peripheral clock.
                                *   This parameter can be: ENABLE or DISABLE.
                                * @retval None
                                */
                              void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
                              {
                                /* Check the parameters */
                                assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
                                assert_param(IS_FUNCTIONAL_STATE(NewState));
                                if (NewState != DISABLE)
                                {
                                  RCC->APB2ENR |= RCC_APB2Periph;
                                }
                                else
                                {
                                  RCC->APB2ENR &= ~RCC_APB2Periph;
                                }
                              }

                               

                              The part uses synchronous logic, the internals of the peripheral are clocked by the bus it is attached too. So if USART1 is on APB2, the baud clock divides down from that clock, nominally 72 MHz, where as USART2 and USART3 on APB1 would clock from that, nominally 36 MHz

                        • Re: SPI speed calculation ?
                          h.rick

                          How about description for SPI and source clock for it ? where can I find it ?

                          This one :

                          7.3.7 APB2 peripheral clock enable register (RCC_APB2ENR) page 109 on the reference ?

                          thanks

                      • Re: SPI speed calculation ?
                        Clive One

                        The source clock tends to depend on which APB or AHB the peripheral lives on. An SPI on APB1 on an F1 is going to typically divide down from 36 MHz, whereas one on APB2 will come from 72 MHz.

                         

                        There is a Clock Tree diagram in the Reference Manual that is somewhat illuminating in this regard.

                        1 of 1 people found this helpful