SPIMemory unable to compile using ST STM32 platform

I am trying to include the SPIMemory library, but when I use “SPIFlash flash”, the code will not compile succesfully anymore.
Lib should also support STM32 according to the Libraries secrion of PlatformIO.

The code for STM32 I have is:

#include <Arduino.h>
#include <SPIMemory.h>

SPIFlash flash(PA15);

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:

The result I get when compiling is:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/JENG_STM32L082KZ.html
HARDWARE: STM32L082KZ 32MHz, 20KB RAM, 192KB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
 - framework-arduinoststm32 4.10900.200819 (1.9.0)
 - framework-cmsis 2.50501.200527 (5.5.1)
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 13 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SPIMemory> 3.4.0
|   |-- <SPI> 1.0
Building in release mode
Compiling .pio\build\JENG_STM32L082KZ\src\main.cpp.o
Linking .pio\build\JENG_STM32L082KZ\firmware.elf
c:/users/jacco/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/JENG_STM32L082KZ/src/main.cpp.o: in function `_GLOBAL__sub_I_flash':
main.cpp:(.text.startup._GLOBAL__sub_I_flash+0x6): undefined reference to `SPIFlash::SPIFlash(unsigned char)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\JENG_STM32L082KZ\firmware.elf] Error 1

I have no clue where the function “_GLOBAL__sub_I_flash” actually is and what the problem is.
When I make an ATMega328 project using the library, it does compile succesfully.

Add the following line to your platformio.ini file:

build_flags = -DARCH_STM32

It looks like a bug in the library but I didn’t have the time to go into details.

1 Like

Yes, it’s a bug in the library. ARCH_STM32 is defined in SPIMemory.h. But before it is defined, it includes SPIFlash.h, which in turn includes SPIMemory.h. So SPIFlash.h is processed with the wrong macro definitions.

1 Like

I included -DARCH_STM32 in the platformio.ini file and it does indeed compile now.
Thank you very much.
Is there anywhere I can report this bug or are there any next steps?

Issues · Marzogh/SPIMemory · GitHub I think… though it makes me wonder why noone else reported this yet o_O.

I think I fixed it in my PR here: Add more stm32 support by benjinne · Pull Request #248 · Marzogh/SPIMemory · GitHub. Can you give it a try?