cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F051C Alternate Function Register problem

delillusions
Associate
Posted on June 28, 2013 at 11:12

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 

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00031936.pdf

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!

#stm32f051c
2 REPLIES 2
Posted on June 28, 2013 at 12:32

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 0xF0000000
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
delillusions
Associate
Posted on June 28, 2013 at 13:03

Thank you!