cancel
Showing results for 
Search instead for 
Did you mean: 

What is the functionality of PAx pins on STM32F103 series?

braveyav
Associate

Hi everyone,

I’m trying to design my first PCB using STM32F103 and I’m still a beginner.

I see that the PAx pins (PA0–PA15) have multiple alternate functions like GPIO, ADC, USART, SPI, etc.

I’m a bit confused about how to properly choose which PA pins to use for my peripherals.

If I use PA9/PA10 for USART, can I still use them as normal GPIO later?
What is functionality of PAx pins ?

I'm using STM32F103C8T6


stm32f103c8 datasheet 
stm32f103c8t6 

I'd really appreciate some guidance before I finalize my board layout.

Thanks! 

Best Regards !

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

Hello @braveyav and welcome to the ST community,

As you stated, each GPIO pin contains many alternate functions. To enable that function, you need to configure it by software. You can either modify that function at run time in your application but you need to ensure there will be no conflict externally by hardware.

What is functionality of PAx pins ?

-> look at the datasheet for each pin. For example: PA2 has three functions: UART2_Tx or ADC input or TIM2_ CH3

mALLEm_0-1771069820548.png

If you enable USART2 for example by software and select PA2 for Tx, PA2 will be reserved for this function. But as I stated before you can change that function in your application bu selecting TIM2 at runtime but you need to do that in a correct way.

Use CubeMx tool to configure the peripherals with their corresponding IOs. You can donwnload the tool from this link.

So you configure the peripherals with CubeMx and you generate the code with that configuration. Than you can use CubeDE tool (downloadable fom this link) and add the user code and compile/debug.

Read also this tutorial: STM32CubeIDE 2.0.0 workflow tutorial

Hope I've answred your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

7 REPLIES 7
mƎALLEm
ST Employee

Hello @braveyav and welcome to the ST community,

As you stated, each GPIO pin contains many alternate functions. To enable that function, you need to configure it by software. You can either modify that function at run time in your application but you need to ensure there will be no conflict externally by hardware.

What is functionality of PAx pins ?

-> look at the datasheet for each pin. For example: PA2 has three functions: UART2_Tx or ADC input or TIM2_ CH3

mALLEm_0-1771069820548.png

If you enable USART2 for example by software and select PA2 for Tx, PA2 will be reserved for this function. But as I stated before you can change that function in your application bu selecting TIM2 at runtime but you need to do that in a correct way.

Use CubeMx tool to configure the peripherals with their corresponding IOs. You can donwnload the tool from this link.

So you configure the peripherals with CubeMx and you generate the code with that configuration. Than you can use CubeDE tool (downloadable fom this link) and add the user code and compile/debug.

Read also this tutorial: STM32CubeIDE 2.0.0 workflow tutorial

Hope I've answred your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Thank you so much @mƎALLEm. So can we say that PAx pins are aliases for pins with multiple functions?

Best Regards !

A pin could be used for many functions according to the datasheet. The function assignment configuration is done by software in the user application. 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@braveyav wrote:

So can we say that PAx pins are aliases for pins with multiple functions?


Probably a more useful description would say that the various different functions are multiplexed onto a pin; eg, for PA2 (from the datasheet extract posted by @mƎALLEm:(

AndrewNeil_1-1771235151017.png

 

Note that this is not unique to STM32 or ST - (pretty much?) all microcontrollers have more internal functions than physical pins, so they all have some way to "multiplex" multiple functions onto a single  physical pin.

Precise details vary, but the principle is the same.

 

#AlternateFunctions

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Chris21
Senior III

"If I use PA9/PA10 for USART, can I still use them as normal GPIO later?"

Yes you can, your software can enable the pins as USART, then later reconfigure them.

But most designs allocate microcontroller pins to various functions permanently, pins switching function from USART to GPIO would be unusual; does the entity communicating via USART get physically disconnected in your system?

Such overloading complexity would typically only be considered if you have run out of microcontroller pins.

As @mƎALLEm mentioned, you can use CubeMx to allocate microcontroller pins to various functions in your system, ideally you will have enough pins for all your system's needs.  Or carefully study the datasheet and allocate pins as needed.

 

Andrew Neil
Super User

@braveyav wrote:

I see that the PAx pins (PA0–PA15) have multiple alternate functions !


Not just the PAx pins - also some PBx on this particular chip.

In general, any PXy pin could have multiple alternate functions.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
waclawek.jan
Super User

Going one step further, the switch as drawn by @Andrew Neil above can in fact be broken to two switches: one selects between GPIO (more specifically, GPIO output) and the input to the other switch, this is called Alternate Function. The second switch then selects between TIM, USART, ADC.

However, in STM32F1xx, the method *how* that function is switched, is different from all other STM32. It was the first STM32 family and ST did not figure out the right way to do yet. So, while in all other STM32 thre's a dedicated register to steer that second switch, in the 'F1 family, it's steered by whichever peripheral's clock is enabled in RCC. This is then further complicated by the need to select groups of pins associated to given peripheral, in the AFIO module.

What I'm trying to get at is, that the STM32F103 is not the best candidate for the first STM32 to be used by a novice.

JW