cube2chibi - convert STM32 CubeMX project to board.chcfg

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
crispus
Posts: 24
Joined: Sat Aug 27, 2016 10:14 am
Has thanked: 4 times
Been thanked: 3 times

cube2chibi - convert STM32 CubeMX project to board.chcfg

Postby crispus » Fri Oct 14, 2016 7:25 pm

Hi,

I created (another) script to convert from a STM32 CubeMX project (*.ioc) to the ChibiOS board file configuration file (*.chcfg).

It updates board.chcfg the following:
- templates path
- HSE/LSE clocks
- VDD
- ports / pins

One nice feature is that you don't need to search trough the datasheet after the alternate function number :)
I run the script with *.ioc found in the STM32CubeMX folder and it works.

The flow of the script is:
  1. Parse .ioc file and create a dictionary
  2. Find MCU part number in the dictionary
  3. Parse db/mcu/families.xml and find the MCU's xml description file
  4. Parse the MCU xml description file
  5. Parse the MCU GPIO xml
  6. Update MCU properties from the dictionary
  7. Mix the information with the existing chibi config file if provided
  8. Save new chibi config file
Known issues:
- Can't yet recognize the alternate function for the STM32F1xx family

TODO:
- Convert CubeMX IPs settings to ChibiOS IPs config

The script can be found here: https://github.com/cburlacu/cube2chibi

Suggestions / issues / patches / forks / pull requests are welcome :)
(Python is not my native language :) )

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: cube2chibi - convert STM32 CubeMX project to board.chcfg

Postby Giovanni » Fri Oct 14, 2016 7:53 pm

Hi,

This looks really useful.

Few ideas:
- Make it an Eclipse plugin, or add it to the existing board files generator plugin as an "import settings" option.
- Do the same with RCC clock settings and create an XML that could be used to generate an mcuconf.h. Problem is that the clock tree is different in each sub-family.

Anyway, if it could be made usable from Eclipse I would gladly include it in ChibiStudio.

Giovanni

crispus
Posts: 24
Joined: Sat Aug 27, 2016 10:14 am
Has thanked: 4 times
Been thanked: 3 times

Re: cube2chibi - convert STM32 CubeMX project to board.chcfg

Postby crispus » Thu Oct 20, 2016 4:01 pm

Hi Giovanni,

I have no experience with eclipse plugins, just a little of java, but I can look into it.
Some questions:
1. Are the sources available for the board file generator plugin?
2. How do you generate mcuconf.h? Is there an example for the xml, or a template?

Thanks,
Cezar

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: cube2chibi - convert STM32 CubeMX project to board.chcfg

Postby Giovanni » Fri Oct 21, 2016 7:51 am

Hi,

All ChibiStudio plugins are available as Eclipse project here: https://svn.code.sf.net/p/chibios/svn/b ... udio_trunk

mcuconf.h is not currently generated but it could be generated exactly like we do for board files, code generation is done using a templates processor called FreeMarker: http://freemarker.org/
FreeMarker is incredibly useful and is already integrated in ChibiStudio plugins.

Giovanni

mobyfab
Posts: 483
Joined: Sat Nov 19, 2011 6:47 pm
Location: Le Mans, France
Has thanked: 21 times
Been thanked: 30 times

Re: cube2chibi - convert STM32 CubeMX project to board.chcfg

Postby mobyfab » Fri Nov 18, 2016 3:28 pm

Very nice, I'll have a look

omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

Re: cube2chibi - convert STM32 CubeMX project to board.chcfg

Postby omcdr » Wed Nov 30, 2016 10:07 pm

I'm trying to use cube2chibi, but I have got errors:

Code: Select all

d:\tmp\cube2chibi-master>python cube2chibi.py

Traceback (most recent call last):
  File "cube2chibi.py", line 20, in <module>
    import cube
  File "d:\tmp\cube2chibi-master\cube.py", line 118
    print "Invalid description - %s / %s " % (self.Pin, signal)
                                         ^
SyntaxError: invalid syntax


I have changed to:

Code: Select all

 print ("Invalid description - %s / %s " % (self.Pin, signal))


next:

Code: Select all

d:\tmp\cube2chibi-master>python cube2chibi.py
Traceback (most recent call last):
  File "cube2chibi.py", line 20, in <module>
    import cube
  File "d:\tmp\cube2chibi-master\cube.py", line 22, in <module>
    from utils import *
  File "d:\tmp\cube2chibi-master\utils.py", line 69
    print ex
           ^
SyntaxError: Missing parentheses in call to 'print'


I have changed to:

Code: Select all

print(ex)


Now I have
TypeError: unorderable types: tuple() >= int()

I don't have idea how to fix it . Can you help ?

Code: Select all

d:\tmp\cube2chibi-master>python cube2chibi.py --ioc p:\chibios\boards\STM32F405_tecu\usb405.ioc --cube "d:\STM32CubeMX"
Starting to parse p:\chibios\boards\STM32F405_tecu\usb405.ioc
STM32F405RGTx
Loading STM32F405RGTx
Loading d:\STM32CubeMX/db/mcu/families.xml
Loading d:\STM32CubeMX/db/mcu/STM32F405RGTx.xml
GPIO version is 'STM32F417_gpio_v1_0'
Loading d:\STM32CubeMX/db/mcu/IP/GPIO-STM32F417_gpio_v1_0_Modes.xml
STM32F405RGTx has 64 pins
STM32F405RGTx has 60 pins (64) (4 duplicates - dict_keys(['VSS', 'VDD']))
PB0: property GPIOParameters is not used? PinState,GPIO_PuPd,GPIO_Label
Traceback (most recent call last):
  File "cube2chibi.py", line 71, in <module>
    processFile(iocFile, args.chibi, args.output)
  File "cube2chibi.py", line 50, in processFile
    mcu.updateProperties(properties)
  File "d:\tmp\cube2chibi-master\cube.py", line 208, in updateProperties
    pin.update(gpioProp, props[key])
  File "d:\tmp\cube2chibi-master\cube.py", line 135, in update
    self.Mode = self.getModeFromSignal(value)
  File "d:\tmp\cube2chibi-master\cube.py", line 109, in getModeFromSignal
    if m and m.groups() >= 1:
TypeError: unorderable types: tuple() >= int()

crispus
Posts: 24
Joined: Sat Aug 27, 2016 10:14 am
Has thanked: 4 times
Been thanked: 3 times

Re: cube2chibi - convert STM32 CubeMX project to board.chcfg

Postby crispus » Wed May 17, 2017 11:28 am

I was busy lately with some other projects.

The script was used with python 2.7, and I think the errors were from python 3.
I updated the script and it seems to work with python 3 as well (3.5.3).

https://github.com/cburlacu/cube2chibi.git


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 7 guests