AnsweredAssumed Answered

Error on AF register calculation for SPI with the Standard Periphery Library

Question asked by devcal on Jul 13, 2012
Latest reply on Jul 14, 2012 by devcal
Based on the Standard Periphery Library. In the following file I found a register calculation error.

  * @file    stm32f4xx_gpio.c
  * @author  MCD Application Team
  * @version V1.0.2
  * @date    05-March-2012

In the Method:
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
Code line: 535

When I try to use the code to set an GPIO_AF_SPI2 ((uint8_t)0x05) on the GPIO peripheral "I" for the pins 1,2 and 3 I get the wrong initialization.

I use the following code:

void set_AF(void){
    GPIO_PinAFConfig(GPIOI, GPIO_Pin_1, GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIOI, GPIO_Pin_2, GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIOI, GPIO_Pin_3, GPIO_AF_SPI2);

In the following table I wrote the readen and expected values from the registers after running the initialization.
GPIOI->AFR[0] 0x400220200x00050500

As you can see the initialization for the pins using the Standard Periphery Library is wrong. I spend a couple of hours debugging my code trying to find the error. I hope this could help someone. And that the algorithm for the register calculation can be checked.