cancel
Showing results for 
Search instead for 
Did you mean: 

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

michaelmichael9137
Associate II
Posted on April 17, 2013 at 15:38

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 PORT_SPI_COMMS GPIOA
#define PIN_SPI_COMMS_NCS GPIO_Pin_4
#define PIN_SPI_COMMS_SCK GPIO_Pin_5
#define PIN_SPI_COMMS_MISO GPIO_Pin_6
#define PIN_SPI_COMMS_MOSI GPIO_Pin_7
void
RCC_Configuration(
void
);
void
GPIO_Configuration(
void
);
void
SPI_Configuration(
void
);
int
main(
void
)
{
GPIO_Configuration();
SPI_Configuration();
RCC_Configuration();
for
(;;){
SPI_I2S_SendData(SPI1,0xAAAA);
}
}
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 */
SPI_I2S_ITConfig(SPI_COMMS, SPI_I2S_IT_TXE, ENABLE);
/* Enable SPI_MASTER */
SPI_Cmd(SPI_COMMS, ENABLE);
}
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_Pin = PIN_SPI_COMMS_SCK | PIN_SPI_COMMS_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 */
assert_param(IS_SPI_ALL_PERIPH(SPIx));
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);
}
else
{
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. #spi-problem-stm32
6 REPLIES 6
frankmeyer9
Associate II
Posted on April 17, 2013 at 15:53

My versions of stm32f4xx_spi.c only know of 3 SPI interfaces - SPI1 to SPI3.

Meaning both the STM32F4-Discovery firmware package and the STM32F4_DSP_Lib package.

Posted on April 17, 2013 at 15:54

Do someone know something about my issue?

Yeah, you're mixing and matching different firmware libraries releases, presumably because you don't have the Include Paths set up coherently, or the tool chain has an older preinstalled library whose includes are taking precedence.

The STM32F427 has SPI4,5,6, it's the die shrunk 2MB FLASH part.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 17, 2013 at 15:55

Meaning both the STM32F4-Discovery firmware package and the STM32F4_DSP_Lib package.

You want the V1.1.0 DSP package.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelmichael9137
Associate II
Posted on April 17, 2013 at 16:05

Thanks for the hint, I'm surprised though because I downloaded the pack from ST website, and it's supposed to be the last version of the DSP_Periphs.(just checked)

Thank you again.

Posted on April 17, 2013 at 16:35

I'm surprised though because I downloaded the pack from ST website, and it's supposed to be the last version of the DSP_Periphs.

The issue isn't with the library, it's with your tool chain, project or configuration thereof.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelmichael9137
Associate II
Posted on April 17, 2013 at 17:13

Ok I solved the problem by using the provided CooCox IDE libraries for STM32F4. When I check in the ''stm32F4xx_spi.c'', the previous problematic lines disapeared. I tried to change my Toolchain at first but nothing happened. Seems that my inc and src files weren't up to date.

Thank you very much clive for your help.