PlatformIO Community

RadioHead library on STM32

Has anyone been able to get the RadioHead library to work on an STM32, specifically rfm22 if that matters. I had a few compile issues with feature that I don’t use compiling initially, which may be an indication of a problem, but, after hacking around those, I can’t get the simplest program to run.

Creating a simple project for an STM32F103CB that contains this for a main.c:

#include <Arduino.h>
#include <SPI.h>
void setup() {
  // put your setup code here, to run once:
}
void loop() {
  // put your main code here, to run repeatedly:
}

will fail to compile.

It works great in the Arduino IDE, but I would love to be able to use PlatformIO.

Try renaming your main.c to main.ino. Platformio needs to know the main file is an Arduino C++ file.

Thanks, but I already tried importing my ino file from my Arduino project into platformio and got the same error. I think it must be due to some defines that are different, but I don’t know how to see what the differences are.

The code around the error is:

#if (RH_PLATFORM == RH_PLATFORM_STM32)
// Maple etc

HardwareTimer timer(MAPLE_TIMER);

#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4)
// rogerclarkmelbourne/Arduino_STM32
// And stm32duino    
HardwareTimer timer(1);

#elif (RH_PLATFORM == RH_PLATFORM_ESP32)

With the error being:

.pio\libdeps\genericSTM32F103CB\RadioHead\RH_ASK.cpp:18:21: error: invalid conversion from 'int' to 'TIM_TypeDef*' [-fpermissive]
   18 | HardwareTimer timer(1);

If I force it to use the first section by defining RH_PLATFORM = RH_PLATFORM_STM32 it compiles, but crashes.

Actually, I think I ended up just ifdeffing out that whole file, but it makes me think that the STM32 framework that I’m using in platformio is different from what I’m using in arduino, which I believe is this: https://github.com/stm32duino/Arduino_Core_STM32

It also took me quite a while just to find a arduino framework that worked, with all the different bootloaders and flashing options, etc. I finally got it to work with no bootloader and flashing via serial. I would also love to use a bootloader, but all the ones I tried either didn’t work, or seemed to flash over themselves, so they only lasted one flash.

you need to change:
HardwareTimer timer(1);
to
HardwareTimer timer(TIM1);

and port to new API those call:
timer.setPeriod((1000000/8)/_speed);
timer.setChannel1Mode(TIMER_OUTPUT_COMPARE)
timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update
timer.attachCompare1Interrupt(interrupt);
written for the maple api:
http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/latest/lang/api/hardwaretimer.html#lang-hardwaretimer
to the API:

when I have time I will try…

If the RadioHead library is written against an older STM32Duino core, you can also just downgrade the platform version that PlatformIO is supposed to use.

Have a look at the released versions: https://github.com/platformio/platform-ststm32/releases

Then instead of

platform = ststm32

write

platform = ststm32@6.1.0

in the platformio.ini to e.g. get the Arduino Core 1.8.0 version instead of the current 1.9.0. Or 5.7.0 for 1.7.0.

No, RadioHead library is written against an other arduino compatible platform for stm32, similar but different.

You’re right, it’s written against the Maple core.

But then the error could also be another one – since 7.0.0 the genericSTM32F103CB board uses STM32Duino instead of Maple as the default underlying core. See e.g. boards/genericSTM32F103CB.json diff in

So maybe

board_build.core = maple

in the platformio.ini fixes the problem?

I suggest this patch:

compile but not tested …

Paolo

Thank you for all the suggestions. I don’t know why I just received notification about the activity on this thread.

In any case, I will try the suggestions as soon as I can and report back. I suspect the maple version would work, since I think that’s the version of stm32 Ardiomp that I’m using in the Arduino IDI. I didn’t know it was available in PlatformIO.

I would prefer to use the default version in PlatformIO, which I believe is the newer version, so I’ll try the patch to see if that fixes it.

My patch was merged it into the last release of RH
https://groups.google.com/g/radiohead-arduino/c/qZF8n_Iv87M/m/rKckCF18AwAJ

1.112 2020-08-05 Fixed some compiler warnings in STM32 Discovery and other processors.
Adde support for ST’s Arduino Core STM32, https://github.com/stm32duino/Arduino_Core_STM32 to RH_ASK, per https://github.com/r-map/rmap/commit/edf9931b21cb7df5b4f67835307255e0fcb301bb.

we have to wait new release for platformio too