cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting available UARTs at compile time

GoEk
Associate III

Hi,

using CubeIDE with CubeMX, is is possible to "check" or "detect", for conditional compiling, which UART ports that are enabled? In the MX-generated USART.C you will find all the handles for the available UARTs but AFAIK, you can't conditional compile on the existence of variables, only #defines. Then, in the stm32h750xx.h (H750 in my case) you can find #defines for the UART ports but that is ALL the MCU's ports, not only used ones.

Regards,

Goran

8 REPLIES 8
KnarfB
Principal III

This may be a trick, but if you give the pins a user label, that label is a define you can test for.

#ifdef USART1_RX_GPIO_Port
...
#endif

defined in main.h

hth

KnarfB

GoEk
Associate III

Thanks. Well, it could possibly work for a single project since you have to match the pin labels from MX, I was aiming for solution that would work on any project, without customization; sort of library code.

Perhaps use a table driven model for pins and module level instantiation ?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

>  I was aiming for solution that would work on any project, without customization; sort of library code.

You can add custom defines to Cube-generated project and make some convention with the library code.

For example you can define a UART number and baudrate that the library should use.

Also as KnarfB wrote, user-defined pin names can serve for this.

Javier1
Principal

I am not sure why you want to do this, doesnt cubeMX generate only the variables for the active UARTs? I have never played with an stm32H7 so maybe im missing something.

what about creating a #define in cubeMx and then playing around with #ifdef's

0693W00000Y8cfYQAR.png 

0693W00000Y8cgWQAR.png 

we dont need to firmware by ourselves, lets talk
Bob S
Principal

NEVER MIND - I mis-read the original question (need a second cup of coffee!)

(original content deleted)

I am creating a service class for UARTs and in that class I have tables with "stuff". Sure, I could always size this table to hold all UARTs available in the MCU but that wastes memory and is ugly. What I wanted was a way, in any application that uses this class, to detect the actual number of ports "activated" in CubeMX.

GoEk
Associate III

I have more or less chosen that way but instead of doing all the customization in MX, I will have a Defines class included into my main class. In that way, everything is collected in a single source file.