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.