Skip to main content
ceremcem
Associate
September 26, 2020
Question

How to extract alternate function mappings from CubeMX's XML database files?

I'm using CubeMX's XML files as "Datasheets in database format" in my own "RTOS Hardware Configuration Tool". However, I couldn't find out how to extract the "Alternate Function Mapping" from those XML files:

0693W000004HS4zQAG.jpg

The `mcu/config/llConfig/ADC-STM32F0xx_DefMapping.xml` is promising but I still couldn't figure out how to translate - eg. - `GPIO_AF2_TIM5` to anything.

Any ideas?

This topic has been closed for replies.

8 replies

TDK
September 26, 2020

GPIO_AF2_TIM5 just expands to 2 through a define. Same as all other GPIO_AFx_* evaluating to x. The TIM5 part is just to make things a bit more readable. Is that what you're after?

#define GPIO_AF2_TIM3 ((uint8_t)0x02) /* TIM3 Alternate Function mapping */
#define GPIO_AF2_TIM4 ((uint8_t)0x02) /* TIM4 Alternate Function mapping */
#define GPIO_AF2_TIM5 ((uint8_t)0x02) /* TIM5 Alternate Function mapping */
#define GPIO_AF2_TIM12 ((uint8_t)0x02) /* TIM12 Alternate Function mapping */
#define GPIO_AF2_SAI1 ((uint8_t)0x02) /* SAI1 Alternate Function mapping */

"If you feel a post has answered your question, please click ""Accept as Solution""."
ceremcem
ceremcemAuthor
Associate
September 28, 2020

For example, in order to configure STM32F030F4Px's PA3 as USART1_RX, I need to set the relevant Alternate Function nibble to "1", as stated in datasheet.

What I could get from mcu/config/llConfig/GPIO-STM32F0xx_DefMapping.xml is that there are 3 "Item"s containing search word "usart1":

* An item contains "GPIO_AF0_USART1" string

* An item contains "GPIO_AF1_USART1" string

* An item contains "GPIO_AF7_USART1" string

How would I know which Item to parse?

In the file mcu/IP/GPIO-STM32F031_gpio_v1_0_Modes.xml, there is a structured data at: IP.GPIO_Pin.9 indicating the following:

0693W000004HtT8QAK.jpg

  

This allows me to conclude that I need to set AF1 in order to configure PA3 as USART1_RX. However, this information is inside a file named *STM32F031*.xml where I'm interested in STM32F030F4Px.

How can I know which "*Modes.xml" file applies to STM32F030F4Px?

ceremcem
ceremcemAuthor
Associate
September 28, 2020

Does the following information indicate that I need to refer to GPIO-STM32F031_gpio_v1_0_Modes.xml for STM32F030F4Px:

mcu/STM32F030F4Px.xml: <IP ConfigFile="GPIO-STM32F0xx" InstanceName="GPIO" Name="GPIO" Version="STM32F031_gpio_v1_0"/>

Uwe Bonnes
Chief
December 15, 2020

It is a long way to scan through the XML files. I do this in ethernut sourceforge svn head to produce headers like

#define I2C1_SCL_FUNC           3

#define I2C1_SDA_FUNC           4

...

       ((gpio == PA09) && (func == TIM1_CH2_FUNC           )) ? 1 : \

       ((gpio == PA09) && (func == I2C1_SCL_FUNC           )) ? 4 : \

       ((gpio == PA09) && (func == USART1_TX_FUNC          )) ? 7 : \

...

withe python script.

ceremcem
ceremcemAuthor
Associate
December 15, 2020

I don't get the idea here. Can you please describe the algorithm step by step?