Kicad_sym file format


I’m editing a symbol in text mode because it’s faster (at least for me), and I have the following problem:
NB: It works, but the file format seems to be a bit odd (I want to make a PHP script to process all the libs I wrote, adding alternate pins, so it would be better if I know the subtleties of the file format).
The symbol I’m editing is a MSP430F5438. 100 pin device.

The symbol definition starts like this. The pins start at number 10, then 100, then 11, 12, etc. I can live with that. except that there is no pin 1.

Screenshot from 2023-03-07 11-02-32

Then at the end of the symbol, pin 99 is the last one, which makes sense because 100 is at the top.
But then there are other definitions for the same symbol, and pin 1 (P6.4) is in <symbol_name>_1_1.
Why is that? Is there a specific reason to treat pin1 apart?

Screenshot from 2023-03-07 10-49-23



Remember that the pin elements don’t have to be in any particular order for a valid symbol, though it looks like KiCad sorts lexicographically by the number field to reduce diffs when comparing versions in a VCS, and pin elements come before symbol elements, You should probably read the whole symbol into an object before working on it, and output it in KiCad’s order when transformation is finished.

PS: This part I’m guessing from my previous glances at the format but the pin elements pertain to the properties while the symbol elements pertain to graphical appearance. I think _0 is for all units, _1 is the A or only unit, _2 B and so forth. But if I got any of this wrong, I didn’t write the preceding, it was the cat jumping on my keyboard. You should check the official documentation or the source code.


Thanks for your reply!
Sorry, my question wasn’t clear.
The symbol definition in my case starts with:

(symbol “MSP430F5438_0_0”

Then there is mostly a list of pins, and I can live with this even if the order is like this
10, 100, 11, 12 … , 2, 21, 22, etc. I can live with this, it’s not really a problem.

The problem is this: from the 100 pin QFP, 99 are defined. Then there is this section:

(symbol "MSP430F5438_0_1"
  (circle (center -45.72 45.72) (radius 1.27)
    (stroke (width 0) (type default))
    (fill (type none))
(symbol "MSP430F5438_1_0"
  (rectangle (start -48.26 48.26) (end 48.26 -48.26)
    (stroke (width 0) (type default))
    (fill (type background))

And at the very end, the last pin is defined:
(symbol “MSP430F5438_1_1”
(pin bidirectional line (at -50.8 30.48 0) (length 2.54)
(name “P6.4” (effects (font (size 1.27 1.27))))
(number “1” (effects (font (size 1.27 1.27))))

So the question is: why is the last pin defined separately in another symbol?
And by the way, why are the outer shape (the rectangle) and the pin1 marker (circle)
defined in separate symbols?
If I generate a file using some script, using an excel file of the pin list, what are the rules
to do that? If I start with defining (symbol “MSP430F5438_0_0”, what are the rules
to add a new symbol definition like (symbol “MSP430F5438_0_1”, then why
(symbol “MSP430F5438_1_0” and not (symbol “MSP430F5438_0_2”, etc…



I think the keyword “symbol” is being reused in another context to describe the pin graphical properties. It’s probably the pin 1 marker.

The usage of the two suffix numbers is probably described in the documentation. :crossed_fingers:


Thanks for your reply.

Well, I have checked the link above (by the way thanks, Paul).
I have read the S-expression format paragraph. Then from the link above,

There is a “LIBRARY_ID” which may correspond to “MSP430F5438” in my case.
Then there is this UNIT_ID. Now as it is a text file, how should I understand this:
“LIBRARY_ID” | “UNIT_ID” ? What does the pipe mean? I suppose it cannot be a boolean
in this text file.
If “LIBRATY_ID” is “MSP430F5438”, what would be “LIBRARY_ID” | “UNIT_ID”?
How do I map this to “MSP430F5438_0_1” that I can see in the symbol file?
What do the 0 and 1 mean?



It’s a grammar definition and those rules are called productions. The pipe indicates alternative expansions of the term.

Hint: UNIT_ID is defined by:

Symbol unit identifiers define how symbol units are identified. The unit identifier is a quoted string have the format “NAME_UNIT_STYLE”. “NAME” is the parent symbol name. “UNIT” is an integer that identifies which unit the symbol represents. A “UNIT” value of zero (0) indicates that the symbol is common to all units. The “STYLE” indicates which body style the unit represents.

So in _0_1, the 0 is the unit number and means common to all units, and 1 is the first kind of body style.



Thanks for your reply. Indeed, the format was in the documentation. Sorry about that, I read it too fast.



If there is some comment you like, then click on the heart underneath that post.
A quick check on your forum shows you have received 54 “likes”, but never given any.
It is a visual feedback so others also can see those posts have been “useful”, and it also unlocks some forum functions. For me it does not matter, I’ve got plenty of them, but it helps new users.


I might be too old to adapt to the social network-ish habits (I don’t have any facebook, insagram… - you name it - account) although I don’t feel I’m a fossile yet. I wasn’t aware of this feature, but I usually never forget to thank people who help me. And I don’t like to brag about it, but I also made everything with the accounting here to be allowed to make donations. Not a big amount, but now I can do it, I have started, and the idea is to do it on a regular basis. That’s my way to show how I appreciate the great work of developers.
As for the “likes” I received, I wasn’t aware of it, but anyway many thanks to people who have appreciated what I wrote. Ok, if it helps, let’s do it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.