If I set the platformio.ini
to
[env:bluepill]
platform = ststm32
board = bluepill_f103c8
framework = zephyr
and use the example project at platform-ststm32/examples/zephyr-blink at develop · platformio/platform-ststm32 · GitHub but replace the main.c
with a main.cpp
of modified content
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>
#include <vector>
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led0 devicetree alias is not defined"
#define LED0 ""
#define PIN 0
#define FLAGS 0
#endif
void main(void)
{
const struct device *dev;
bool led_is_on = true;
int ret;
dev = device_get_binding(LED0);
if (dev == NULL) {
return;
}
ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
if (ret < 0) {
return;
}
std::vector<int> delay_times {500, 250, 500, 250};
int index = 0;
while (1) {
gpio_pin_set(dev, PIN, (int)led_is_on);
led_is_on = !led_is_on;
k_msleep(delay_times.at(index));
index = (index + 1) % delay_times.size();
}
}
and additionally write my zephyr/prj.conf
as
CONFIG_GPIO=y
CONFIG_SERIAL=n
CONFIG_CPLUSPLUS=y
CONFIG_NEWLIB_LIBC=y
since per Unable to use C++ Standard Library · Issue #15603 · zephyrproject-rtos/zephyr · GitHub that is needed to activate C++ supprt in Zephyr, it does compile.
RAM: [== ] 20.1% (used 4113 bytes from 20480 bytes)
Flash: [== ] 15.7% (used 10286 bytes from 65536 bytes)
Building .pio\build\bluepill\firmware.bin
========================= [SUCCESS] Took 11.88 seconds =========================
Interestingly enough I also tried
build_unflags = -nostdinc
build_flags = -lstdc++
in the platformio.ini
, which did compile, and generated a smaller firmware, but doesn’t seem to be intended way, so you should rather stick to above.