Importing HAL libraries C++ files.
Hi,
I have created an empty C++ in STM32CubeIDE to create an a project with my own structure. I don't want to use or have the code generation tool on my project.
The problem that I have is that I can't import the HAL libraries from a C++ files since when I compile it fails, I get undefined reference for all the functions that come form the HAL.
I have already added the HALlibrary files to the project structure and added the path for C and C++ in the project settings.
I think that I'm doing something wrong when integrating the c libraries from the HAL into de C++ code.
from my main file I call a c function in a cpp function and from there I call my GPIO.h library that is cpp. Inside this library I call the HAL functions.
Does someone know what I am doing wrong?
Below are a summarize of my files.
Thank you.
main.c
#include <stdint.h>
#include "App.h"
int main(void)
{
//Start app
InitApp();
while(1);
}App.h
#ifndef APP_H_
#define APP_H_
#ifdef __cplusplus
extern "C" {
#endif
void InitApp();
#ifdef __cplusplus
}
#endif
#endif /* APP_H_ */App.cpp
#include "App.h"
#include "GPIO.h"
GPIO gpio;
void Run()
{
// Main application loop
while (1)
{
}
}
void InitApp(void)
{
// Initialize basic HW configuration
gpio.InitGPIO()
Run();
}GPIO.h
#ifndef GPIO_H_
#define GPIO_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32g4xx_hal_gpio.h"
#include "stm32g4xx_hal_rcc.h"
#ifdef __cplusplus
}
#endif
class PPGPIO
{
public:
GPIO();
void InitGPIO();
};
#endif /* GPIO_H_ */GPIO.cpp
#include "GPIO.h"
#include "stm32g473xx.h"
void GPIO::InitGPIO (void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
// GPIO Ports Clock Enable
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
//Configure GPIOD to inputs with no pull-ups
GPIO_InitStruct.Pin = GPIO_PIN_All;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}