2016-10-07 01:51 PM
Hi. I am writing my engineering thesis and I have to build a project based on STM32F746G-Discovery. So I started by creating a project in CubeMX, then writing some code in it in Keil uVision 5, wrote my own LCD libraries and so on. After that I wanted to add ADC functionality to my project, so I opened CubeMX and enabled ADC, but when I generated the code, all my ''user code'' and libraries I created just disappeared.
I made sure many times that my code is between ''user code begin'' and ''user code end'' comments, and that the checkbox ''keep user code when re-generating'' is checked.Could you please help me? I'd like to finish this project as fast as possible, but it won't be possible if everytime I want to add another peripheral I have to write my code from scratch.I am aware that I can write the peripheral definitions and initializations myself, but I didn't download CubeMX so that I have to do it by hand anyway.Greetings,Marcin2016-10-07 05:15 PM
Suggest you always have CubeMX, or any other auto-gen tool, create into a sandbox, and then use merge tools like WinMerge or Araxis Merge to manage your code in/out of generated source. Archive your project frequently.
2016-10-08 08:38 PM
Marcin,
From my article that will be going out next week:''I don’t particularly care for ST’s code style, I find putting my code into their slots pretty restrictive, so I would replace line 25 with a function call to my mainline code in another file.
24 /* USER CODE BEGIN WHILE */
25 ThermostatMain();
26 {
27 /* USER CODE END WHILE */
Even if you rerun the code generation phase of Cube, line 25 will be preserved. Then in my code, probably in a file called thermostat.c in my
source
directory, I would have a function called ThermostatMain() which would contain my normal FOREVER loop structured code.''
Well, at least I thought it would be preserved.So, my suggestion is to create your own source and include directories and put all of your code there instead of the Src and Inc directories that Cube creates.In main, get out as soon as possible, replace the while (1) with a subroutine call and don't ever touch the Cube generated files again.Frankly, and I've said this before here, the generated code from Cube should not create main(). Some RTOS' provide main and take care of a bunch of stuff before giving the processor over to your application. Cube should have generated stuff that my code calls. But, too late now. Let's work around it.Andrei from The Great White North(as seen on the embedded.fm podcast and blog)