cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO & alternate function = confusion

krk
Associate II
Posted on December 13, 2009 at 13:09

GPIO & alternate function = confusion

6 REPLIES 6
krk
Associate II
Posted on May 17, 2011 at 13:34

Hi,

ok today I played a bit around with the STM32-P103 board ( STM32F103RBT6 ) and get confused with alternate function of the GPIO pins.

I understood that I can configure each pin with the GPIOx_CRn register for his alternate function. I tested it with the USART_1 on PA9/10 and it worked fine. But from where does the information come which alternate function shall be used if the port has _multiple_ alternate functions ?

Let me give you one example:

- I want use USART_1 TX/RX on PA9/10

- I also want use TIM1_CH4 at PA11 to generate a PWM signal

- I also want use PA12 as an normal ( =no alternate function ) output

First question: Is this configuration possible or does I miss something ?

When I check the datasheet I see:

- PA9/10 is also used by TIM1_CH2/3. Because I want use TIM1_CH4 at PA11, TIM1 AND USART1 are activated. So where does the information come from which pin is mapped to which alternate function ?

My assumption is that the TIM1 pins at PA9/10/12 will be mapped to TIM1 if I activate the corresponding TIM1 channels ?

What will happen if I activate USART_1 TX/RX on PA9/10 AND also the TIM1_CH2/3 channels ?

swhite
Associate III
Posted on May 17, 2011 at 13:34

Ok, here my 2c worth.

First you configure the GPIO pin(s) for the type of I/O you want. That is

* Input (pullup/pulldown/floating/analog)

* Output (push-pull, open-drain)

* Alternate-function--that is peripheral controlled--output (push-pull, open-drain)

Inputs always connect to any on-chip peripheral(s). Outputs only do so if they're setup as ''alternate function''.

For outputs if there's a conflict only the peripheral that is clocked drives the output. If you have more than one clocked you're asking for trouble. If you don't (i.e. forget to) enable the peripheral clock your output(s) won't change.

BTW the datasheet (not family manual) has a table containing the pin mappings.

FYI many peripheral I/O functions can be ''remapped''. All this means is that the I/O that peripheral uses are on different pins than the reset default. All GPIO configuration is done for those pins (i.e. not the default ones).

krk
Associate II
Posted on May 17, 2011 at 13:34

Thanks for your quick answer. If I understand you corretly than the only thing I must consider is that two peripherals shall not share the same alternate-OUTPUT pin ?!

So I would think that I can use my described scenario (?):

- PA9 = USART1_TX ( disable TIM1_CH2 )

- PA10 = USART1_RX ( disable TIM1_CH3 )

- PA11 = TIM1_CH4 ( disable USART1_CTS ) ( CAN & USB is not used )

- PA12 = Output

swhite
Associate III
Posted on May 17, 2011 at 13:34

Quote:

If I understand you corretly than the only thing I must consider is that two peripherals shall not share the same alternate-OUTPUT pin ?!

Exactly. However that doesn't mean you can't use both peripherals. If you want to use both peripheral output functions then you have to remap the pins for one of them. Some peripherals, such as the timers, have the ability to output signals but you don't have to enable them.

Quote:

- PA9 = USART1_TX ( disable TIM1_CH2 )

- PA10 = USART1_RX ( disable TIM1_CH3 )

- PA11 = TIM1_CH4 ( disable USART1_CTS ) ( CAN & USB is not used )

- PA12 = Output

So to use USART1_TX you can't use Timer 1 output compare 2 to generate a signal on PA9 (you can use Tim1 OC2 without an output function). Similarly you can't use Timer 1 OC3 to generate output. USART1_CTS is an input function so it is always connected to PA11 so you must configure USART1 to ignore CTS.

You could always remap USART1 or TIM1 to use all the functions of both at the same time.

akaiser9
Associate II
Posted on May 17, 2011 at 13:34

And never forget to consult the errata sheet. There are conflicts between peripherals and their pins mentioned.

krk
Associate II
Posted on May 17, 2011 at 13:34

Ok, thx I checked the errata. But it seems that there are no conflicts with the peripherie I want to use 🙂

[ This message was edited by: krk on 13-12-2009 17:40 ]