Cubemx -> Makefile utility

Cores are the underlying magic that make the Arduino API possible
User avatar
Posts: 2
Joined: Tue Dec 06, 2016 12:23 pm

Re: Cubemx -> Makefile utility

Postby kont-noor » Sat Feb 04, 2017 12:37 pm

Well I solved my issue. There were 2 differences between expected `.cproject` file and mine. There was hardcoded domain (superClass attribute) and different name attribute.
Below there is the diff. It could be helpful.

Code: Select all

--- a/
+++ b/
@@ -138,7 +138,7 @@ def main():
     root = tree.getroot()

     # MCU
-    mcu_node = root.find('.//toolChain/option[@superClass="fr.ac6.managedbuild.option.gnu.cross.mcu"][@name="Mcu"]')
+    mcu_node = root.find('.//tool/option[@name="Microcontroller"]')
         mcu_str = mcu_node.attrib.get('value')
     except Exception as e:
@@ -166,7 +166,7 @@ def main():
             c_defs_subst += ' -D{}'.format(c_def_str)

     # Link script
-    ld_script_node_list = root.find('.//tool/option[@superClass="fr.ac6.managedbuild.tool.gnu.cross.c.linker.script"]')
+    ld_script_node_list = root.find('.//tool/option[@name="Linker script"]')
         ld_script_path = ld_script_node_list.attrib.get('value')
     except Exception as e:

This change helped me to generate proper Makefile

User avatar
Posts: 214
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex

Re: Cubemx -> Makefile utility

Postby sheepdoll » Sat Feb 04, 2017 7:58 pm

I just pushed my makefile script to github

The script is written in the PostScript language and optimized for running through the Ghostscript interpreter. for more info for the community pages.

I use postscript as a general purpose language such as most people would use python for. I prefer postscript for such scripting as it can parse hex and binary files directly. This tool was written for my personal use. For a more general audience I would recommend re-writing it as python.

Some notes on reading the github code. As there is only one file I would recommend reading it from inside the github as cloning it will make the script unreadable or an attempt to launch a CUPS viewer such as preview on the mac. (which for security reasons disables the file system.)
Reading the code in the github file viewer also uses syntax color highlighting, which makes the code more readable.

PostsScript is stack based and RPN syntax so the operands are pushed onto the stack and popped by the operator. The classic example is to add 2 number the syntax would be 2 2 add which would leave 4 on the top of the stack.

Postscript also uses Key value dictionaries like a SQL database. (why I love the language so much.) Dictionaries are pushed onto the stack. These can be created explicitly with a count such as 10 dict. The operand 10 is left over from Version 1 this is how many keys are in the dict.

To make the dictionary the current one the operator 'begin' is used to "open" it. Any key in the dictionary can be directly referenced. when the dictionary is open. to close a dictionary the operator end is used. There is a separate dict stack and objects can be found from any open dict. Dicts are similar to c++ objects.

Dicts can also be created with the '<<' and '>>' I call these french quotes. They are not shifts or stream markers.

Names in postscript are preceded by a slash so /nameExample is a reference these are pointers to object. Pushing nameExample on the stack will load the value from any open dictionary. The operator 'def' is used to associate a name with an object. Name keys are not executed until the def is read.

Code objects are nested inside braces '{}' these are executed when the name is loaded.

String objects are contained inside parathisis. '()'

Arrays are inside brakets '[]'

comments are preceded by a percent '%'

The top part of the github code are extensions that are mostly macros used for viewing dictionaries, Hex, binary and floating point data.

The real code starts around line 375 (\033[0;32m) print This is some code that makes the back channel print green text using ANSI escape sequences. Print '=' and '==' operators all write text to the back channel.

I also wrote some more readable file writing extensions that allow me to format the backchannel or re direct it to a printed page or file.
I named these writlin adn writef

Postscript is known as the self un-documenting language So I expect that few here will be interested in this code. I personally find it useful and find Python to be backwards and hard to follow due to the lack of code blocks and the needless use of indentations.

I wanted this code to also be able to create the pin name table code. That will require more work as I need to according to the person I talked to at STM to look inside the cube databases themselves. Ideally this tool would be directly part of the Cube Code generation, Or ST should provide hooks to generate code for any IDE from these setup files. Currently ST seems to think the user will copy the code from the code databases "repository" directory where the examples are stored. Some of this is generated automatically, Which is of minimal use as the peripherals are only partially configured.

I am still working on extending this code to create board.txt and platform.txt. Most likely that will be a separate script added to the Github folder when it is ready.

Return to “Cores”

Who is online

Users browsing this forum: No registered users and 1 guest