How to port STM32CubeMX output to Mbed?

I have an existing project, implemented on top of Mbed OS 5.15. I need to add more interfaces, so I need to change processor package to a higher pincount one.

Currently, the pinout is defined on PeripheralPins.c etc files, which were first automatically created, then manually edited to reflect the current need. All this was done by other team, which is not anymore available. I planned the new pinout with STM32CubeMX, as it became too difficult to manually map alternative pins, as some interfaces overlap primary pins of others.

So to the question. The PeripheralPins.c file is created from xml files, which are stored in STM32CubeMX directory tree, using the STM32_gen_PeripheralPins.py script. Can I somehow take the STM32CubeMX project output, as input for PeripheralPins.py script, and create new PeripheralPins.c (etc) files?

Or, what is the proper way to convert STM32CubeMX project to Mbed’s PeripheralPins.c (etc) files?

PeripheralPins.c has no code, only const tables.
The tables are for each peripherial (i2c, adc, uart, etc), and then each pin that can be assigned to that peripheral. I think maybe STM32CubeMX actually assigns each pin to a peripheral? In mbed, the assignment is done by software when you instantiate a driver, the pins used are given in the driver constructor. The PeripheralPins.c is a map between pin and the peripheral to be used (ie, UART1 vs UART2) and the alternate function number, and pullup or down.

On mbed each board has its own pin map in PeripheralPins.c because each MCU device has its own pins available, but also the board only connects certain pins, and some of those pins are used for fixed functions.

Yes. This is because most of pins have several functions and the processor needs to be configured, which pins are used for which peripherals. For example, in some embedded Linuxes, dtb files (in /boot directory) map these, and the mapping recipes come from processor configuration program.

This may be true for ready-made prototyping boards, but for tailored embedded boards, those need to be acquired from somewhere else.

I just can’t believe, there would not be any way to import the processor configuration program output to Mbed compilation, as it is just too much manual work (=potential errors) to edit those bits and pieces to various drivers.

I also find the MCU configuration software very useful, but since Mbed is platform-independent, it is probably very hard to support all the individual config tools of all platforms. AFAIK there is no established tooling for this conversion.

Hi @jeromecoutant

Do you have any idea about this?

Thanks,
Kalle

Hi
Maybe you could have a look on

–custom option goal is to take in input ioc file from CubeMx

2 Likes

Hi, thanks. This was very good hint.

We are using Mbed 5.15 and for that version, there is no -custom option yet. Does the newer version’s STM32_gen_PeripheralPins.py work with older versions, i.e. does it generate proper files for those?

I would say script should work with all mbed-os version

Hi Jerome

Now it seems, that I got on the proper track. I fetched the latest script (along with mbed-os master) and executed it, and got the following error:

<myprompt>$ python mbed-os/targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py -c lqfp144_v001.ioc

    Script version 1.17
    CubeMX DB version DB.6.0.0

     * Board file: 'lqfp144_v001.ioc'
     * Output directory: /mnt/c/git/targets_custom/TARGET_STM/TARGET_STM32H7/TARGET_STM32H743xI/TARGET_
    .xml'nerating PeripheralPins.c and PinNames.h with '/mnt/c/Program Files/STMicroelectronics/STM32Cube/STM32CubeMX/db/mcu/STM32H743ZITx

    .xml doesn't existbeMX file. File /mnt/c/Program Files/STMicroelectronics/STM32Cube/STM32CubeMX/db/mcu/STM32H743ZITx
     ! ! ! Check in /mnt/c/Program Files/STMicroelectronics/STM32Cube/STM32CubeMX/db/mcu

The next step would then be to just debug the py script, but at least now I know, where to proceed. Thanks.:slight_smile:

This documentation is very helpful! I never stumbled upon this before, I think this should be linked somewhere more visible in the Mbed documentation.

2 Likes