cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f2xx pb 14 hardware fault

akshay
Associate
Posted on November 01, 2013 at 08:55

When i use the command

GPIO_PinAFConfig(GPIOB, GPIO_Pin_14 ,GPIO_AF_SPI2);

the controller goes to a hardware fault.

my init function is 

void SPI_FLASH_Init(void)

{

  SPI_InitTypeDef  SPI_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

   

  /* Enable SPI2, GPIOA and GPIOBclocks */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 , ENABLE);

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

  /* Configure SPI2 pins: SCK, MISO and MOSI */

  GPIO_PinAFConfig(GPIOB, GPIO_Pin_13 ,GPIO_AF_SPI2);

GPIO_PinAFConfig(GPIOB, GPIO_Pin_14 ,GPIO_AF_SPI2);

GPIO_PinAFConfig(GPIOB, GPIO_Pin_15 ,GPIO_AF_SPI2);

  /* Configure PB.2 as Output push-pull, used as Flash Chip select */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Deselect the FLASH: Chip Select high */

  SPI_FLASH_CS_HIGH();

  /* SPI2 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_Soft;

  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

  SPI_InitStructure.SPI_CRCPolynomial = 7;

  SPI_Init(SPI2, &SPI_InitStructure);

  

  /* Enable SPI2  */

  SPI_Cmd(SPI2, ENABLE);   

}

1 REPLY 1
Posted on November 01, 2013 at 12:15

GPIO_PinAFConfig(GPIOB, GPIO_Pin_14 ,GPIO_AF_SPI2);

GPIO_PinSource14

GPIO_PinAFConfig wants an index (PinSource) not a mask (Pin)
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..