STM32CubeIDE: retarget to a different MCU - Page 1
Forum section: electronics / general

author: aix
author_rank: Regular Contributor
timestamp: January 30, 2020, 08:19:16 am
content: Is there a way to retarget an STM32CubeIDE project to a different MCU? The official answer seems to be "no", but I wonder if there's still a practical way to do it (or at least to migrate user code between projects).For a project, I want to use the smallest STM32 package that's large enough. But what happens if I do run out of pins — is there a way to migrate the firmware project to the next-larger package without copying & pasting every block of user code by hand?

author: thm_w
author_rank: Super Contributor
timestamp: January 30, 2020, 09:14:15 pm
content: You could try manually editing the .ioc project file, and see if it lets you regenerate. Of course make a back up copy of everything first.Code:#MicroXplorer Configuration settings - do not modifyFile.Version=6KeepUserPlacement=falseMcu.Family=STM32F2Mcu.Name=STM32F207V(C-E-F-G)TxMcu.Package=LQFP100

author: TK
author_rank: Super Contributor
timestamp: January 30, 2020, 09:30:53 pm
content: Quote from: aix on January 30, 2020, 08:19:16 amIn case changing the device on the .ioc file does not work, you need to respect the areas where the generated code reserves for user added code. I was able to migrate many times the device by creating a new project with the new device, then copy paste the user reserved areas only.

author: rcbuck
author_rank: Frequent Contributor
timestamp: January 30, 2020, 10:18:04 pm
content: I went through this about a week ago and could not find any way to switch processors. I finally ended up going the copy/paste route for main.c and main.h.Make a copy of the entire project folder and move it to another directory. Then in the STM32CubeIDE program delete the project from the Workspace. Answer "No" when it asks if you want to delete the files from the disk. Then close STM32CubeIDE and move the project folder to another location on the disk. You now have two backup copies.Hopefully you are not using the default location for your projects. I create all of my projects in a folder I have named CubeMX Projects. Each project has its own folder underneath that folder.You will have to copy/paste the main.c and main.h stuff. Do that only after you have setup and generated the code for the .ioc file. You can then simply copy all of the other .c and .h files from the old project to the new project. After you do that, just use File -> Open File... and open each of the files you copied over to the new project folder. Once you do that, they will then be part of the new project and will show up in the Src and Inc folders.

author: IgorM
author_rank: Newbie
timestamp: October 01, 2021, 07:17:11 am
content: May be this will help. Chapter 15 from UM1718 STM32CubeMX "User manual":Tutorial 5: Exporting current project configuration to a compatible MCU.When List pinout compatible MCUs is selected from the Pinout menu, STM32CubeMX retrieves the list of the MCUs which are compatible with the current project configuration, and offers to export the current configuration to the newly selected compatible MCU.This tutorial shows how to display the list of compatible MCUs and export your current project configuration to a compatible MCU:1. Load an existing project, or create and save a new project.2. Go to the Pinout menu and select List Pinout Compatible MCUs. The Pinout compatible window pops up. If needed, modify the search criteria and the filter options and restart the search process by clicking the Search button. The color shading and the Comments column indicate the level of matching:– Exact match: the MCU is fully compatible with the current project.– Partial match with hardware compatibility: the hardware compatibility can be ensured but some pin names could not be preserved. Hover the mouse over the desired MCU to display an explanatory tooltip.– Partial match without hardware compatibility: not all signals can be assigned to the exact same pin location and a remapping will be required. Hover the mouse over the desired MCU to display an explanatory tooltip.3. Then, select an MCU to import the current configuration to, and click OK, Import. The configuration is now available for the selected MCU.4. To see the list of compatible MCUs at any time, select Outputs under the Window menu. To load the current configuration to another compatible MCU, double-click the list of compatible MCUs.5. To remove some constraints on the search criteria, several solutions are possible:– Select the Ignore Pinning Status checkbox to ignore pin status (locked pins).– Select the Ignore Power Pins checkbox not to take into account the power pins.– Select the Ignore System Pins not take into account the system pins. Hover the mouse over the checkbox to display a tooltip that lists the system pins available on the current MCU.

author: peter-h
author_rank: Super Contributor
timestamp: October 01, 2021, 03:32:53 pm
content: The reason I post few solutions here is because there are so many people here who know so much more than I doHowever (having spent last 9 months on Cube IDE) it should not be too hard to retarget to a different package of the same chip, if say you discover you need more pins, or want to downsize a package.You can select the Alternate Function for any GPIO pin. It's far from obvious but with enough staring at the data sheet one can work it out.Going to a different chip needs a change to the "HAL" stuff.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 01, 2021, 06:08:09 pm
content: You can relatively easily retarget a project if using the HAL, outside of STM32Cube. It's actually one benefit of using the HAL (there are some drawbacks too.) As long as the parts are "equivalent" (both have the peripherals and features you use in your project), it's often just a matter of redefining the macro for the part used. Then you can use macros to redefine some things, such as IOs, if need be, depending on the part. And your project becomes flexible without even having to duplicate it.I do not use STM32Cube and never recommend it. It's a huge mess. The fact it wouldn't apparently let you retarget a project, while the underlying libraries have been written just to ease that, is mind-boggling. But ideally, it would even let you define "variants" for your project, as I suggest above.Develop your projects outside of STM32Cube and the pain will be gone. The time investment to do this will be worth it.

author: Jeroen3
author_rank: Super Contributor
timestamp: October 01, 2021, 06:48:59 pm
content: It's actually quite easy to use the STM32CubeIDE code generator and put your actual application source codeoutsidethe generated project.You just have to accept the way how eclipse creates makefiles.Then you could just create multiple target projects, while linking to the same application code. And compile them all at once!I wasn't successfull on compiling and running any unit-test projects like this from stm32cubeIDE, but that is probably because of Windows, should be trivial on linux.