Skip to main content
GoEk
Associate III
Jan 18, 2023 9:15 PM UTC
Question

Detecting available UARTs at compile time

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

This topic has been closed for replies.

8 replies

KnarfB
Super User
Jan 18, 2023 9:37 PM UTC

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
GoEkAuthor
Associate III
Jan 18, 2023 10:47 PM UTC

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.

Tesla DeLorean
Guru
Jan 18, 2023 11:53 PM UTC

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

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Javier1
Principal
Jan 19, 2023 8:15 AM UTC

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 

hit me up in https://www.linkedin.com/in/javiermuñoz/
GoEk
GoEkAuthor
Associate III
Jan 19, 2023 7:07 PM UTC

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.

Bob S
Super User
Jan 19, 2023 4:38 PM UTC

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

(original content deleted)