You didn’t copy stm8s_it.h from the original example correctly. (original source). Large blocks of code are just missing in regards to handling SDCC. Could it be that you let some tool autogenerate this code, which was meant to be for a totally different compiler?
Ok, I changed that file as you advised, but faced a new error:
Processing stm8sblue (platform: ststm8; board: stm8sblue; framework: spl)
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: ST STM8 (2.1.0) > ST STM8S103F3 Breakout Board
HARDWARE: STM8S103F3P6 16MHz, 1KB RAM, 8KB Flash
DEBUG: Current (stlink) External (stlink)
PACKAGES:
framework-ststm8spl @ 0.20301.181217 (2.3.1)
tool-stm8binutils @ 0.230.0 (2.30)
toolchain-sdcc @ 1.40200.0+sha.d0b830b
LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Compiling .pio/build/stm8sblue/src/stm8s_it.rel
Linking .pio/build/stm8sblue/firmware.elf
Checking size .pio/build/stm8sblue/firmware.elf
Error: The program size (24477 bytes) is greater than maximum allowed (8192 bytes)
*** [checkprogsize] Explicit exit, status 1
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
RAM: [ ] 0.0% (used 0 bytes from 1024 bytes)
Flash: [==========] 298.8% (used 24477 bytes from 8192 bytes)
Executing task in folder HeatingDetector: platformio run
## Processing stm8sblue (platform: ststm8; board: stm8sblue; framework: spl)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: Redirecting…
PLATFORM: ST STM8 (2.1.0) > ST STM8S103F3 Breakout Board
HARDWARE: STM8S103F3P6 16MHz, 1KB RAM, 8KB Flash
DEBUG: Current (stlink) External (stlink)
PACKAGES:
* framework-ststm8spl @ 0.20301.181217 (2.3.1)
* tool-stm8binutils @ 0.230.0 (2.30)
* toolchain-sdcc @ 1.40200.0+sha.d0b830b
LDF: Library Dependency Finder → https://bit.ly/configure-pio-ldf
LDF Modes: Finder \~ chain, Compatibility \~ soft
Found 0 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Compiling .pio/build/stm8sblue/SPL/stm8s_adc1.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_awu.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_beep.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_clk.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_exti.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_flash.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_gpio.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_i2c.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_itc.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_iwdg.rel
/home/destructor/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_itc.c:60: warning 59: function ‘ITC_GetCPUCC’ must return value
Compiling .pio/build/stm8sblue/SPL/stm8s_rst.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_spi.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_tim1.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_tim2.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_tim4.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_uart1.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_wwdg.rel
Compiling .pio/build/stm8sblue/src/main.rel
Compiling .pio/build/stm8sblue/src/stm8s_it.rel
src/main.c:135: warning 85: in function assert_failed unreferenced function argument : ‘file’
src/main.c:135: warning 85: in function assert_failed unreferenced function argument : ‘line’
/home/destructor/.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
Linking .pio/build/stm8sblue/firmware.elf
Checking size .pio/build/stm8sblue/firmware.elf
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
Error: The program size (24477 bytes) is greater than maximum allowed (8192 bytes)
\*\*\* \[checkprogsize\] Explicit exit, status 1
RAM: \[ \] 0.0% (used 0 bytes from 1024 bytes)
Flash: \[==========\] 298.8% (used 24477 bytes from 8192 bytes)
====================================================================== \[FAILED\] Took 2.06 seconds ======================================================================
* The terminal process “platformio ‘run’” terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
* Executing task in folder HeatingDetector: platformio run
## Processing stm8sblue (platform: ststm8; board: stm8sblue; framework: spl)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: Redirecting…
PLATFORM: ST STM8 (2.1.0) > ST STM8S103F3 Breakout Board
HARDWARE: STM8S103F3P6 16MHz, 1KB RAM, 8KB Flash
DEBUG: Current (stlink) External (stlink)
PACKAGES:
* framework-ststm8spl @ 0.20301.181217 (2.3.1)
* tool-stm8binutils @ 0.230.0 (2.30)
* toolchain-sdcc @ 1.40200.0+sha.d0b830b
LDF: Library Dependency Finder → Library dependency…
LDF Modes: Finder \~ chain, Compatibility \~ soft
Found 0 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Compiling .pio/build/stm8sblue/SPL/stm8s_adc1.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_awu.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_beep.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_clk.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_exti.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_flash.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_gpio.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_i2c.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_itc.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_iwdg.rel
/home/destructor/.platformio/packages/framework-ststm8spl/Libraries/STM8S_StdPeriph_Driver/src/stm8s_itc.c:60: warning 59: function ‘ITC_GetCPUCC’ must return value
Compiling .pio/build/stm8sblue/SPL/stm8s_rst.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_spi.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_tim1.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_tim2.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_tim4.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_uart1.rel
Compiling .pio/build/stm8sblue/SPL/stm8s_wwdg.rel
Compiling .pio/build/stm8sblue/src/main.rel
Compiling .pio/build/stm8sblue/src/stm8s_it.rel
src/main.c:135: warning 85: in function assert_failed unreferenced function argument : ‘file’
src/main.c:135: warning 85: in function assert_failed unreferenced function argument : ‘line’
/home/destructor/.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
Linking .pio/build/stm8sblue/firmware.elf
Checking size .pio/build/stm8sblue/firmware.elf
Error: The program size (24477 bytes) is greater than maximum allowed (8192 bytes)
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
\*\*\* \[checkprogsize\] Explicit exit, status 1
RAM: \[ \] 0.0% (used 0 bytes from 1024 bytes)
Flash: \[==========\] 298.8% (used 24477 bytes from 8192 bytes)
====================================================================== \[FAILED\] Took 2.35 seconds ======================================================================
* The terminal process “platformio ‘run’” terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
For how many years has PlatformIO not yet achieved stability in operation. So, to build a minimal project for STM8 on STVD + Cosmic, I needed to watch 1 video on YouTube and a few hours of perseverance. And to build the same minimal project on PlatformIO, I spent 3 days, without achieving the result.
I do not understand now why I need PlatformIO. For STM32 I use STM32CubeIDE, for Arduino I use Arduino IDE, Raspberry and other Python based MCU are not interested for me (I don’t know Python). Why do I need PlatformIO on Linux OS?
This is due to your stm8s_conf.h now. All includes for all subsystems were activated. SDCC is very poor at producing optimized code and doing link-time-optimization and dead code elimination. PlatformIO has an optimization that the C files from the SDK are not compiled in if their respective header file is not activated in the stm8s_conf.h (see platform code). Again, if you take the code exactly from https://github.com/platformio/platform-ststm8/blob/develop/examples/spl-uart-simple-printf/src/stm8s_conf.h, it compiles fine.
Compiling .pio\build\stm8sblue\src\stm8s_it.rel
src\main.c:135: warning 85: in function assert_failed unreferenced function argument : 'file'
src\main.c:135: warning 85: in function assert_failed unreferenced function argument : 'line'
Linking .pio\build\stm8sblue\firmware.elf
Checking size .pio\build\stm8sblue\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 0.0% (used 0 bytes from 1024 bytes)
Flash: [======= ] 70.4% (used 5771 bytes from 8192 bytes)
Building .pio\build\stm8sblue\firmware.hex
=========================== [SUCCESS] Took 3.16 seconds =========================== * Terminal will be reused by tasks, press any key to close it.
Yeah, I’ve changed stm8s_conf.h, and my code was built successfully! But why is such a large size for a UART working? If we compare it with Arduino IDE + Mini Pro MCU, all flash size fits in 1 KB. Where is an advantage here?
The Arduino AVR core typically does not use printf() for UART output. printf() as a dynamic string construction / formatting function has a huge overhead. Also, AVR-GCC is better at producing optimized (and dead code elimininated code..) than SDCC for STM8.
I’m sure if you didn’t use printf(), but instead the regular UART1_SendData8() from the SPL (stm8s_uart1.h etc.), the size would again go down.
You’re right. I’ve just deleted #include<stdio.h> and related code, after these actions flash size became 4024 bytes. Then I tried to build as a release, but the size did not change.