Compile without using board and framework

Hi all!

I want to use PlatformIO to program my STM8 microcontrollers in the future.

I am writing my libraries on register level on my own and therefore I just want to include my header and C files into my main file and compile that using the SDCC compiler.

As I understood I need a “platformio.ini” file containing basic definitions:

platform = ststm8
upload_protocol = stlinkv2
board = <custom>

How can I only compile my own labraries together with the main.c file using the SDCC compiler and STLINKV2 protocol to upload that to my custom baord?

Thanks for any help in advance!


1 Like

You delete the framework = ... line and then no framework will be compiled in. That’s “baremetal”.


You have to provide a board definition so that PlatformIO can figure out the basic compile settings and flash / RAM limits.

1 Like

Hi @maxgerhardt

Thanks for the reply.
Ok, I will delete the framework tag.

Did I understand this right, that I will just make a board definition for every microcontroller (not actually the board) I am using and will include that for each?
Do I have to add the MCU name in the “env” tag? Or can I just use “[env]”
I tried the following .json board file:

  "build": {
    "f_cpu": "2000000L",
    "cpu": "stm8",
    "mcu": "stm8s103f3p6",
    "variant": "standard"
  "upload": {
    "maximum_ram_size": 1024,
    "maximum_size": 8192,
    "protocol": "stlinkv2",
    "protocols": [
  "name": "ST STM8S103F3 chip",
  "url": "",
  "vendor": "ST"

But there is a compile error:
Error: Missing target configuration for stm8s103f3

And how do I unclude my library path?
I tried the following:

platform = ststm8
upload_protocol = stlinkv2
board = <to be done>
include_path = D:/Libraries/Mikrocontroller-C/STM8/
build_flags = 
    -I D:/Libraries/Mikrocontroller-C/STM8/

But when i use #include “LIB.h” I got the following error:
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit

Well per

the board file needs to have a “debug” section with either “openocd_board” or “openocd_target” present. At least give it

There is no include_path option. Please use the library management if intended if source files are involved: Library Management — PlatformIO latest documentation

Ok, thanks, so as long as I don’t use the debug function, it does not matter which MCU exactly is written there?

If I use “lib_deps” is there an option to specify my include path “D:/Libraries/Mikrocontroller-C/STM8/”?

And is there a possibility that I don’t need to place the main.c file into a folder called “src”?

It doesn’t, but writing stm8s there is actually correct for OpenOCD, so I don’t see a point in writing an explicitly wrong value there.

With lib_deps you can point to a PlatformIO library (preferably has a library.json in it). You would write that file and put it in STM8.

If there are no source files in there, only .h files, then doing build_flags = -I... is also okay.

You can redirect the source directory to another source directory or to . (meaning directly the directory where the platformio.ini is per docs in the special [platformio] ini section.

I meant the “svd_path” but removing that also worked.

Ok, thanks, using build_flags = -ID:/Libraries/Mikrocontroller-C/STM8/include seems to work because it’s compiling now…


src_dir = .

worked flawlessly!

The last problem I am facing now is the following:
I have a “main.c” file:

#include <stdint.h>
#include "io.h"
#include "delay.c"

#define LED1_PIN 4					// define LED 1 pin

void main(void)
    PD_DDR |= (1 << LED1_PIN);		// configure PD4 as output
    PD_CR1 |= (1 << LED1_PIN);		// use push-pull mode for PD4

		PD_ODR ^= (1 << LED1_PIN);	// toggle LED
		delay_ms(500);				// wait 500ms

which is including a file called “delay.h”:

static inline void delay_ms(uint16_t ms);
static inline void delay_us(uint16_t us);

The file “delay.c” also includes this “delay.h” header file:

#include "delay.h"

static inline void delay_ms(uint16_t ms)
    for (uint32_t i = 0; i < ((F_CPU / 18000UL) * ms); i++)
        __asm__("nop");         // assembly command "not operate"

static inline void delay_us(uint16_t us)
    for (uint32_t i = 0; i < ((F_CPU / 18UL) * us); i++)
        __asm__("nop");         // assembly command "not operate"

The compiler shows the error ASlink-Warning-Undefined Global '_delay_ms' referenced by module 'main', but when I include the “delay.c” into the main file (instead of “delay.h”) it works flawlessly. But the header file should be included not the .c file.
What to do about that?

If you want to use static inline, the definition of the function must be right there in the header file, not in a separate c file. Otherwise it can’t be static nor inline.

Removing “static inline” still produces the same error except if I include “delay.c” instead of “delay.h”…
So it seems that the compiler doesn’t know that there is a corresponding .c file which has to be used when incuding the .h file.

Just let that be your header file and delete the .c file.

Ok, but that’s not ANSI-C! Header files do not contain code but only declarations…
Is there a possibility to incude the header files which are not containing the definitions?

A sensible approach would be to put the static inline functions in either a header file if they are to be widely used or just in the source files that use them if they are only ever used from one file.

In any case, this thread is getting too off-topic, the original question about PlatformIO configuration was solved.

Ok, thanks I will just include the .c files.
Everything from the beginning is resolved.