Script for creating KiCad symbols for STM32 MCUs


This script is now part of KiPart. A tool for creating KiCad symbols from CSV files.

ST has recently released a tool for creating projects for STM32 mcu’s called STM32CubeMX . This tool also allows you to plan your pin layout for a selected MCU part. Using the interface you see below, you can select pin features and configuration. You can also label the pins as you desire.

After you plan your pin layout, you can create a list of pins in the form of a CSV file. For this from menu select: “Pinout > Generate CSV pinout text file”. This should create a CSV file similar to this:

"Position","Name","Type","Signal","Label"
"1","VBAT","Power","",""
"2","PC13-ANTI_TAMP","I/O","",""
"3","PC14-OSC32_IN","I/O","RCC_OSC32_IN",""
"4","PC15-OSC32_OUT","I/O","RCC_OSC32_OUT",""
"5","PH0 - OSC_IN","I/O","RCC_OSC_IN",""
"6","PH1 - OSC_OUT","I/O","RCC_OSC_OUT",""
"7","NRST","Reset","",""
"8","VSSA/VREF-","Power","",""
...
...
...

Using this file and my script you can create a KiCad symbol that is specific to this pin layout in a whim. Get the script here.

When you run the script from the command line:

./makestmlib.py --name symbol_name input_file_name.csv output_file_name.lib

It should generate a KiCad symbol library which contains a symbol similar to what you see below.

As you can see output isn’t perfect. It certainly requires some edits. But it’s still very very useful.


2 responses to “Script for creating KiCad symbols for STM32 MCUs”

  1. Hey Hasan,
    very useful script to generate the symbols automatically!!
    I tried to run your Script but a error occurs :
    File “./makestmlib.py”, line 24, in parse_csv_file
    number, name, ptype, signal, label = row
    ValueError: not enough values to unpack (expected 5, got 1)

    Google says that this error occurs when your data isn’t in the right format, but my data generated by STMCube seems to be right:
    “Position”,”Name”,”Type”,”Signal”,”Label”
    “1”,”VBAT”,”Power”,””,””
    “2”,”PC13-ANTI_TAMP”,”Input”,”GPIO_Input”,””
    “3”,”PC14-OSC32_IN”,”Input”,”GPIO_Input”,””
    “4”,”PC15-OSC32_OUT”,”Input”,”GPIO_Input”,””
    “5”,”PH0 – OSC_IN”,”Input”,”GPIO_Input”,””
    “6”,”PH1 – OSC_OUT”,”Input”,”GPIO_Input”,””
    “7”,”NRST”,”Reset”,””,””
    “8”,”PC0″,”Input”,”GPIO_Input”,””
    “9”,”PC1″,”Input”,”GPIO_Input”,””

    May do you have any idea what is wrong?

    best regards
    florian

    • florian, first of all, this script is now a part of KiPart, any updates I make as part of KiPart. But I doubt that using KiPart version will solve your problem.

      One potential issue I see is the quoting characters in your file. But this could be the formatting of the wordpress. Can you post a link to your file (gist etc.) so I can debug this properly?

Leave a Reply

Your email address will not be published.