2024-02-04 07:59 AM
Hi,
I have plenty of embedded code that was written in a mixture of C/C++ with target of NXP processors, now I am going to port it onto STM32 targets, I wrote a mini class OutputPort as a test in CubeIDE:
OutputPort.h:
#include "stm32f767xx.h"
class OutputPort
{
public:
OutputPort(GPIO_TypeDef* gpio, uint16_t gpioPin);
virtual ~OutputPort();
private:
GPIO_TypeDef* gpio;
uint16_t gpioPin;
public:
void Toggle();
void Set();
void Reset();
};
OutputPort.cpp:
#include "OutputPort.h"
#include "stm32f7xx_hal.h"
OutputPort::OutputPort(GPIO_TypeDef* gpio, uint16_t gpioPin)
{
this->gpio = gpio;
this->gpioPin = gpioPin;
}
OutputPort::~OutputPort() { }
void OutputPort::Toggle() { HAL_GPIO_TogglePin(gpio, gpioPin); }
void OutputPort::Set() { HAL_GPIO_WritePin(gpio, gpioPin, GPIO_PIN_RESET); }
void OutputPort::Reset() { HAL_GPIO_WritePin(gpio, gpioPin, GPIO_PIN_SET); }
main.c :
/* USER CODE BEGIN Includes */
#include <OutputPort.h>
/* USER CODE END Includes */
/* USER CODE BEGIN 2 */
Port* Led1 = new Port(GPIOB, GPIO_PIN_0);
/* USER CODE END 2 */
The compiler reports: error: unknown type name 'class'
Then I change the main.c to main.cpp as I did with NXP processor which are also ARM Cortex,
it looks like the compilation is OK, but the linker reports error:
Core/Startup/startup_stm32f767zitx.s:99: undefined reference to `main'
The line 99 of startup_stm32f767zitx.s is a jump instruction (jump to main):
/* Call the application's entry point.*/
bl main
Anyone knows any workaround?
Regards
Chao
Solved! Go to Solution.
2024-02-05 02:46 AM
Sorry I have to come back to this post for a new issue in compiling C++ code.
The C++ code compilation is all right now in my previous test project which is my first CubeIDE project. Then I was trying to use that method to do the same thing in the example project (Nucleo-STM32F767ZI) : LwIP_HTTP_Server_Netconn_RTOS
However, I found unexpectedly I don't get the option of "Convert to C++" when right click on this project in Project Explorer.
When I right click on other projects, I could see this option or option of "Convert to C" for the one I already converted to C++.
I also did a new import of this example, and the result does not change.
Any solution for this?
Regards
Chao
2024-02-05 06:49 PM
I did this example import again more carefully, and found the following:
It looks like that it's not an STM32CubeIDE version example, is not compatible with CubeIDE, and is not configurable in CubeIDE (actually there is no .ioc file), so is it possible to convert this example from other toolchain/IDE (say MDK-ARM) to CubeIDE?
It would be highly appreciated if someone could share a link of this conversion.
Regards
Chao
2024-02-05 07:22 PM
> so is it possible to convert this example from other toolchain/IDE (say MDK-ARM) to CubeIDE?
See here:
https://wiki.st.com/stm32mpu/wiki/How_to_move_from_SW4STM32_to_STM32CubeIDE
Can also just try "Import ac6 System Workbench for STM32 Project" without the extra steps.
2024-02-06 07:18 AM - edited 2024-02-06 07:21 AM
In CubeIDE, do "Import".... then in the dialog select "Import STM32CubeIDE example".
This option is slightly better than "Import ac6 System Workbench..." as the import tool has more clues. Internally, of course, it will use the SW4STM variant of the example, so all advices on importing from SW4STM and fixes after the import, apply. See also here.