2013-06-28 02:12 AM
Hi Everyone!
Sorry for interrupting all of you, but I have a problem. Next year I will graduate from my University as an Electrical Engineer (at least on paper I will be one). For my thesis I'm currently using an STM32F051C8T6 ARM. I have to say, that I specialized myself in Hardware Designing and not in Programming, but I can handle myself (most of the time). I designed, build, tested and currently using my own STM32 board. I successfully programmed almost every peripheral in the MCU without the provided Standard Peripheral Libraries [SPL]. I started with using those, but in time I wrote my own libraries and they work as they should be. There is still one function I still has to use from the SPL, and that is setting the Alternate Function of the GPIO pins. The problem is that the Reference Manual for the MCU ans the provided stm32f0xx.h in the SPL are not matching with each other. The Ref.Manual says it has two registers (GPIOx_AFRL and GPIOx_AFRH x = A..B page 137), while the provided stm32f0xx.h file only contains this line: '' __IO uint32_t AFR[2]; /*!< GPIO alternate function low register, Address offset: 0x20-0x24 */'' (line 411) Can someone help me about how to use the Alternate Functions without the SPL? I rarely use the STMs predefined Register Bit Definitions. Thank you for your help! Best Regards! #stm32f051c2013-06-28 03:32 AM
It was done like that to simplify the indexing into the register, ie you don't need to do a comparison for [0..7] and [8..15] on the pin.
GPIOx_AFRL -> AFR[0] GPIOx_AFRH -> AFR[1] Each pin has a 16-to-1 MUX, so 4-bits are allocated. All 16 states may not be used, other STM32 parts might use 8-10 combinations. So pin PA0 would be the low order 4-bits in GPIOA->AFR[0], PC15 would be the high order 4-bits in GPIOC->AFR[1], ie mask 0xF00000002013-06-28 04:03 AM