2025-01-29 01:18 AM
Dear Sir,
Hardware: STM32H7B3I-DK
Software: STM32MX 6.13.0 / STM32CubeIDE 1.17.0 / TouchGFX 4.24.1/ STM32Cube_FW_H7_V1.12.0
Start the project from TouchGFX, and then refer to STM32 Graphics Workshop (STM32H7BWorkshop2020_labs12345), to develop the details in Model.hpp, ModelListener.hpp, Model.cpp, and main.c, etc. Aiming to display a data from hardware side on the screen, at this stage it is just a float constant (as can be seen in main.c), later it will be data from an external ADC.
The project can display a float constant (the 1.5555) in the Simulator on TouchGFX (refer to Model.cpp file), but in STM32CubeIDE, there are 2 build errors as show below (As a result, unable to show the float constant from main.c on the screen.):
(Copy from the Console of STM32CubeIDE after build):
C:/TouchGFXProjects/ADC_Output_Display/TouchGFX/gui/src/model/Model.cpp:30: undefined reference to `Adc_Output_GetValue'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:103: STM32H7B3I-DK.elf] Error 1
"make -j2 all" terminated with exit code 2. Build might be incomplete.
17:19:18 Build Failed. 2 errors, 1 warnings. (took 29s.943ms)
The Adc_Output_GetValue() has already been defined both in Model.cpp and main.c; so not sure what means the: undefined reference to ‘Adc_Output_GetValue’; and do not know what to do next.
Also do not understand the meaning of:
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:103: STM32H7B3I-DK.elf] Error 1
Could you please provide your advice, and suggestion about what to do?
Thank you very much for your attention and support.
With best regards
EY1
P.S.
The print screen for above project:
Simulator result:
STM32CubeIDE Build Results (below 2):
Also enclosed in the attachment is main.c
Model.cpp and Model.hpp are not allow to attach, due to the cpp and hpp extension.
So, enclose the Model.cpp content below:
Model.cpp
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
extern "C" {
extern float Adc_Output_GetValue(void);
}
Model::Model() : modelListener(0)
, tickCounter(0)
{
}
void Model::tick()
{
tickCounter++;
if ((tickCounter % 20) == 0)
{
if (modelListener != 0)
{
modelListener->notifyAdc_VoltChanged(getNewAdc_Volt());
}
}
}
float Model::getNewAdc_Volt()
{
#ifndef SIMULATOR
return Adc_Output_GetValue();
#else
// Implementation for simulator
return 1.5555;
#endif /*SIMULATOR*/
}
Thank you very much for your time and help.
2025-01-30 04:54 AM
Hello @EY1 ,
Remember, when you are posting code, please use the code formatting for better readability.
For your issue, in the simulator it work because it do not tries to get the real value. In the model try to add directly "include <main.h>" in the extern.
Best regards,
Louis B.
2025-01-30 05:57 AM - edited 2025-01-30 06:11 AM
Do you have the actual function defined in main.c? All I can see from what you posted is a declaration.
EDIT. Actually I see the problem from your main.c, you need to move your function definition to outside of main().
You have it defined in the while(1) loop, which is the wrong place. Put the definition outside of main and it should at least build, you can also remove the HAL_Delay:
float Adc_OutPut_GetValue(void);
float Adc_OutPut_GetValue(void)
{
return 3.1416;
}
2025-01-30 06:01 PM
Thank you LouisB and AMars.4 for your reply.
I have added #include <main.h>" in the extern in Model.cpp
and have moved the function out of the while(1) loop, first place it under /* USER CODE BEGIN 5 */ not working, then place the function under /* USER CODE BEGIN 1 */ inside int main(void); it still can not build. Getting the similar build errors from STM32CubeIDE:
C:/TouchGFXProjects/ADC_Output_Display/Core/Src/main.c:129:9: warning: 'Adc_OutPut_GetValue' defined but not used [-Wunused-function]
129 | float Adc_OutPut_GetValue(void)
| ^~~~~~~~~~~~~~~~~~~
C:/TouchGFXProjects/ADC_Output_Display/TouchGFX/gui/src/model/Model.cpp:31: undefined reference to `Adc_Output_GetValue'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:103: STM32H7B3I-DK.elf] Error 1
"make -j2 all" terminated with exit code 2. Build might be incomplete.
11:22:34 Build Failed. 2 errors, 2 warnings. (took 17s.333ms)
Below the two print screens from STM32CubeIDE:
Enclosed also Model.cpp (as shown below) and the main.c as an attachment.
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
extern "C" {
#include <main.h>
extern float Adc_Output_GetValue(void);
}
Model::Model() : modelListener(0)
, tickCounter(0)
{
}
void Model::tick()
{
tickCounter++;
if ((tickCounter % 20) == 0)
{
if (modelListener != 0)
{
modelListener->notifyAdc_VoltChanged(getNewAdc_Volt());
}
}
}
float Model::getNewAdc_Volt()
{
#ifndef SIMULATOR
return Adc_Output_GetValue();
#else
// Implementation for simulator
return 1.5555;
#endif /*SIMULATOR*/
}
Thank you very much for your attention and support. I look forward to hearing from you both.
With best regards
EY1
2025-01-30 06:10 PM
Your function is still in the wrong place, it needs to be outside of the main function.
Place it in the /* USER CODE BEGIN 0 */ section.
2025-01-31 04:11 PM
Thank you AMars.4 for your reply.
I have placed the function under the /* USER CODE BEGIN 0 */ in main.c
The Model.cpp remains the same (unchanged).
In the build results, "the warning for main.c 'Adc_OutPut_GetValue' defined but not used" disappear; thank you.
The current STM32CubeIDC build results:
C:/TouchGFXProjects/ADC_Output_Display/TouchGFX/gui/src/model/Model.cpp:31: undefined reference to `Adc_Output_GetValue'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:103: STM32H7B3I-DK.elf] Error 1
"make -j2 all" terminated with exit code 2. Build might be incomplete.
09:28:32 Build Failed. 2 errors, 1 warnings. (took 1m:34s.826ms)
and the print screen:
The build error, Model.cpp:31: undefined reference to `Adc_Output_GetValue' is still remained.
Not sure how to overcome this.
Enclosed also the updated main.c
Thank you very much for your time and support. I look forward to hearing your advice.
With best regards
EY1
2025-01-31 11:20 PM
The function in main doesn't match what you are calling from the model because of the upper case "P".
Change from "P" to "p" in the two places in main.c that you need to....
"Adc_Output_GetValue" instead of `Adc_OutPut_GetValue"
Every reference has to match exactly.
2025-02-01 03:20 PM
Thank you AMars.4.
Thank you very much for your advice. I have fixed this function name error in main.c. The project can now be built in STM32CubeIDE, and working in the STM32H7B3I-DK Board.
The following are the two print screens:
Thank you very much for your support. I greatly appreciate all your help.
With best regards
EY1
2025-02-04 01:23 AM
Hello @EY1 ,
If you were able to solve your issue, please put the a best answer so other can find the solution easily.
Best regards,