CubeMX and Kicad - a helper tool

Hi everyone. I’ve been playing with ST Micro’s CubeMX tool recently, as part of a hobby project. I have no intention of making the PCB, I just find schematic capture and perusing datasheets quite theraputic :slight_smile:

My design uses an STM32F767 - a big 208 pin LQFP Cortex-M7, along with a VGA DAC, Ethernet, USB Hub, Audio Codec, etc. I have been configuring my STM32 pinout using ST’s CubeMX software. If you haven’t seen it, it lets you pick a CPU from the ST catalog, then enable various peripherals. ST’s chips have some flexibility in function routing, but they are not fully flexible like, say, Nordic chips are. By that I mean, if you want to turn on UART4, you might find there are three possible pins that can be U4TX and another three that can be U4RX. If you then enable SPI3, you might find that some of those options for the UART pins are no longer available. Even with a the big 208 pin devices, it can be quite a balancing act to enable all the types of peripherals you want without pin collisions, and CubeMX can help.

What I found tedious though, was copying the pin definitions from CubeMX (PA0 is UART4TX, PC15 is FMC_D3, etc) into Kicad. After I’d relaid out my chip twice and had to tear up a huge set of labels and re-do them, I figured there was an easier way.

Well, here’s a Python tool I wrote. It reads in a Symbol library, a CPU name, a Schematic and a CubeMX pin spreadsheet in CSV format. It then adds labels to the schematic according to the CubeMX configuration, lined up with the pins.

It won’t work for vertical pins, and currently it only appends to the schematic, so you have to manually move the final “$EndSCHEMATC” line otherwise Kicad won’t see all the labels you just added. And you have to delete any existing labels before you run the tool. But so far, it’s helped me out a bit.

Before I go too far down this road, does anyone know if there a plugin system for Kicad which would allow me to integrate this sort of thing? What does everyone else do to copy pin configuration into their schematic tool of choice? Does Altium have features which make this easier? What about for Atmel, or TI, or Silicon Labs parts with configurable pins?

3 Likes

I use ALTIUM and my first thought is always to write scripts for anything that takes me more than 3 repetitive steps stuff, but with every project being just slightly different #xkcd 1205 just did not work out.

The compromise between automation and manual labor I ended up with is it taking the datasheet and/or pin configuration tool, managing that data into an excel sheet and the using Altium’s list editor to paste the date into net labels or whatever makes the most sense. It really is a powerful tool that tends to be overlooked even by experienced users.

https://www.altium.com/documentation/altium-designer/sch-pnl-schlistsch-list-ad

Maybe there is something similar for Kicad.

1 Like

SnapEda has many parts, supports all tools. So maybe look there first…

I think you missed the point. He’s not looking for the generic symbol/footprint, he’s trying to get labels onto the nets, so that, for example, pin 14 has a label saying USART1_TX instead of PA9 (which could have one of 5 or more different functions you have to look up in the datasheet).

Ok, I see

It is annoying. But is labeling specific function the way forward? If you use another function then you need to change the schematics and you cannot use the symbol for the next project

I normally create an excel sheet that has pin allocation, including gain factors so I can handover to the SW guy

Granted, the schematics is not easier to read that way

I think the peripheral function (UART TX, SPI COPI, LCD VSYNC, etc) you assign to a given pin is largely based on what is connected to that pin via the rest of your schematic. So, to me, it seemed natural to place net labels on the wires coming out of the symbol which reflect the function I had assigned to that pin in CubeMX.

For example, if I am wiring up an SDRAM, I will have some address pins labelled A0…A13 (amongst other things). Automatically putting a nice label next to pin PB4 called SDRAM_A3 seemed quite useful to me. To be clear, this doesn’t affect the symbol, nor its re-use - only the net names on the wires attached to the symbol. Even better, if CubeMX decides to re-layout the pin-muxing on my chip (for reasons), with this tool I can quickly re-generate the labels. I have used busses, or just the net labels, to connect up all my sub-sheets and other components, there’s actually very little left to do on the schematic side, otherwise if you like to wire things up individually you may have to do some re-routing. The PCB side, of course, is a different matter.

1 Like