cancel
Showing results for 
Search instead for 
Did you mean: 

F4 Discovery Max SPI Speed

jvaldez
Associate
Posted on August 11, 2012 at 02:46

Hello,

1. What is the maximum SPI speed I am suppose to achieve with the 8MHz HSE?

2. I would like to achieve at least 25MHz, what would it take to achieve that both code and HW? Currently with my code below I get 13MHz.

void configure_spi_r(void)

{

  //Init GPIO structure 

  GPIO_InitTypeDef GPIO_InitStructure;

  //Init SPI structure 

  SPI_InitTypeDef SPI_InitStructure; 

  

   //Enable SPI clocks  

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE); 

  

  /* Enable GPIO clocks */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

  

  //Set GPIOs 

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; 

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; 

  GPIO_Init(GPIOA, &GPIO_InitStructure); 

  /* Connect SPI pins to AF5 */  

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1); //CLK

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1); //MOSI

  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 

  SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 

  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; 

  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; 

  SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; 

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; 

  SPI_InitStructure.SPI_CRCPolynomial = 7; 

  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; 

  

  //SPI1- for CLK, DATA, CS(DIR) 

  SPI_Init(SPI1,&SPI_InitStructure); 

  SPI_SSOutputCmd(SPI1,ENABLE); 

  SPI_Cmd(SPI1,ENABLE); 

}
2 REPLIES 2
zaurozavr
Associate II
Posted on August 11, 2012 at 03:32

1. SPI clock depends on APB clock. In case of SPI1  max APB1 clock is sysclock/2, so with 168MHz MCU APB1 gets 84 MHz. Max SPI clock in theory is APB/2 but due to inner MCU structure ST promised max SPI clock 37.5 MHz only.

 

2. So there is no problem to achieve 25Mhz. But it does not assume you'll get (37.5/8) Megabytes per second throughput. To get closer to max possible Mbps ratio use 16 bit transfer (if possible), unfold the transmission loop, use direct register  access instead of functions. 

3. In your initialization NSS and MISO do not used as AF pins, so it is better to leave them for a general use.

jvaldez
Associate
Posted on August 13, 2012 at 18:22

Thank you for the information. I added code below and now get 27MHz. 

RCC_PCLK2Config(RCC_HCLK_Div1); //DEFAULT WAS Div2