0
\$\begingroup\$

I am new to the STM32 world. I am using [STM32F407VG]1 (100 Pins pkg). I have to select an 8-bit port for connecting 8 digital inputs to the MCU.. but the datasheet shows so many alternate as well as additional functions on each pin that I am confused as to which pins i should select. Is there any SOP about how to select appropriate pins when multiple options are available for pin assignment?

edit:

Regarding Alternate Functions on port pins.. for example TIM1/2 alternate functions can be assigned on Port A, B or E.. Are all assignments of Alternate Functions equal or is there any more preferable port for peripheral alternate functions.. as in the case of TIM1 are all the Port A, B or E assignments would be same in all respects or will there be any difference from one case to the other?

enter image description here

\$\endgroup\$
  • 5
    \$\begingroup\$ I recommend the STM32CubeMX software to find out possbilities for pins. \$\endgroup\$ – Jeroen3 Feb 14 at 10:44
  • 1
    \$\begingroup\$ I generally interface groups of signals on a single port (using the primary function for digital I/O). That means that a single read can get all the inputs (or a write for outputs). \$\endgroup\$ – Peter Smith Feb 14 at 11:51
  • 1
    \$\begingroup\$ If an alternate function is available on multiple ports, then the only difference between ports is the list of other alternate functions on that same pin that you exclude yourself from when you select that port. If you don't need any of the other functions on any of those pins then it doesn't matter which port you select. Another consideration could be ease of routing on the board if you're designing your own board. \$\endgroup\$ – kkrambo Feb 14 at 13:06
  • 1
    \$\begingroup\$ A third consideration, if you're developing a low power application, then there might be an argument for combining all of your enabled pins onto a as few ports as possible so that you don't enable more ports than necessary. \$\endgroup\$ – kkrambo Feb 14 at 13:12
  • 1
    \$\begingroup\$ In your schematic tool, select a convenient pin for the function you want, and give a note to your PCB layout guy that he can change to pin X, Y, or Z if it makes routing cleaner. \$\endgroup\$ – pgvoorhees Feb 14 at 13:43
4
\$\begingroup\$

Work order in a professional project:

  • Determine what the product should do and write a spec.
  • Find out which external hardware that is needed. In particular, which serial buses do you need, how many ADC channels, how many PWM channels, how many GPIO etc. This should preferably be in the spec too.
  • Pick a MCU based on what you need. Not based on finding one on some hobbyist board or in a packet of corn flakes.

So the obvious answer to the question is then: pick GPIO from pins that aren't used by other hardware peripherals needed in your project. Port routing alternatives may be available.

Once that is sorted out, you should place pins related to the same external hardware the same GPIO port. For example if you need to scan 8 buttons, it will be wise to place all 8 in adjacent order on "port x".

And finally, if none of the above matters, pick pins that gives shortest paths/best layout on the PCB.

\$\endgroup\$
1
\$\begingroup\$

For the STM ARM Cortexes, I find that paying attention to what peripheral (including DIO port) sits on which bus. This lets you pay attention to where all your throughput is, allowing you to think about saving clock ticks if you have resources to spare, or consolidation on to fewer busses if you need to sip power.

from https://electronics.stackexchange.com/a/195643/11684 from STM32F40XX datasheet, via https://electronics.stackexchange.com/a/195643/11684

\$\endgroup\$
  • 1
    \$\begingroup\$ I don't know about the part described in that image (it isn't a STM32 part!), but on STM32F407, all of the GPIO peripherals are on AHB1. More generally, all of the peripherals of a given type are usually all on the same bus -- picking which one to use is a matter of pin planning, not power savings. \$\endgroup\$ – duskwuff Feb 14 at 17:57
  • 1
    \$\begingroup\$ @duskwuff -sorry, grabbed the wrong image. Tried to get something a little simpler, and missed. As you'll see, USARTs bus varies, as do timer busses. I thought I recalled that SPI's fall on different busses too, but I don't see that. Different timers have different capabilities as well, so they are more than pin planning. \$\endgroup\$ – Scott Seidman Feb 14 at 18:24
  • 1
    \$\begingroup\$ Also, the busses run at different speeds. \$\endgroup\$ – Scott Seidman Feb 14 at 18:25
  • 1
    \$\begingroup\$ Much better. FWIW: You might as well credit the new image to the original source -- it's from the STM32F407 datasheet. \$\endgroup\$ – duskwuff Feb 14 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.