cancel
Showing results for 
Search instead for 
Did you mean: 

Shared experience: Migrating from 2017 CubeMX + IAR project to 2019 CubeIDE/Gcc

S.Ma
Principal

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....

  1. Backup your IAR project folders (zip them)
  2. Open your reference IAR project source code which has old CubeMX source files
  3. Prefferably, each of the STM32 peripherals have their own generated C file (uart.c, spi.c...)
  4. Open a file explorer to the source files directories if possible, all the non cube generated code should be on a specific subfolder
  5. 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.
  6. Open the main.c and the ***_it.c (the ISR list) in IAR source editor.
  7. Create a CubeIDE project, select your board MCU / package / memory size
  8. First, define manually all the pins you use on the package
  9. Second, enable the peripherals your use (this way, the default GPIO will be the ones you already predefined)
  10. Third, in the project advanced, decide which peripheral uses HAL or LL
  11. Go to the clock page and don't use the automatic mode, get the clock tree setup correctly now
  12. Open the *_IT.C file (ISR functions)
  13. 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.
  14. Generate the code with one source per peripheral and compare with IAR source files to check all is similar
  15. To build all CTRL+B
  16. There should be no error and you should be able to go in debug mode.
  17. Close CubeIDE and zip Cube IDE User project as backup step.
  18. Now open your IAR user source folder and subfolders, excluding the cubeMX files.
  19. Copy the user source folder
  20. Paste it in your CubeIDE project folder
  21. In Cube IDE, click and select the project (blue icon top left)
  22. Push F5 : All the new files will be added to the project (as exclude from build by default)
  23. Select on CubeIDE your added user top source folder
  24. Right click and edit properties. Uncheck the "Exclude from build" check mark
  25. The folder icon will have a blue disk on it.
  26. 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)
  27. Now like in IAR, you need to have a default compiler paths setup.
  28. Click on the project blue icon
  29. Right click and select "properties"
  30. Open C/C++ Build
  31. Select Settings
  32. Click on tools settings
  33. Select MCU GCC compiler / Include Path
  34. Add all the user folders containing user h or c file
  35. Review all the added user files to the project, remove the ones which are not part of IAR
  36. Then Generate Code
  37. Then Run debug mode, you should be able to go to the beginning of main()
  38. Close debug and now edit manually main.c and the *_it.c files to math IAR equivalent
  39. Before compiling, some gcc specifics
  40. static functions should also use static in their declaration
  41. int is different than int32_t
  42. main.c uses void Error_Handler(void) while old code used void _Error_Handler(a,b) so adapt your code
  43. Now rebuild all (you can use clean menu command for this)
  44. Fix all errors and get to build without errors
  45. open debugger and make sure you can go to the beginning of main
  46. Close cube IDE and zip it as backup restore point
  47. 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.

2 REPLIES 2
S.Ma
Principal
STOne-32
ST Employee

Bonjour,

Many thanks for this valuable contribution to our STM32 Community, I’m quite sure that is very useful to many of us . Please send us your address, we have a Nucleo Gift for you .@Amel NASRI​ @Imen DAHMEN​ 

Cheers,

STOne-32.