2023-07-23 01:03 AM
Hello
I am using CubeIde and cubeMx on a project for several years with no issues.
But I am facing today a limit of CubeMx:
On a STM32L431RCTx I need to have UART2_RX on PA15 and PA2 as GPIO_EXT, not as UART2_TX. CubeMX forces me to have PA2 as UART2_TX :(
I also can't easily use "USER CODE BEGIN/END" areas because CubeMX uses elseif which I can't split (see attached image)
1) Is there a trick to mixing MX setups and personal setups (and this "elseif" not nice)?
2) Is it better to configure everything manually? if so, what is the best practice?
Thank you very much in advance
PS : I'm using CubeID3 1.13 with STM32Cube FW_L4 V1.18.0
2023-07-23 01:43 AM
and can you (i dont have this chip, but all similar ) define in Cube half duplex? then only one pin is used.
2023-07-23 01:56 AM
2023-07-23 02:03 AM
yepp, on half duplex the "TX" pin is used, pa2 here. but now you get pa15 free to use...for exti.
or try alternate pin: first set uart ...as it wants. pa2+15 . then hold ctrl key and click mouse on the pa2 pin + hold key, then blinking all possible alternative pins. if this is something you like, just click on the alternative pin and select ...uart..here. then it uses this pin.
2023-07-23 02:07 AM
Selecting half duplex MX selects PA2!
PA2 in the only pin for USART2_TX and MX persists in selecting this pin when USART2 is selected.
If we put PA2 in reset state USART2 is automatically disabled.
Same behavior with USART3.
It seems that MX does not allow to use an UART for RX only. For me it's a bug... Because I commonly do it without using MX.
2023-07-23 02:11 AM
Yes, no alternative for USART2_TX and I don't have free pin
2023-07-23 02:16 AM
I imagined 2 solutions to bypass CubeMX:
1) Check "Do not generate the main" in Cube MX and rebuild a main that uses some of what CubeMX generated and some of my own code.
2) Let CubeMx generate the initializations and override at the end with my own modifications
Could one of these solutions be the correct one? what else ?
2023-07-23 02:45 AM
if Cube otherwise doing good job for you, i would keep it,
and set uart as it likes.
then after init in main you write to port mode (MODER..) and switch mode for pa2 -> input.
and set exti 2 . and write void EXTIx_x_IRQHandler(void) in xxxit.c .
2023-07-23 02:47 AM
For normal mode selecting "Receive Only" or "Transmit Only" doesn't release the respective unneeded pin. For "Single Wire (Half-Duplex)" mode enabling the "TX and RX Pins Swapping" doesn't move the single allocated pin from Tx pin to Rx pin, which is what the hardware actually does. That's just what RubeMX is. And what's the point of all of this contraption? The HAL broken bloatware cannot receive USART stream without ridiculous hacks anyway. Toss it all away and develop a useful and working code:
https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx
CubeID3
How can "E" be misunderstood for "3"? Does your eyesight mirror some single letters?
2023-07-23 02:58 AM
There's ID3 in my company name, fingers go faster than eyes
I'll attempt an overload of what CubeMX does.
Little by little the overload will be able to take more and more things from cubeMX.