cancel
Showing results for 
Search instead for 
Did you mean: 

Self initializing UART with Pin Stackign

MŻbik.1
Associate II

Hello everyone,

I have not conventional question. My purpose is to create code where 2 pins are used as two different interfaces (I2C1 and USART3). I know that pin Stacking option is just theoretical as no code is generated for this interface. I found solution to it as I: 

1. Generated normal code for I2C so it works normal

2. defined huart3 struct and mx_UART3_Init all in user code brackets in usat.c /usatr.h the same as it would be generated from ioc file.

3. Code in fucntion HAL_UART_MspInit and HAL_UART_MspDeInit is generated only for one instance USART1 (My debug uart). So i added "else if" for USART3 instance as if it would be generated by cube. The trouble here is that user code bracket is only inside the "if(instance ==USART1)" 

And here is my problem code is working fine, trouble is this that every time i change something in ioc file my code from third point is deleted so i need to take care of it and add again my changes. 

Is there any way to stop cube from changing this file? Or maybe there is a bracket i can add so cube won't change my code ? 

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

You can just copy the generated usart.c to other file (myusart.c) add that into the project and exclude the generated usart.c from build.

Don't take the Cube too seriously - its present state and a decent kind of "AI assistant" are as far away as the Moon. 🙂 Keep all your project files in source control, review and revert unwanted changes.

View solution in original post

5 REPLIES 5
TDK
Guru

No way around this currently. CubeMX just doesn't support dynamic pin assignment to any real degree.

If you feel a post has answered your question, please click "Accept as Solution".

Hi TDK,

Ok if there is no such thing, maybe there is a way to just exclude usart.c from being regenerated ?

LCE
Principal

Isn't there the option in MX to "preserve" USER code in project settings, which is somehow marked with comments like "USER code begin / end"?

Pavel A.
Evangelist III

You can just copy the generated usart.c to other file (myusart.c) add that into the project and exclude the generated usart.c from build.

Don't take the Cube too seriously - its present state and a decent kind of "AI assistant" are as far away as the Moon. 🙂 Keep all your project files in source control, review and revert unwanted changes.

Hi Pavel,

actually you're right. I got so focused on making it this way that I forgot I can just make it my self in another folder. Thank you for good advice.😁