cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Bug with SPI1

belmondo2002us
Associate
Posted on September 23, 2012 at 22:17

I am having a strange issue. I am using FatFS and I have setup the SPI1 with

CS - PB14

CK - PA5

MISO - PA6

MOSI - PA7

When I just use the SD card interface, everything works well. I am getting the proper SPI signals and protocol. As soon as I add GPIO PE3 and enable it, then my SPI1 MISO signal goes all over. I even removed the SD card interface to see if MISO was staying High. And it does when the PE3 is not enable but as soon as PE3 is enabled, MISO turn to an output and generates all kind of signals on the line.

I have attached the signal analysis pictures - One with PE3 on and without.

Does anyone know whether this is a Bug inside the ST ?

FatFS init

-------------------------------------------------------

static void

power_on (

void

)

{

SPI_InitTypeDef  SPI_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

/* Enable SPI & GPIO clocks */

SPI_GPIO_CLK(ENABLE);

SPI_PERIF_CLK(ENABLE);

for

(Timer1 =

25

; Timer1; );

/* Wait for 250ms */

/* Configure I/O for Flash Chip select */

GPIO_InitStructure.GPIO_Pin = SPIMMC_PIN_CS;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(SPIMMC_PORT_CS, &GPIO_InitStructure);

/* Deselect the Card: Chip Select high */

CS_HIGH();

/* Connect SPI pins to AF */

 

SPI_AF_SET();

GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;

        

/* SPI SCK pin configuration */

GPIO_InitStructure.GPIO_Pin = SPIMMC_PIN_SCK;

GPIO_Init(SPIMMC_PORT_SCK, &GPIO_InitStructure);

/* SPI MOSI pin configuration */

GPIO_InitStructure.GPIO_Pin =  SPIMMC_PIN_MOSI;

GPIO_Init(SPIMMC_PORT_MOSI, &GPIO_InitStructure);

/* SPI MISO pin configuration */

GPIO_InitStructure.GPIO_Pin =  SPIMMC_PIN_MISO;

GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;

GPIO_Init(SPIMMC_PORT_MISO, &GPIO_InitStructure);

/* SPI_MMC 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_Low;

SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;

SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;

/* 84000kHz /256 = 328 < 400kHz */

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_InitStructure.SPI_CRCPolynomial =

7

;

SPI_Init(SPIMMC, &SPI_InitStructure);

SPI_CalculateCRC(SPIMMC, DISABLE);

/* Enable SPIx  */

SPIMMC->CR1 |= SPI_CR1_SPE;

/* drain SPI */

while

(!(SPIMMC->SR & SPI_I2S_FLAG_TXE)) { ; }

SPIMMC->DR;

}

PE3 Init

-------------

void

init_PE3(

void

)

{

  GPIO_InitTypeDef GPIO_InitStructure;

 

/* Enable GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE , ENABLE);

/*-- GPIO Configuration ------------------------------------------------------*/

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;

  GPIO_Init(GPIOE, &GPIO_InitStructure);

}

 

2 REPLIES 2
Posted on September 24, 2012 at 00:40

The solution is somewhat obfuscated by the lack of defines, but I don't see any AF pin source configuration.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..