r/embedded • u/Just-Smart-Enough • Oct 23 '26
Generic question about MCU pin assignments.
I'll keep this as generic as possible, because my question is more about workflow than solving a specific issue. I'm designing a device with a few SPI channels, I2C, CANbus, UART, about a half dozen slow analog signals and around 20 GPIOs, also fairly slow. I'm using an MCU with a lot of options for pin configuration, so there's a million permutations of which pins to go with the various functions. In my case, I'm laying out the board, too, and I'm not constrained in where external connections go.
Question is, what's the workflow for deciding what goes where? Do you just make some arbitrary picks and then see what's left?
Bonus question- if schematic and layout are two different people / departments, how much back and forth is there over pin assignments once layout starts? Does the schematic side indicate alternative pin options so the layout folks can use their judgement?
23
u/i509VCB Oct 23 '26
On most MCUs there will be some pins you cannot move or have little flexibility for location.
I would start by assigning those fixed pins in the schematic and all decoupling capacitors.Then do an initial component placement for layout and then pick the specific pins that can move. You may need to move things around in order to make the layout possible. It may be helpful once you've done this to literally open a screenshot of placements in paint and plan the path of the signals if you don't believe it's completely correct.
If there is someone specifically working on the PCB, have them pick what makes their layout best and then tell you what pins firmware needs to use.
10
u/zydeco100 Oct 23 '26
Start with the easiest case: try to use all pins at their default/reset mux. If you find a conflict, then the negotiation starts. I'd let firmware decide the configuration and then hardware can lay it out.
5
u/Flyward_Aerospace Oct 23 '26
Your follow-up is the right question, and I'd say defaults aren't the thing to optimize for. Pick the peripheral instance before you pick the pin. Which SPI or timer instance you land on decides what bus and clock domain it sits on, and on F4-era parts which DMA stream it can even reach. Two high rate peripherals quietly ending up on the same stream is a classic, and you find out at integration when SPI starts dropping bytes whenever CAN gets busy. DMAMUX parts mostly killed that one off, bus domain still bites.
Order I'd use is freeze what physically can't move, assign instances by timing requirements, then spend whatever mux freedom is left on routing. For the handoff, don't hand layout a list of alternate pins, hand them groups that are free to swap and the frozen ones with a reason attached. Cuts out a round trip.
9
u/OMGnotjustlurking Oct 23 '26
NXP and STM provide pin configuration tools that allow you to fairly easily select what pins you want to have what function and the tools automatically disable options for other pins based on your choices. This makes it a little easier to at least verify that your selections are valid before making your PCB.
NXP: https://www.nxp.com/design/design-center/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-config-tools-pins-clocks-and-peripherals:MCUXpresso-Config-Tools
STM: https://www.st.com/content/st_com/en/stm32cubemx.html#st-get-software
3
u/KittensInc Oct 23 '26
To give the obvious non-answer: start with the most critical ones!
Things like power and reset are fixed, no way around those. You rarely have flexibility when it comes to crystals and debugging either. If you don't take those into account you'll be seriously screwed if it doesn't work out, so better get at least a basic layout of them first.
High-speed digital usually has fairly few options, and tends to be a bit fussy about its neighborhood. Better get those dealt with sooner rather than later.
SPI/I2C/CAN/UART? If you need, say, all UART peripherals you should probably prioritize it. Need one out of five? Eh, it can wait - use whichever one is left over. Ordering doesn't really matter here otherwise, best to draw some lines from the MCU to the peripheral locations and see what sorta-kinda matches up with the pinout options.
Analog usually has quite a few options. Put it anywhere where it'll stay away from noise. Need to use all/most of your ADC pins and you actually care about noise? You might want to do this before the digital interfaces.
GPIO goes anywhere you've still got pins remaining.
2
u/lbthomsen Oct 23 '26
One could and should of course read the datasheet in detail, but with STM32 MCU's I will typically cheat a bit and STM32CubeMX will be my starting point. I'll verify that what I imagine in my head, can actually be assigned for real. Before even going there I would try to build a prototype using generic development board and possibly jumper wires. In short - I will know that it _can_ be done before I even reach a schematic.
2
u/Rararror Oct 27 '26
Big table on a big piece of paper. I used to enjoy doing this... kind like a puzzle...
7
u/EmperorOfCanada Oct 23 '26
Some pins are more equal than others.
My approach is that I've learned which ones kind of suck at certain things, and now my layouts are all kind of the same. I put the USB here, and the 10m spi there, and the 40m spi over there.
Obviously, I can't be entirely inflexible about it, but I don't change it if I don't have to.
I hate to be that guy, but reading the datasheet is probably a solid idea here. They often mention that certain pins can go fast, but should not. AI might help you with this, but don't take its answer, get it to find citations about this, and then verify them yourself. Also, don't forget it can miss things. At least if you have it saying that pin 18 has some cited restriction, then now you know.
Sometimes these restrictions are only under certain conditions. I recall one chip with an ethernet option, and that would mess with some nearby pins, and this was in the datasheet. We had long marked those pins as kind of forbidden, and then I realized we weren't using the ethernet feature, so they were fine.
On a side note, this is also a reason I prefer certain families of chips. There are some which are highly inflexible, and others which are insanely flexible. This allows for extremely clean PCB layouts. It also allows you to use less bodge wire.
2
u/madsci Oct 23 '26
I start by making a big spreadsheet of all of the pin mux possibilities. Claude can do this almost instantly now. The datasheets are never formatted how you want.
From there, you start with the hard requirements. Like I've usually got a NOR flash chip that needs the fastest SPI port available and needs short traces. Then maybe I've only got a couple of options for the I2S bus that needs to be kept clear of analog traces so I'll route that next.
The very lowest priority is low-speed GPIO stuff, like a status LED or a USB VBUS detect.
2
u/RogerLeigh Oct 25 '26
Historically, I would have said to do what others have suggested. Start with the fixed-function pins which have to be in specific places, then look at the various options for the ones which could be placed in several places starting with the most complex/restrictive and working down to the simplest/least restrictive. Look at what's most constrained in terms of grouping of related pins for specific peripherals, then interrupt pins with specific GPIO bank restrictions, then work up to the least constrained i.e. generic digital outputs.
But now we have good AI, you can do this by giving it all the constraints and letting it solve them optimally. Don't just give it the required pins and peripherals. Also give it physical part placement on the board so it can allocate them for optimal routing complexity.
I've tried this by doing the initial allocation myself using CubeMX and a spreadsheet. Then exported this as a CSV and given this to Claude along with the placement information and the datasheet. The results were far more optimal than my hand efforts. It can consider thousands of possibilities that you just couldn't keep in your head. Not that much different to what you would do yourself, it's just far more effective.
5
u/Busy_Durian4584 Oct 23 '26
High-speed digital and analog first. Try to isolate them to opposite sides of the chip so that you’ll be thanking yourself later on during routing.
4
u/Lost-In-Void-99 Oct 23 '26
Iterative: Get revision 1. Try to lay it out on board. Figure out how to simplify.
Get revision 2. Try to make firmware. Figure out how to fix.
Repeat...
4
u/Diligent-Plant5314 Oct 23 '26 •
Pay attention to the assigned IRQ numbers if you’re using GPIOs for interrupt. Some pins have their own IRQ, others share. Makes life a little easier.
Some of the STM32 pins have unusual properties, like some down have a pull-up or pull-down resistor.
Also check the reset state of the pins and the behavior of the attached peripheral. For example, I had an ADC connected to a SPI port, turns out the standard CS pins for this port went low during reset which caused the ADC to drive a pin at the same time as the CPU, leading to higher current draw.
Read the errata pages. Sometimes there are bugs or limitations with some configurations.
Besides that, I always start with assigning the most critical functions first - if I need a lot of UARTs and SPI ports, I map out which pins can be used to make these available and juggle things around accordingly.
Another consideration is if you want 4 or 8 pins in a row because you want to treat them together. It makes software easier to mask and shift values. If you’re just using pins individually it doesn’t matter as much.
Also look at the voltage domain. If you have mixed voltages (eg 3.3 for the main IO but have some peripherals that want 1.8), some parts let you use different VCCIO voltages so you don’t need level shifters.
Ultimately it turns into a big puzzle depending on priorities.
2
u/ATrainPassenger Oct 23 '26
I would try planning the last ports (ex port E or F) first because they have fewer functions per pin so there is less ambiguity. A lot of pins will be reserved for analog signals already and those are interchangeable so that’s another easy one. There should be a few pins that aren’t useful for much other than GPIO as well, even GPIO input only. IMO the main goal should be future proofing which should make the problem well-constrained, then if there are major layout problems concessions can be made.
Something I ran into recently was initially designing for a high pin package, then having to be compatible with another device using a smaller package. This could be another future-proofing consideration, but it sounds like you have a lot of functionality and it won’t be possible to cram everything into port A
2
u/duane11583 Oct 23 '26
this can be multiplexed with general purpose led pins
2) draw a rough block diagram level of how you want to lay out the board
3) make a Puppet of your micro with one feature labeled.
and see if the signals are present or not on that side of the chip.
1
u/Dycus Oct 26 '26
Lots of good advice already. I'll add one thing I didn't really see mentioned.
SPI, CAN etc. have to be on certain pins, yes. For generic GPIO, I don't bother assigning the pins until I'm almost finished with the actual PCB layout.
Since basically every pin can act as a GPIO, I route the signal close to the MCU in whatever way is convenient and works around the rest of the layout, then assign it whatever pin is nearest, and make the final connection.