Page 1 of 1

cube2chibi - convert STM32 CubeMX project to board.chcfg

Posted: Fri Oct 14, 2016 7:25 pm
by crispus
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 :) )

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

Posted: Fri Oct 14, 2016 7:53 pm
by Giovanni
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

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

Posted: Thu Oct 20, 2016 4:01 pm
by crispus
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

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

Posted: Fri Oct 21, 2016 7:51 am
by Giovanni
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

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

Posted: Fri Nov 18, 2016 3:28 pm
by mobyfab
Very nice, I'll have a look

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

Posted: Wed Nov 30, 2016 10:07 pm
by omcdr
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()

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

Posted: Wed May 17, 2017 11:28 am
by crispus
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