cancel
Showing results for 
Search instead for 
Did you mean: 

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

devcal
Associate II
Posted on July 13, 2012 at 11:59

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.

Register

Address

Read

Expected

GPIOI->AFR[0] 0x40022020 0x00050500

0x00005550

GPIOI->AFR[1] 0x40022024 0x05000000

0x00000000

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.

Regards
2 REPLIES 2
Posted on July 13, 2012 at 13:45

GPIO_PinAFConfig(GPIOI, GPIO_Pin_1, GPIO_AF_SPI2);

You're supposed to be using GPIO_PinSource1

GPIO_PinSourceX uses numbers/index and has to be used alone.

GPIO_Pin_X uses a bit vector mask and can be combined with an OR.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
devcal
Associate II
Posted on July 14, 2012 at 13:10

Ok thanks, now I realize my mistake.