2023-10-25 02:00 AM
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 ?
Solved! Go to Solution.
2023-10-26 12:50 AM - edited 2023-10-26 12:56 AM
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.
2023-10-25 08:08 PM
No way around this currently. CubeMX just doesn't support dynamic pin assignment to any real degree.
2023-10-25 11:56 PM
Hi TDK,
Ok if there is no such thing, maybe there is a way to just exclude usart.c from being regenerated ?
2023-10-26 12:17 AM
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"?
2023-10-26 12:50 AM - edited 2023-10-26 12:56 AM
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.
2023-10-26 02:11 AM
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.:beaming_face_with_smiling_eyes: