Author Topic: Pin selection tool  (Read 949 times)

0 Members and 1 Guest are viewing this topic.

Offline Nominal AnimalTopic starter

  • Super Contributor
  • ***
  • Posts: 8354
  • Country: fi
    • My home page and email address
Pin selection tool
« on: November 14, 2026, 06:42:47 pm »
I've noticed that whenever I look at a microcontroller or SoC I might wish to use, especially the reduced-pin non-BGA versions, some of the more interesting peripherals are effectively mutually exclusive because of limited available pins.  To solve this, I created a tool, of course.

However, I'm wondering if you too have encountered this issue, and would like a semi-interactive browser-based local tool (no server, no internet connection needed, CC0/Public Domain license so you can modify it to your liking) for this, in the same vein as my FIR filter spectrum analysis or Advantest horizontal scaling and palette test pages.

The algorithm is a simple, deterministic, fast, and recursive; well suited for JS in a browser, finding solutions in a fraction of a second even on slow devices.  On each iteration, it first checks if any of the facilities needed has only one pin choice left, and assigns them, removing it from the other facilities' lists.  If it runs out, it tells which facilities conflicted (and ran out of pins).  Otherwise, it repeats this as long as pins can be assigned.  Then, it collects the undetermined ones and their leftover options.

I was thinking the tool could then present these as drop-down lists, where you need to assign at least one to proceed (but can assign all if you want).  It then repeats this (presenting further choices if necessary), until the pin configuration is fully determined (or runs out of pins, in which case you can change your choices before).  Finally, it presents the determined pin set, in both sorted pin order, and in sorted facility order.



As a practical example, consider STM32H7A3RIT or STM32H7A3RGT (datasheet) in LQFP-64.  Let's say you're helping @Tantratron with the display replacements for some Advantest spectrum analyzers, and you wish to use AT056TN53v1 display at 640×480 resolution, and the parallel PSSI 8-bit input.

Essentially, you want USB (DM and DP for firmware updates), 8-bit PSSI, and LCDC. Is it possible or not?

If you want a pure RGB888 or RGB565 output, it turns out it is not.  However, if you don't mind skipping some color component bits on the output (which is not a problem if you use L8 or A44 byte-per-pixel modes with palette look-ups, and don't need to do pixel color math at all), it can; for example,
Code: [Select]
SWCLK     49:PA14
SWDIO     45:PA13

USB_DM    43:PA11
USB_DP    44:PA12

LCD_VSYNC 23:PA7
LCD_HSYNC 37:PC6
LCD_DE    25:PC5
LCD_CLK   35:PB14

LCD_R1    16:PA2
LCD_R2    15:PA1
LCD_R4    21:PA5
LCD_R5     8:PC0
LCD_R6    53:PC12
LCD_R7    24:PC4

LCD_G0    27:PB1
LCD_G1    26:PB0
LCD_G4    29:PB10
LCD_G5     9:PC1
LCD_G6    38:PC7
LCD_G7    36:PB15

LCD_B1    51:PC10
LCD_B2    17:PA3
LCD_B3    40:PA8
LCD_B5    57:PB5
LCD_B6    50:PA15
LCD_B7    54:PD2
which leaves a couple of PWM-capable pins and ordinary GPIO pins (for backlight and orientation on the display), but also the SWDIO, SWCLK, and USB FS pins free for very easy reprogramming.  (When the BOOT0 is pulled high when plugging in the USB, it boots up in ARM DFU firmware upload mode.)  The logical use is on the left, and the  LQFP64pin:name is on the right; but you can use any pin naming scheme you want.

Note that 8-bit red (R), green (G), and blue (B) components are stored as Rfb, Gfb, Bfb in the framebuffer and LUTs, where
    Rfb = ((R >> 1) & 0x06) | (R & 0xF0)
    Gfb = ((G >> 2) & 0x03) | (G & 0xF0)
    Bfb = ((B >> 1) & 0x0E) | (B & 0xE0)
but you do have full 18-bit color (262,144 colors) with the LCDC is configured to output RGB888.  Again, if you just use predefined colors and don't do blending, everything will work just fine; it's just that blending colors due to the above won't work right (either in hardware or in software): you would have to do the reverse of the above (and replicate the two LSBs) first, then do the blending, then redo the above.  Doable, but too annoying in practice.

Of course, right now the LQFP-100 version (STM32H7A3VxT) is cheaper than the LQFP-64 version at Mouser right now (with none in stock at Digikey), so this is a bit silly example; but illustrates the type of problem this tool solves.

If you want to try it out first, the very crude prototype (working) command-line, text-based implementation in Python3 is attached.  Again, if there is interest, I'd rather make this into a tool page for portability and nice-GUI ease-of-use.  It does assume each pin can be individually assigned, so won't work for some MCUs like most WCH-IC RISC-V ones (which configure pins as sets, not individually).
 
The following users thanked this post: pardo-bsso, Tantratron

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 6144
  • Country: nl
Re: Pin selection tool
« Reply #1 on: November 22, 2026, 09:32:09 am »
Hi Nominal Animal,

this is interesting, but it is not clear as to what the input data should be for your python tool. (Have not played with it, just looked at the code in a glance)

Within the development of my modular control surface, I have ran into pin issues that not only are problematic due to other peripheral pin interference, but also lack of DMA support.

As an example, I'm designing a fader module that uses WS2812-2020 and 5050 leds to display states and other information. To make full use of the STM32F103C8, I like to have a triple fader variant that needs to support four WS2812 data streams. With my single timer based setup it turns out that only timer 1 can be used for this. Why because this is the only one that has DMA connections for all of the compare channels. Timer 2 does have all four compare/capture events routed to DMA, but channel 2 and channel 4 both use DMA channel 7, so no independent data transfer possible.

Why four data streams, well to allow for faster independent updates of the different led strips.

So I can imagine there are other limitations when allocating IO pins to different peripherals than just the alternate function selection alone.

Offline Nominal AnimalTopic starter

  • Super Contributor
  • ***
  • Posts: 8354
  • Country: fi
    • My home page and email address
Re: Pin selection tool
« Reply #2 on: November 22, 2026, 09:15:08 pm »
it is not clear as to what the input data should be
Just lines of
    facility-or-pad alternatepin1 alternatepin2
with #, ;, or // starting a comment.  I fixed a couple of typos in the attached version.

I've also attached the example configuration file for STM32H7A3RIT/STM32H7A3RGT.

When run, the output is
Code: [Select]
Found 1 solutions.
Resolved assignments:
  LCD_B1       = 51:PC10       |  15:PA1       = LCD_R2     
  LCD_B2       = 17:PA3        |  16:PA2       = LCD_R1     
  LCD_B3       = 40:PA8        |  17:PA3       = LCD_B2     
  LCD_B5       = 57:PB5        |  20:PA4       = PSSI_DE     
  LCD_B6       = 50:PA15       |  21:PA5       = LCD_R4     
  LCD_B7       = 54:PD2        |  22:PA6       = PSSI_PDCK   
  LCD_CLK      = 35:PB14       |  23:PA7       = LCD_VSYNC   
  LCD_DE       = 25:PC5        |  24:PC4       = LCD_R7     
  LCD_G0       = 27:PB1        |  25:PC5       = LCD_DE     
  LCD_G1       = 26:PB0        |  26:PB0       = LCD_G1     
  LCD_G4       = 29:PB10       |  27:PB1       = LCD_G0     
  LCD_G5       = 9:PC1         |  29:PB10      = LCD_G4     
  LCD_G6       = 38:PC7        |  34:PB13      = PSSI_D2     
  LCD_G7       = 36:PB15       |  35:PB14      = LCD_CLK     
  LCD_HSYNC    = 37:PC6        |  36:PB15      = LCD_G7     
  LCD_R1       = 16:PA2        |  37:PC6       = LCD_HSYNC   
  LCD_R2       = 15:PA1        |  38:PC7       = LCD_G6     
  LCD_R4       = 21:PA5        |  39:PC9       = PSSI_D3     
  LCD_R5       = 8:PC0         |  40:PA8       = LCD_B3     
  LCD_R6       = 53:PC12       |  41:PA9       = PSSI_D0     
  LCD_R7       = 24:PC4        |  42:PA10      = PSSI_D1     
  LCD_VSYNC    = 23:PA7        |  43:PA11      = USB_DM     
  PSSI_D0      = 41:PA9        |  44:PA12      = USB_DP     
  PSSI_D1      = 42:PA10       |  45:PA13      = SWDIO       
  PSSI_D2      = 34:PB13       |  49:PA14      = SWCLK       
  PSSI_D3      = 39:PC9        |  50:PA15      = LCD_B6     
  PSSI_D4      = 52:PC11       |  51:PC10      = LCD_B1     
  PSSI_D5      = 58:PB6        |  52:PC11      = PSSI_D4     
  PSSI_D6      = 61:PB8        |  53:PC12      = LCD_R6     
  PSSI_D7      = 62:PB9        |  54:PD2       = LCD_B7     
  PSSI_DE      = 20:PA4        |  57:PB5       = LCD_B5     
  PSSI_PDCK    = 22:PA6        |  58:PB6       = PSSI_D5     
  SWCLK        = 49:PA14       |  61:PB8       = PSSI_D6     
  SWDIO        = 45:PA13       |  62:PB9       = PSSI_D7     
  USB_DM       = 43:PA11       |  8:PC0        = LCD_R5     
  USB_DP       = 44:PA12       |  9:PC1        = LCD_G5     
No unresolved cases; configuration is fully determined.
No unused/unassigned pins.
where the left side is sorted by facility, and the right side is sorted by pin.

So I can imagine there are other limitations when allocating IO pins to different peripherals than just the alternate function selection alone.
Sure; 5V tolerance on STM32H7 series is another limitation, if you want to interface to older 5V TTL logic (which has the same voltage level thresholds as 3.3V CMOS).

The idea is that you list all the possibilities, and the tool searches for valid combinations.  It will also tell how many solutions it can find.

With the command-line tool, you need to update the configuration to limit the options if there are more than one valid combination; the browser tool could do it interactively, giving you a list of pin names, each with a checkbox, for the undetermined facilities.
 
The following users thanked this post: pcprogrammer


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->