STM8 w/SPL linking problem on blinky

Hi, I’m trying to compile a simple blinky with SPL on my STM8 board (with an stm8s003f3p6 on it). It’s a linking problem, i share my code:

#include "stm8s.h"
#include "stm8s_it.h"
#include "stm8s_gpio.h"

void main()
{
    GPIO_Init(GPIOD, GPIO_PIN_3, GPIO_MODE_OUT_PP_HIGH_FAST);
    while (1)
    {
        GPIO_WriteReverse(GPIOD, GPIO_PIN_3);
        for (volatile uint16_t i = 0; i < 16000; ++i);
    }
}

and this is de output:

Processing stm8sblue (platform: ststm8; board: stm8sblue; framework: spl)
-------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm8/stm8sblue.html
PLATFORM: ST STM8 1.0.2 > ST STM8S103F3 Breakout Board
HARDWARE: STM8S103F3P6 16MHz, 1KB RAM, 8KB Flash
PACKAGES: 
 - framework-ststm8spl 0.20301.181217 (2.3.1) 
 - tool-stm8binutils 0.230.0 (2.30) 
 - toolchain-sdcc 1.30804.10766 (3.8.4)
Warning! Couldn't find stm8s_conf.h file!
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Framework incompatible library /home/tute/.platformio/lib/LimetOS_ID6894
Found 0 compatible libraries
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
Scanning dependencies...
No dependencies
Building in release mode
sdcc -o .pio/build/stm8sblue/src/main.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -Iinclude -Isrc -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc src/main.c
sdcc -o .pio/build/stm8sblue/src/stm8s_it.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -Iinclude -Isrc -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc src/stm8s_it.c
sdcc -o .pio/build/stm8sblue/firmware.elf -mstm8 --nostdlib --code-size 8192 --iram-size 1024 --out-fmt-elf .pio/build/stm8sblue/src/main.rel .pio/build/stm8sblue/src/stm8s_it.rel -L/home/tute/.platformio/packages/toolchain-sdcc/share/sdcc/lib/stm8 -lstm8

?ASlink-Warning-Undefined Global '_GPIO_Init' referenced by module 'main'

?ASlink-Warning-Undefined Global '_GPIO_WriteReverse' referenced by module 'main'
*** [.pio/build/stm8sblue/firmware.elf] Error 1

my folder has this files:

blinky
  |-- src
  |    |-- main.c
  |    |-- stm8s_it.c    // from github example
  |-- include
       |-- stm8s_conf.h  // from github example (I commented USE_FULL_ASSERT)
       |-- stm8s_it.h    // from github example

So, the only way I could compile this is by copying the stm8s_gpio.c file from .platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/ into my project’s “src” folder.

Can I fix this? I’m doing something wrong? Thanks in advance.

PS: I’m using Linux with codium btw.

Per platform-ststm8/examples/spl-blink/src at develop · platformio/platform-ststm8 · GitHub that file should be in src/ not include/, maybe PIO can then figure out the configuration.

1 Like

I missed that one, why is that? It compiles now but with 130% of flash memory usage :crazy_face:

Processing stm8sblue (platform: ststm8; board: stm8sblue; framework: spl)
-------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm8/stm8sblue.html
PLATFORM: ST STM8 1.0.2 > ST STM8S103F3 Breakout Board
HARDWARE: STM8S103F3P6 16MHz, 1KB RAM, 8KB Flash
PACKAGES: 
 - framework-ststm8spl 0.20301.181217 (2.3.1) 
 - tool-stm8binutils 0.230.0 (2.30) 
 - toolchain-sdcc 1.30804.10766 (3.8.4)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Framework incompatible library /home/tute/.platformio/lib/LimetOS_ID6894
Scanning dependencies...
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
No dependencies
Building in release mode
sdcc -o .pio/build/stm8sblue/SPL/stm8s_adc1.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_adc1.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_awu.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_awu.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_beep.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_beep.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_clk.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_clk.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_exti.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_exti.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_flash.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_flash.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_gpio.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_gpio.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_i2c.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_i2c.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_itc.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_itc.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_iwdg.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_iwdg.c
/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_itc.c:60: warning 59: function 'ITC_GetCPUCC' must return value
sdcc -o .pio/build/stm8sblue/SPL/stm8s_rst.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_rst.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_spi.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_spi.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_tim1.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_tim1.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_tim2.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_tim2.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_tim4.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_tim4.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_uart1.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_uart1.c
sdcc -o .pio/build/stm8sblue/SPL/stm8s_wwdg.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc /home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_wwdg.c
/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_tim2.c:1110: warning 116: right shifting more than size of object changed to zero
sdcc -o .pio/build/stm8sblue/src/main.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -Iinclude -Isrc -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc src/main.c
sdcc -o .pio/build/stm8sblue/src/stm8s_it.rel -c -mstm8 --opt-code-size -DF_CPU=16000000L -DPLATFORMIO=40304 -DSTM8S_BLUE -DSTM8S103 -DUSE_STDPERIPH_DRIVER -DUSE_STDINT -Iinclude -Isrc -I/home/tute/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/inc -Isrc src/stm8s_it.c
sdcc -o .pio/build/stm8sblue/firmware.elf -mstm8 --nostdlib --code-size 8192 --iram-size 1024 --out-fmt-elf .pio/build/stm8sblue/SPL/stm8s_adc1.rel .pio/build/stm8sblue/SPL/stm8s_awu.rel .pio/build/stm8sblue/SPL/stm8s_beep.rel .pio/build/stm8sblue/SPL/stm8s_clk.rel .pio/build/stm8sblue/SPL/stm8s_exti.rel .pio/build/stm8sblue/SPL/stm8s_flash.rel .pio/build/stm8sblue/SPL/stm8s_gpio.rel .pio/build/stm8sblue/SPL/stm8s_i2c.rel .pio/build/stm8sblue/SPL/stm8s_itc.rel .pio/build/stm8sblue/SPL/stm8s_iwdg.rel .pio/build/stm8sblue/SPL/stm8s_rst.rel .pio/build/stm8sblue/SPL/stm8s_spi.rel .pio/build/stm8sblue/SPL/stm8s_tim1.rel .pio/build/stm8sblue/SPL/stm8s_tim2.rel .pio/build/stm8sblue/SPL/stm8s_tim4.rel .pio/build/stm8sblue/SPL/stm8s_uart1.rel .pio/build/stm8sblue/SPL/stm8s_wwdg.rel .pio/build/stm8sblue/src/main.rel .pio/build/stm8sblue/src/stm8s_it.rel -L/home/tute/.platformio/packages/toolchain-sdcc/share/sdcc/lib/stm8 -lstm8
MethodWrapper(["checkprogsize"], [".pio/build/stm8sblue/firmware.elf"])
sdcc -o .pio/build/stm8sblue/firmware.ihx -mstm8 --nostdlib --code-size 8192 --iram-size 1024 --out-fmt-ihx .pio/build/stm8sblue/SPL/stm8s_adc1.rel .pio/build/stm8sblue/SPL/stm8s_awu.rel .pio/build/stm8sblue/SPL/stm8s_beep.rel .pio/build/stm8sblue/SPL/stm8s_clk.rel .pio/build/stm8sblue/SPL/stm8s_exti.rel .pio/build/stm8sblue/SPL/stm8s_flash.rel .pio/build/stm8sblue/SPL/stm8s_gpio.rel .pio/build/stm8sblue/SPL/stm8s_i2c.rel .pio/build/stm8sblue/SPL/stm8s_itc.rel .pio/build/stm8sblue/SPL/stm8s_iwdg.rel .pio/build/stm8sblue/SPL/stm8s_rst.rel .pio/build/stm8sblue/SPL/stm8s_spi.rel .pio/build/stm8sblue/SPL/stm8s_tim1.rel .pio/build/stm8sblue/SPL/stm8s_tim2.rel .pio/build/stm8sblue/SPL/stm8s_tim4.rel .pio/build/stm8sblue/SPL/stm8s_uart1.rel .pio/build/stm8sblue/SPL/stm8s_wwdg.rel .pio/build/stm8sblue/src/main.rel .pio/build/stm8sblue/src/stm8s_it.rel -L/home/tute/.platformio/packages/toolchain-sdcc/share/sdcc/lib/stm8 -lstm8
Error: The program size (10645 bytes) is greater than maximum allowed (8192 bytes)
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 0 bytes from 1024 bytes)
Flash: [==========]  129.9% (used 10645 bytes from 8192 by*** [checkprogsize] Explicit exit, status 1
tes)
.pio/build/stm8sblue/firmware.elf  :
section    size         addr
HOME        111        32768
GSINIT       26        32879
GSFINAL       3        32905
CONST        46        32908
CODE      10505        32954
SSEG          1   4294967295
Total     10692

The link-time optimizer of sdcc is extremely bad, basically every function / global variable from every compiled file is linked into the final target, even if you use none of the functions. You can see from the compile log that you’re compiling the components CLK, EXTI, FLASH, GPIO, I2C, ITC, IWDG, RST, SPI, TIM,… → flash overflow.

As this line says

Try commenting out all the unneccsary component in the config file header until the code minimally fits.

1 Like

Thank you very much, this is rustic compiling then… Is preatty bad, I used SDCC long time ago w/AT89x51, and worked fine because has no HAL, just defines for the SFR, so I never notice the bad optimization.