cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] How to obtain the Project name ?

There is the macro __FILE__ to know the complete path of the source code but how to estract only the project name of CubeWorkspace ?

I would like to display this on my develop phase to be sure of the version running.

On Arduino Due I have used this code but with STM32 is not easy:

void display_Running_Sketch (void)
{
  String the_path = __FILE__;
  String the_date = __DATE__;
  String the_time = __TIME__;
  String ver;
  
  int slash_loc = the_path.lastIndexOf('\\');
  
  String the_cpp_name = the_path.substring(slash_loc+1);
  
  int dot_loc = the_cpp_name.lastIndexOf('.');
  
  String the_sketchname = the_cpp_name.substring(0, dot_loc);
 
  ver = the_sketchname + " " + the_date + " " + the_time;
 
  myGLCD.setFont((unsigned char *)SmallFont);
  myGLCD.setColor(255, 255, 255);
  myGLCD.print((const char *)ver.c_str(), CENTER, 1);    
 
  delay(1000);
 
  myGLCD.print((char *)"                            ", CENTER, 1);    
}

1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

The Eclipse IDE (on which CubeIDE is based) has a predefined macro ${ProjName} that you can assign to a C macro.

Navigate to

Project / Properties / C/C++ Build / Settings / Tool Settings / MCU GCC Compiler / Preprocessor

Set the Configuration line at the top to [ All configurations ]

Use the green + symbol next to Define symbols (-D) and enter

PROJECTNAME="${ProjName}"

Now you can use the PROJECTNAME macro as a string value in your project.

View solution in original post

2 REPLIES 2
berendi
Principal

The Eclipse IDE (on which CubeIDE is based) has a predefined macro ${ProjName} that you can assign to a C macro.

Navigate to

Project / Properties / C/C++ Build / Settings / Tool Settings / MCU GCC Compiler / Preprocessor

Set the Configuration line at the top to [ All configurations ]

Use the green + symbol next to Define symbols (-D) and enter

PROJECTNAME="${ProjName}"

Now you can use the PROJECTNAME macro as a string value in your project.

Very good, thank you

void LCD_LOG_Ver2()
{
	BSP_LCD_SetFont (&LCD_LOG_TEXT_FONT);
	BSP_LCD_SetTextColor(LCD_LOG_TEXT_COLOR);
	BSP_LCD_DisplayStringAt(5, 5, (uint8_t *)PROJECTNAME, CENTER_MODE);
}