platformio / platform-ststm32

ST STM32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/ststm32
Apache License 2.0
395 stars 310 forks source link

Arduino "Blinky" will not fit into rom of genericSTM32F103C8 target #322

Open johnnyegel opened 4 years ago

johnnyegel commented 4 years ago

There seems to be a problem with building for the genericSTM32F103C8, which causes the resulting firmware to become very big. A very simple blinky example will not build as it exceeds the 64Kb (yeah!) of ROM, thus making it impossible to make anything useful using Platform IO for such boards.

I've used the latest PlatformIO plugin for VScode, and I am running Ubuntu 19.10.

Here is my very simple blinky example (main.cpp):

#include <Arduino.h>
#define BLINK_DELAY   1000

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  static int state = 0;
  static uint32_t lastupdate = millis();

  uint32 now = millis();
  if (now - lastupdate >= BLINK_DELAY) {
    state = 1 - state;
    digitalWrite(LED_BUILTIN, state);
    lastupdate = now;
  }
}

The build fails on the link step, reporting the following error:

Linking .pio/build/genericSTM32F103C8/firmware.elf
arm-none-eabi/bin/ld: .pio/build/genericSTM32F103C8/firmware.elf section `.text' will not fit in region `rom'
arm-none-eabi/bin/ld: region `rom' overflowed by 16256 bytes
collect2: error: ld returned 1 exit status

It is simple to reproduce this by creating a new Arduino Project for this target, pasting the code into main.cpp and trying to build it.

Moving the two static variables inside the loop() function outside of the function, will take the size down within 64Kb.

However, the bug still cause problems with Libraries over which I have no control. For instance the FastLED library is not possible to use on this target, as just including it will cause the program to not fit in memory.

My minimal test project is attached here.

TestOutputSize.zip

nopnop2002 commented 4 years ago

You can avoid it by changing as follows.

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
board_build.core=stm32

Probably the problem with the maple core toolchain.

#include <Arduino.h>
#define BLINK_DELAY   1000

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  static int state = 0;
  static uint32_t lastupdate = millis();

  uint32_t now = millis();
  if (now - lastupdate >= BLINK_DELAY) {
    state = 1 - state;
    digitalWrite(LED_BUILTIN, state);
    lastupdate = now;
  }
}

Refer to this