Hi there, I believe this is new bug report (i.e. I’ve checked everything I can and can’t find any error on my side).
I have a piece of code (printing to serial) that was working fine up until yesterday, before I updated PIO. Now, it’s completely broken and prints garbage and crashes the application. The same code works properly in the Arduino IDE.
The problem is float and double numbers fail with Serial.print() and appear to display some random memory address as a string. Here is the code I tested:
void setup(void)
{
Serial.begin(115200);
delay(1000);
Serial.println("int:");
int i = 0;
Serial.println(i);
Serial.println("float:");
float f = 0.F;
Serial.println(f);
Serial.println("double:");
double d = 0.;
Serial.println(d);
}
Here is the output after compiling and uploading with PIO extension (under VSCode):
int:
0
float:
␀������������������������������������������������������������������������U␀ �U␀ �9␀ ␀␀␀␀����␇␡␂␀␆␡␂␀␀␀␀g␀ 0␀␀␀␀␀␀␀o|␂g␀ ␀␀␀␀␀␀␀␀␀␀␀␀�5␀ 0␀␀␀␁␀␀g␀ ␀␀␀␀�z␂g␀
␀␀␀␀␀␀␀o|␂g␀ ␀␀␀␀␀␀␀␀␀␀␀␀�5␀
double:
␀���������������������������������������������������������������������������������������␁␀␀g␀ ␀␀␀␀Uz␂g␀ 0␀␀␀␀␀␀␀C|␂g␀ ␀␀␀␀␀␀␀␀␀␀␀␀�5␀ 0␀␀␀␁␀␀g␀ ␀␀␀␀Uz␂g␀
␀␀␀␀␀␀␀C|␂g␀ ␀␀␀␀␀␀␀␀␀␀␀␀�5␀
␀␀␀�5␀ ␁␀␀␀'�␂␀���������w␂␀ww␂␀'�␂␀%�␂␀�t␂␀␀␀�5␀ ��␂␀�5␀ �5␀ ]v␂␀�T␀ �5␀ ␔�␂␀�b␂␀BNO055␀␀␀␀␀␀␁␀␀␀7␀␀␀␃␀␀␀␀␀␀␀␀␀␀␀
␁�������������������������������������������������������������BNO055␀␀␀␀␀␀␁␀␀␀7␀␀␀␃␀␀␀␀␀␀␀␀␀␀␀
�#<␀␀␀␀␀␀␀␀����������������g�␂␀����␕�␂␀��������\␀␀␀�����T␀ +␗␀␀ 6␀ 6␀ �U␀ ␘6␀ ␄␀␀␀�3�+|*���U␀ ␀␀␀␀␁␀␀␀�=␀ loop␀�l␀␁␀␀␀����␁␀␀␀␀␀␀␀␀␀␀␀␀␀_'�␀␀␀HV␀ �V␀ HV␀ �V␀ ␀␀␀␀␐V␀ ����␐V␀ ␐V␀ ␁␀␀␀$V␀ �����f␀ �f␀ ␀␀␀␀␔␀␀␀␄␀␀␀��␀␃ˋ��␀4�)�␡�H␅b��s{b�␛␌����{5.1�!ͪ�G0%␑
␡�Y�␌�#␑m��P 7���%�E�␘��}�␖␜���7���P���7�/;<M�{␐␀␀����������������������������������������������������������������������������������������������������������������������������������������������������������������������������
�������.....
And here is the output after compiling and uploading with Arduino extension (under VSCode):
int:
0
float:
0.00
double:
0.00
After the PIO uploaded code tries to print a double or float and instead prints garbage, the program will randomly crash as well.
Board: I’m using Adafruit nFR52 Feather, using BSP 10.1. Prior to upgrade, I was using BSP 9.3 but the PIO upgrade also upgraded the BSP (I have all auto updates enabled). I’m not sure if the cause is the BSP or something in PIO itself or perhaps a specific compiler flag, but this code was working fine before updating.
Any ideas what may be causing this? And is there a way to disable all compiler optimizations?
Thanks