Skip to main content
Ciuffoly
Senior
March 22, 2020
Solved

[SOLVED] How to obtain the Project name ?

  • March 22, 2020
  • 2 replies
  • 2324 views

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); 
}

This topic has been closed for replies.
Best answer by berendi

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.

2 replies

berendi
berendiAnswer
Principal
March 22, 2020

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.

Ciuffoly
CiuffolyAuthor
Senior
March 22, 2020

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);
}