I’m trying to port a small application that works fine under the original Arduino IDE, but I’m not able to get it working on Platformio.
#include <Arduino.h>
#define ARDUINOJSON_ENABLE_PROGMEM 0
#include <ArduinoJson.h>
#include <stdint.h>
StaticJsonDocument<2000> jsonDoc;
#define LED_BUILTIN PB1
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial)
{
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); // Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial1.begin(8*115200,SERIAL_8E1);
}
/*
* create hostname based on board & serial Id
*/
String getHostname() {
uint16_t *idBase0 = (uint16_t *) (0x1FFFF7E8);
uint16_t *idBase1 = (uint16_t *) (0x1FFFF7E8+0x02);
uint32_t *idBase2 = (uint32_t *) (0x1FFFF7E8+0x04);
uint32_t *idBase3 = (uint32_t *) (0x1FFFF7E8+0x08);
return "MAPLE-"+String(*idBase3 & 0xFFFF);
}
extern "C" char* sbrk(int incr);
static int FreeStack() {
char top = 't';
return &top - reinterpret_cast<char*>(sbrk(0));
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
jsonDoc.clear();
deserializeJson(jsonDoc,"{}");
JsonObject json = jsonDoc.as<JsonObject>();
json["cmd"]="MQTT-PUB";
json["topic"]="src/"+getHostname()+"/system/upTime";
json["message"]=String(millis());
json["qos"]=0;
json["retained"]=false;
String str;
serializeJson(jsonDoc,str);
str+="\n";
Serial.println(str);
Serial1.println(str);
json["topic"]="src/"+getHostname()+"/system/heap";
json["message"]=String(FreeStack());
serializeJson(jsonDoc,str);//
str+="\n";
Serial.println(str);
Serial1.println(str);
Serial.flush();
Serial1.flush();
}
I tried all kind of build options, but none seem to work correctly. Code compiles but doesn’t write anything to UART1 or USB.
[env:maple]
platform = ststm32
board = maple
framework = arduino
build_flags =
-D USBD_USE_CDC
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_USB_FULLMODE
-D USBCON
-D USBD_VID=0x0483
-D USB_MANUFACTURER="Unknown"
-D USB_PRODUCT="\"BLUEPILL_F103C8\""
-D HAL_PCD_MODULE_ENABLED