Serial bug and firmware question

Sorry for long post :smile:

I and Talybin are trying to identify a potential bug with Serial, first char in first message is always garbage. See Issue #682.

as example following code on Photon:

unsigned long lastTime = 0;

void setup()          
{
    Serial1.begin(9600);
}

void loop()  
{    
    unsigned long now = millis();     
    if (lastTime == 0 ||  ((now - lastTime) > 5000)){ 
        Serial1.println("!");
        lastTime = now; 
    }
}

give this output in Putty:

â–’!
!
!

We think reason is that there is copy paste error in firmware, there is no memset for tx_buffer, so that the reason for garbage char in first message.

So I trying to resolve it in firmware to see if it fixes this problem.

I install all depecies needed according too Particle.io firmware

after that i use

git clone https://github.com/spark/firmware.git
cd firmware
git checkout latest

Then open files in downloaded firmware and edit copypaste error from Issue #682 so we do memset both for rx and tx buffer.

hal/src/core/usart_hal.c#L120
hal/src/core/usart_hal.c#L215
hal/src/stm32f2xx/usart_hal.c#L148-L149
hal/src/stm32f2xx/usart_hal.c#L263-L264

Than I switch to modules folder, connect Photon in DFU-mode and run

make PLATFORM=photon clean all program-dfu

so photon receives changed fixed firmware. No errors received and firmware are loaded in photon.

Then under user/applications I create a folder test and create file test.cpp :

#include "application.h"

unsigned long lastTime = 0;

void setup()          
{
    Serial1.begin(9600);
}

void loop()  
{    
    unsigned long now = millis();     
    if (lastTime == 0 ||  ((now - lastTime) > 5000)){ 
        Serial1.println("!");
        lastTime = now; 
    }
}

Then i change to main folder and run

make PLATFORM=photon APP=test
make PLATFORM=photon APP=test program-dfu

In output i receive

!
!
!

but when i push reset i receive

â–’!
!
!
!

My question is, do I update photon firmware right or do i make mistake somewhere?

If I do correct firmware update, can it be somewhere else reason for garbage char is? Someone who can help us find it?

@changed blink to test

The steps you took seem good (apart from flashing blink after flashing your test app - I imagine that was a copy/paste error?)

I have seen this issue too. Is the garbage character always the same?

Yes :), no blink there, changed it.

Yes char is always the same.

Yes, the same char is suspesious. One theory is that compiler or OS fills the uninitialized memory with some char by default. I know Microsoft compiler/OS for example do fill with 0xCC.