2023-01-18 01:15 PM
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
2023-01-18 01:37 PM
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
2023-01-18 02:47 PM
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.
2023-01-18 03:53 PM
Perhaps use a table driven model for pins and module level instantiation ?
2023-01-18 11:10 PM
> 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.
2023-01-19 12:15 AM
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
2023-01-19 08:38 AM
NEVER MIND - I mis-read the original question (need a second cup of coffee!)
(original content deleted)
2023-01-19 11:07 AM
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.
2023-01-19 11:10 AM
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.