AnsweredAssumed Answered

Problem : SPI 4, 5 & 6 undeclared in stm32F4xx_spi.c

Question asked by rebeat.pete on Apr 17, 2013
Latest reply on Apr 17, 2013 by rebeat.pete
Hi everyone and thanks in advance for your help.

I'm trying to configure an SPI link between my STM32F4VG407 and a Shift register (M74HC595).

I wrote a simple code to start : 
//#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_spi.h"
#define SPI_COMMS           SPI1
#define PIN_SPI_COMMS_NCS   GPIO_Pin_4
#define PIN_SPI_COMMS_SCK   GPIO_Pin_5
void RCC_Configuration(void);
void GPIO_Configuration(void);
void SPI_Configuration(void);
int main(void)
void SPI_Configuration(void)
    SPI_InitTypeDef SPI_InitStructure;
    /* SPI1 configuration -------------------------------------------------*/
    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_2Edge;
    SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStructure.SPI_CRCPolynomial = 7;
    SPI_Init(SPI_COMMS, &SPI_InitStructure);
    /* Enable SPI_MASTER TXE interrupt */
    /* Enable SPI_MASTER */
void GPIO_Configuration(void)
    GPIO_InitTypeDef GPIO_InitStructure;
    // Enable SPI1 Pins Software Remapping //
    //GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);
    // Configure SPI_MASTER pins: SCK,MOSI //
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(PORT_SPI_COMMS, &GPIO_InitStructure);
void RCC_Configuration(void)
    // Enable GPIO clock //
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

When I build it, I have the following error : 

     [cc] D:\Squarp\Code_Ressources\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_spi.c: In function 'SPI_I2S_DeInit':
        [cc] D:\Squarp\Code_Ressources\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_spi.c:250:20: error: 'SPI4' undeclared (first use in this function)
        [cc] D:\Squarp\Code_Ressources\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_spi.c:257:20: error: 'SPI5' undeclared (first use in this function)
        [cc] D:\Squarp\Code_Ressources\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_spi.c:250:20: note: each undeclared identifier is reported only once for each function it appears in
        [cc] D:\Squarp\Code_Ressources\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_spi.c:266:17: error: 'SPI6' undeclared (first use in this function)

It seems like SPI4, 5 and 6 doesn't exist. I can find only SPI1, SPI2 & SPI3 when I read the datasheet of the STM32F4, so I'm surprised about it.
I'm using the "stm32f4xx_spi.c" source from "STM32F4xx_StdPeriph_Driver".
Here is the part of code from "stm32f4xx_spi.c" that lead to the failure : 
  * @brief  De-initialize the SPIx peripheral registers to their default reset values.
  * @param  SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2, 3, 4, 5 or 6
  *         in SPI mode or 2 or 3 in I2S mode.  
  * @note   The extended I2S blocks (ie. I2S2ext and I2S3ext blocks) are de-initialized
  *         when the relative I2S peripheral is de-initialized (the extended block's clock
  *         is managed by the I2S peripheral clock).
  * @retval None
void SPI_I2S_DeInit(SPI_TypeDef* SPIx)
  /* Check the parameters */
  if (SPIx == SPI1)
    /* Enable SPI1 reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
    /* Release SPI1 from reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
  else if (SPIx == SPI2)
    /* Enable SPI2 reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
    /* Release SPI2 from reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
  else if (SPIx == SPI3)
    /* Enable SPI3 reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
    /* Release SPI3 from reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
  else if (SPIx == SPI4)
    /* Enable SPI4 reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI4, ENABLE);
    /* Release SPI4 from reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI4, DISABLE);
  else if (SPIx == SPI5)
    /* Enable SPI5 reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI5, ENABLE);
    /* Release SPI5 from reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI5, DISABLE);
    if (SPIx == SPI6)
      /* Enable SPI6 reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI6, ENABLE);
      /* Release SPI6 from reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI6, DISABLE);

I tried to comment the concerned part and it does build properly but I have the feeling that it's not a good thing to do. 
Do someone know something about my issue? Thanks again.