Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino Plus 2 SPI Possible Speeds?


  • Please log in to reply
5 replies to this topic

#1 tonofsteel

tonofsteel

    Member

  • Members
  • PipPip
  • 14 posts

Posted 12 November 2014 - 01:29 AM

What are the possible speeds for the SPI port on the Netduino Plus 2?  I have read that you can use the .NET SPI config with any speed you want but internally the firmware will actually change this to a valid speed.  This valid speed is based on the internal STM32F4 SPI clock prescaler.

 

I have tried to read through the data sheets and look for any forum posts that reference how this would all tie together but I am still not clear on it all.

 

Even in the datasheet it says what the max rate for the SPI interface is but not much about what the valid ones are.  In the manual it said that it can have different values using the prescaler on fPCLK.

 

Is there any explanation for how this works or what the valid values are for this anywhere that does not involve reverse engineering the STM32 clock tree and .NET micro firmware?  Even if I calculate from the datasheets what the values are it is not clear what the Netduino firmware does when you select an arbitrary value for the SPI initialization, unless you are familiar with the firmware source I suppose.

 

I thought I read there were 8 or 12 valid prescaler values so this surely can't be too large of a table to include in any documentation? 

 



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 12 November 2014 - 04:20 PM

There are three SPI modules on Netduino Plus 2 microcontroller connected to two system busses: SPI1 on APB2, SPI2 and SPI3 on APB1. The bus frequencies are 42 MHz and 84 MHz and 3 bit prescaler is /2, /4, ... /256, which gives the following clock speeds:
Prescaler APB1      APB2
          42000000  84000000
    2     21000000  42000000 
    4     10500000  21000000
    8      5250000  10500000
   16      2625000   5250000
   32      1312500   2625000
   64       656250   1312500
  128       328125    656250
  256       164062    328125
I guess the firmware selects speed closest to the above values, the actual code is
    UINT32 clock = SYSTEM_APB2_CLOCK_HZ / 2000; // SPI1 on APB2
    if (Configuration.SPI_mod != 1) clock = SYSTEM_APB1_CLOCK_HZ / 2000; // SPI2/3 on APB1
    if (clock > Configuration.Clock_RateKHz << 3) {
        clock >>= 4;
        cr1 |= SPI_CR1_BR_2;
    }
    if (clock > Configuration.Clock_RateKHz << 1) {
        clock >>= 2;
        cr1 |= SPI_CR1_BR_1;
    }
    if (clock > Configuration.Clock_RateKHz) {
        cr1 |= SPI_CR1_BR_0;
    }
    spi->CR1 = cr1;
where SPI_CR_BR_0..2 are prescaler bits (or-ed to give 0..7).

#3 tonofsteel

tonofsteel

    Member

  • Members
  • PipPip
  • 14 posts

Posted 14 November 2014 - 03:50 AM

Thanks CW2!  This helps a lot.

 

I downloaded the manuals and data sheets for the STM32 and read through them again today.  I think part of the reason why I was getting confused is that from the clock tree diagrams it shows the AHB prescaler going to the APBx prescaler.  The AHB has /1, /2, ... /512 while the APBx prescaler has /1, /2, ... /16

 

I see the max frequencies you reference in the data sheet and manual as being the max allowed for each bus.

 

I am not sure how to correlate the chart going to 256 with the manual/data sheet, does it go to 256 due to a combination of setting the AHB and APBx clocks in combination?

 

Are the values you list just for setting the SPI_I2SPR prescaler register?  I don't remember seeing anything in the .NET micro framework for changing clock settings so I am guessing that if I wanted to change the APB clocks this would be a firmware extension.



#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 14 November 2014 - 10:46 AM

The prescaler values are just for the SPI modules, SPI_CR1 register bits BR0..BR2.



#5 tonofsteel

tonofsteel

    Member

  • Members
  • PipPip
  • 14 posts

Posted 15 November 2014 - 06:57 PM

Ah ok I think I see it now.  So if I understand this correctly I can change the other clock prescalers in the firmware and end up with slower speed options since they APBx clocks are running at max right now?



#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 18 November 2014 - 02:48 PM

Yes, you should be able to lower peripheral clock speed by adjusting the bus clocks frequencies. But, when you start playing with PLL settings, keep in mind that the USB FS module requires 48 MHz clock to operate properly.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.