cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a shortcut in STM32CubeIDE to quickly implement declared function / method?

HTD
Senior III

In Visual Studio there is. I found there is the "Implement method" option in the IDE context menu, but it does nothing.

My project is properly configured, IDE knows where's the header and the source file. I can switch between them quickly. It's pretty annoying I have to type entire implementation by hand (or copy and paste it from the header) instead of some automatic function. It would be the best if all methods from the header would be automatically implemented as empty methods. Is it possible in STM32CubeIDE, or maybe I need a plugin for that?

10 REPLIES 10
Markus GIRDLAND
ST Employee

Hello there,

The "Implement Method" option only works with C++ so the targeted source file needs to be .cpp in order to function.

0693W00000NrulzQAB.pngI'm not sure if perhaps there's a way to do some of the work in .c files using Templates in Window -> Preferences -> C/C++ -> Editor -> Templates.

I tested it with a C++ file and nothing happens when I click on "Implement method":

0693W00000NruoFQAR.pngHere's where I right click:

0693W00000NruooQAB.pngThe file is saved, the source file exists and I can navigate to it by both "switch header / source" and pressing F12 (F3 with original bindings) on an already implemented method.

Hmm, that seems odd. Did you "convert" the project or do you have a source file with .cpp?

I haven't used this method before, I just ran a simple test when I read your question earlier today. Here's how I did my test:

I set up an empty C++ project for an F4 discovery board and just added a "test.h" and "test.cpp". From the test.cpp I added a simple

#include "test.h"

This made the project structure look like this:

0693W00000Nrv4IQAR.pngI set up two test functions in the header file:

0693W00000Nrv4wQAB.pngThis allows me to use the Implement Method option:

0693W00000Nrv5LQAR.png0693W00000Nrv5aQAB.pngThis then gets added to the test.cpp:

0693W00000Nrv5uQAB.png

And here's what I got when I try to use implement shortcut I've just made on .cpp file:

0693W00000Nrv6xQAB.pngWhile still in the .hpp file I have:

0693W00000Nrv7HQAR.png

Did you use the "Implement Method" shortcut when you have the .cpp file or .hpp file selected? It seems to make a difference in that you need to do it on the header file.

HTD
Senior III

It's already C++ project, created with TouchGFX. My header is .hpp, since it's a part of the GUI that is mostly C++. There is a bridge between C and C++ code, a one linking class that calls C function, but it's not the one I test it on. I test it on a regular C++ class that doesn't DIRECTLY link any C code (except one of the partner header references a .h header, naturally).

HTD
Senior III

What's even weirder, here's .hpp part that is NOT IMPLEMENTED:

0693W00000NrvAGQAZ.pngIt compiles without errors or warnings.

HTD
Senior III

I tried both. In .hpp it does nothing, in C++ it shows "No methods to implement".

HTD
Senior III

I guess it's probably a weird bug in STM32CubeIDE, or it just doesn't work with my specific project. There's one more thing broken: refactoring. When I try to rename a method in header - it just refuses to do so. When I rename the same method in source it does replace some occurances in code, but doesn't touch the header and I must finish the refactoring manually.

What is specific about my project:

It is created with TouchGFX for 2 core STM32H747. There are 3 project - one: a root project, mostly empty, but contains 2 projects for each core, CM4 and CM7.

Also - the headers are not visible in the project tree. The sources are links to the files. I theoretically can change the structure to include everything, but then when I generate new changes with TouchGFX designer my custom structure will be overwritten (if it conflicts with what the Designer intends to do). IDK, maybe the IDE doesn't look for includes when there are not present it its project tree. It's a bug, because the includes are specified in options, visible in Include Browser and project settings. Anyway - it finds the includes properly, but maybe it doesn't find them when any Refactor option is used.