STM32CubeMX to Arduino Library?

Hi,

Couldn't find a suitable Arduino timer library for an STM32, to use in my project. Thought I'd better learn to write one.

At present, I have timer code running, mostly as STM32 TIMER HAL invocations, buried in a Platformio/ STM32CubeMX mish-mash project. There's lots of stuff in the HAL layer setup and running, that I don't think I need or want.

The question is, how to go from the Cube project, to running the code in Arduino STM32 library form?

Any links or (polite) direction appreciated.

GBEM.

STMCube will only configure the peripherals that you tell it to (except for the base stuff that's needed for the chip to function), so if there's stuff you don't need, it's up to you to disable it.

Also it assumes that you're starting on bare metal (unless you have an RTOS selected) so it's not going to be compatible with Arduino libraries without being careful that you're not affecting something that another library needs.

What is it doing that you don't think you need?

Hi CLI,

Thanks for advice on porting to Arduino. I can see now, that it's going to be a tough job.

I posed the STM32CubeMX to Arduino porting question to ChatGPT, and got some very broad guidance. I can see now, that it's more about the specifics of each application.

Thank you, CLI, for your question: individual HAL component need. I think I've lost most of it at CubeMX code generation. Did away with sysTick, etc. Now it's just a careful analysis, to see which bits of the CubeMX code, conflict with how Arduino lays out the hardware.

Nearly got a mash-up of the STM32 timer library for Arduino to compile. It fails during linking, complaining about multiple definitions, of things I added!?

Thanks again for your interest and help, CLI.

GBEM

AFAIK the STM32duino core is basically a wrapper around HAL. I.e. for creating the Arduino API, STM used HAL functions as much as possible. The net result is a rather top-heavy, bloated core that's easy to use, but remarkably inefficient.

Frankly, if you've got your project in STM32Cube, I'd consider simply keeping it there.

Have you already seen this? It's very clean and easy to use.

Ciao, Ale.

Hi ilguargua,

Thanks for the link. A very comprehensive solution, but I'm set on learning to code my own. I should come back to check-out the HardwareTimer library.

GBEM

Okay, down to one linker error.

I'm using a timer, which STM32CubeMX has set to generate an interrupt when CCR counts up to ARR. HAL_TIM_PeriodElapsedCallback() is the apparently 'weakly' defined ISR callback, that I've fully defined in my timer code.

For what ever reason, I'm getting both definitions included in the compilation, leading to a 'multiple definitions of' link error. The 'weak' definition of the ISR callback, hasn't survived the transition from CubeIDE code, to Platformio. It's now a strong prototype definition.

Anyone?

GBEM

No, it's that the Arduino framework defines it's own version of the Timer ISR callback HAL_TIM_PeriodElapsedCallback(), in a Arduino STM32 framework file called HardwareTimer.cpp.

But how to get my HAL_TIM_PeriodElapsedCallback() ISR to run, for timer 2 interrupts, without having to disturb Arduino's own definition of the same named ISR?

GBEM

Hi ilguargua,

I might have to concede, that the STM32duino HardwareTimer library, may be the most appropriate solution.

It just gets very messy (and doesn't work very well), when STM32CubeMX HAL library code, is ported to Arduino.

GBEM

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.