Description
Board
Not board specific
Device Description
Not board specific
Hardware Configuration
Not board specific
Version
v2.0.2
IDE Name
PlatformIO 4.2.0
Operating System
Windows 10
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
921600
Description
I have been using Platformio 3.5.0 without any issues for very long time.
I tried to moving on to version 4.2.0 based off 2.0.2 but it seems it has lots of underlying problems or it requires me to rewrite most of my code.
I can't share all of it as its quite advanced, instead I will provide you with few insights and code that had dramatic performance issues. I run all code on mostly tasks with priority 4-8 and less important ones being on 3 and 2.
Top is version 3.5.0 of Platformio (I don't know exactly which Arduino version it's based off - sorry).
Bottom is version 4.2.0
Note - I left device to run for 5 minutes to make sure test is fair.
Displays are as follows (starting from left top corner):
-
Log speed - is .CSV logging appending the file with ~30 parameters, speed is in rows/second - as you can see on 3.5.0 it was stable and flat and it's jittery on new version (but it does keep up.
-
Max heap - I wouldn't worry about this one, but we can see change in max heap and it's much smaller than on previous version.
-
RPS - it's "responses per second" - basically I use single wire serial connection (LIN type) to gather data from old typ ECU, here my performance is most important and as you can see it doesn't keep up with it. Maybe my code here is wrong as it's very complicated to provide great stability, but I have been using this one for few years and never has issues before.
It's worth mentioning I am using GPS at 5Hz data rate constantly sending data to my second Serial input.
- Free heap - here difference is huge and I can't believe it's only due to change from 3.5.0 to 4.2.0 - but I can't find any other culprit!
But the worst offender of all is the part of sketch below that I use to transfer data from/to SD card. Below is snippet of function I use to get those performance stats:
Before I managed to get constantly around 71 ms:
[E][Gauge.S.cpp:1536] handleCopyFile(): Time to read /displayConfig.json - 73 ms
But now it's not even funny:
[E][Gauge.S.cpp:1536] handleCopyFile(): Time to read /displayConfig.json - 1466 ms
I think SD card handling may have changed so some sort of guide of how to move to new type of handling files would be appreciated.
Sketch
#define SD_CS 15
#define SD_SCK 14
#define SD_MISO 27
#define SD_MOSI 13
SPIClass SDSPI(HSPI);
// In setup()
void setup() {
SDSPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
SD.begin(SD_CS, SDSPI, 80000000);
}
// Yes I could have written it better
// It basically transfers files from SD card to flash and vice versa with usage of temp.dat file in case of power failure.
#define COPY_BUFFER 512
#define TEMP_NAME "/temp.dat"
boolean handleCopyFile(const char* nameSource, const char* nameTarget, boolean overwrite = true, boolean toSDCard = false, boolean removeSource = false) {
#ifdef DEBUG
uint32_t fileWriteStamp = millis();
#endif
uint8_t bufFile[COPY_BUFFER];
boolean sourceExist;
boolean targetExist;
if(toSDCard) {
sourceExist = SPIFFS.exists(nameSource);
targetExist = SD_USE.exists(nameTarget);
} else {
sourceExist = SD_USE.exists(nameSource);
targetExist = SPIFFS.exists(nameTarget);
}
if(!overwrite) overwrite = !targetExist;
if(sdReady && sourceExist && overwrite) {
File sourceFile;
if(toSDCard) sourceFile = SPIFFS.open(nameSource, "r");
else sourceFile = SD_USE.open(nameSource, "r");
if(!sourceFile) return false;
boolean renamed = false;
if(targetExist) {
if(toSDCard) {
// SD_USE.remove(nameTarget);
} else {
renamed = SPIFFS.rename(nameTarget, TEMP_NAME);
}
}
File targetFile;
if(toSDCard) targetFile = SD_USE.open(nameTarget, "w");
else targetFile = SPIFFS.open(nameTarget, "w");
if(!targetFile) {
sourceFile.close();
if(renamed) SPIFFS.rename(TEMP_NAME, nameTarget);
return false;
}
size_t bytesRead = COPY_BUFFER;
while(bytesRead = sourceFile.read(bufFile, COPY_BUFFER)) {
targetFile.write(bufFile, bytesRead);
#ifdef DEBUG
// Serial.write(bufFile, bytesRead);
#endif
}
targetFile.flush();
sourceFile.close();
targetFile.close();
if(renamed) SPIFFS.remove(TEMP_NAME);
#ifdef DEBUG
log_e("Time to read %s - %6d ms", nameSource, millis() - fileWriteStamp);
#endif
if(removeSource) {
if(toSDCard) {
SPIFFS.remove(nameSource);
} else {
SD_USE.remove(nameSource);
}
}
delay(20);
return true;
} else if(targetExist) return true;
return false;
}
Debug Message
Before on 3.5.0:
[E][Gauge.S.cpp:1536] handleCopyFile(): Time to read /displayConfig.json - 73 ms
Now on 4.2.0:
[E][Gauge.S.cpp:1536] handleCopyFile(): Time to read /displayConfig.json - 1466 ms
### Other Steps to Reproduce
_No response_
### I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Type
Projects
Status