I have a full functional project on STM32L4R5 on custom board running since 2017.
The code initially was generated once from CubeMX + Cube/HAL and then evolved through IAR IDE. Recently, someone asked me to migrate to 2020 Cube IDE / Gcc and for the rare ones in the same situation, share my way of going there (and save some hours of eclipse discovery).
This my quick step by step. I didn't want to "import" as I wanted to get a refresh of HAL version.
Here is what I learnt over 1.5 day of struggling through the IDE eclipse based project creation and merge....
- Backup your IAR project folders (zip them)
- Open your reference IAR project source code which has old CubeMX source files
- Prefferably, each of the STM32 peripherals have their own generated C file (uart.c, spi.c...)
- Open a file explorer to the source files directories if possible, all the non cube generated code should be on a specific subfolder
- In this subfolder, remove all the *.c and *.h which are not used in IAR IDE, or rename their file extension in uppercase *.C and *.H to be later excluded from CubeIDE.
- Open the main.c and the ***_it.c (the ISR list) in IAR source editor.
- Create a CubeIDE project, select your board MCU / package / memory size
- First, define manually all the pins you use on the package
- Second, enable the peripherals your use (this way, the default GPIO will be the ones you already predefined)
- Third, in the project advanced, decide which peripheral uses HAL or LL
- Go to the clock page and don't use the automatic mode, get the clock tree setup correctly now
- Open the *_IT.C file (ISR functions)
- In the file, from top to bottom of the file, you will have the SYSTICK and other peripheral ISR. In CubeIDE/MX, activate the interrupts that are present in the same order. If there is DMA ISR, add them to each peripheral in the SAME top to bottom file order.
- Generate the code with one source per peripheral and compare with IAR source files to check all is similar
- To build all CTRL+B
- There should be no error and you should be able to go in debug mode.
- Close CubeIDE and zip Cube IDE User project as backup step.
- Now open your IAR user source folder and subfolders, excluding the cubeMX files.
- Copy the user source folder
- Paste it in your CubeIDE project folder
- In Cube IDE, click and select the project (blue icon top left)
- Push F5 : All the new files will be added to the project (as exclude from build by default)
- Select on CubeIDE your added user top source folder
- Right click and edit properties. Uncheck the "Exclude from build" check mark
- The folder icon will have a blue disk on it.
- Please note that IAR source file group wont be imported. The folder view on the CubeIDE is like file explorer and real directories. (virtual folders is more advanced)
- Now like in IAR, you need to have a default compiler paths setup.
- Click on the project blue icon
- Right click and select "properties"
- Open C/C++ Build
- Select Settings
- Click on tools settings
- Select MCU GCC compiler / Include Path
- Add all the user folders containing user h or c file
- Review all the added user files to the project, remove the ones which are not part of IAR
- Then Generate Code
- Then Run debug mode, you should be able to go to the beginning of main()
- Close debug and now edit manually main.c and the *_it.c files to math IAR equivalent
- Before compiling, some gcc specifics
- static functions should also use static in their declaration
- int is different than int32_t
- main.c uses void Error_Handler(void) while old code used void _Error_Handler(a,b) so adapt your code
- Now rebuild all (you can use clean menu command for this)
- Fix all errors and get to build without errors
- open debugger and make sure you can go to the beginning of main
- Close cube IDE and zip it as backup restore point
- Now you can start debugging. gcc and IAR are different in code speed and performace,even if compile optimisation are both disabled for easier debug/breakpoint.
I hope these simpe tips help people migrate faster than the 12 hours hard learning with 3 from scratch retrials done so far.
If this helps a bit, let me know.