2012-07-13 02:59 AM
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 ExpectedGPIOI->AFR[0] 0x40022020 0x00050500
0x00005550GPIOI->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. Regards2012-07-13 04:45 AM
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.2012-07-14 04:10 AM
Ok thanks, now I realize my mistake.