Can using dtostrf function messup the moteino ?

Started by VdesmedT, June 12, 2017, 04:02:45 PM

VdesmedT

Hello,

I just repeat it three times cause I did not believed it :-) I was working on a sketch that I uploaded dozen of times with success until the moment I started using dtostrf function to display float on an lcd. Once I uploaded that sketch, not only the sketch stopped functioning (lcd off) but I can no longer upload any sketch on it.  I first though that I might have fried the moteino then start using another one but the exact same behaviour happens even completely disconnected from any other electronic (LCD, thermistor, brushless motor...)

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

is what arduino ide reports...

I thought I would reload the bootloader but before I start buying expensive avr-isp-mkII and all, I rather make sure that it makes sens...

TomWS

Quote from: VdesmedT on June 12, 2017, 04:02:45 PM
Hello,

I just repeat it three times cause I did not believed it :-) I was working on a sketch that I uploaded dozen of times with success until the moment I started using dtostrf function to display float on an lcd. Once I uploaded that sketch, not only the sketch stopped functioning (lcd off) but I can no longer upload any sketch on it.  I first though that I might have fried the moteino then start using another one but the exact same behaviour happens even completely disconnected from any other electronic (LCD, thermistor, brushless motor...)

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

is what arduino ide reports...

I thought I would reload the bootloader but before I start buying expensive avr-isp-mkII and all, I rather make sure that it makes sens...
Since you didn't include your code, it's hard to tell, but my guess would be that your output character buffer isn't long enough for the precision you've specified, you're stomping all over your stack, and returning to nowhereville...  but I could be wrong.


VdesmedT

Hello Tom,

I should have thought that this was the most reasonable analysis ;-)

{
  char strBuffer[30];
  dtostrf(lapTime/1000.0, 20, 1, strBuffer);
  u8g.drawStr(50, 55, strBuffer);
}

Do you thing that if that code goes wrong it could have destroy the bootloader part of the memory in such a way that you can no longer upload code ?

TomWS

Quote from: VdesmedT on June 13, 2017, 01:46:29 AM
...reversing order of quote...
Do you thing that if that code goes wrong it could have destroy the bootloader part of the memory in such a way that you can no longer upload code ?
I (think) it depends on the fuse bits you've got set, on whether the bootloader is locked or not and I'm not sure what the default it - it should be locked, IMO.

Quote

{
  char strBuffer[30];
  dtostrf(lapTime/1000.0, 20, 1, strBuffer);
  u8g.drawStr(50, 55, strBuffer);
}

A question and a comment:
Question: do you REALLY need 20 digits of precision on your number????
Comment:  strBuffer should be declared as static if you're going to pass it to u8g library.  The graphics library updates in the background and doesn't buffer the data, hence the data can't 'disappear' as soon as the block is exited as you have it.

Tom

VdesmedT

#4
Quotewhether the bootloader is locked or not and I'm not sure what the default is
It is a stock moteino so I guess Felix can answer that.

Quotedo you REALLY need 20 digits of precision on your number?
Signature is char * dtostrf(double __val, signed char __width, unsigned char __prec, char * __s)

I though the width was for max buffer length  :-*. For my defense it was 2am  ;D

QuotestrBuffer should be declared as static
In the actual code, strBuffer is defined outside of the draw() scope, so globally in this case. Good to know though. Thanks

I guess, at the end, the main question is to understand what can causes the moteino to be in a state where no sketches can be uploaded and if re burning the bootloader can solve that problem ?

TomWS

Quote from: VdesmedT on June 13, 2017, 07:54:16 AM
It is a stock moteino so I guess Felix can answer that.
If you're thinking about burning a bootloader, you need to learn what the fuses are and what they mean.  Moteino settings are documented on the LowPowerLab website, DAGS AVR Fuse Calculator to learn what the bits mean...

Tom

VdesmedT

First question is : can it help in solving my issue ?  If I understand it correctly it boils down to knowing if my sketch could have damage the bootloader and that is determine by the fact that the AVR Fuse flag is set on or off when initialy loaded by Felix. right ?  What else could t be that prevent me from uploading a sketch to each moteino that have received that mighty sketch of me ?

Felix

The bootloader section is protected via the lock bits fuses.

VdesmedT

Thank you Felix. Then I suppose the boot loader is untouched and my problem is elsewhere...  What else can prevent a sketch to be uploaded ?

Felix

Does the Moteino reboot when you attempt to upload the sketch?
(ie LED blinks a few times and that indicates it enters the bootloader)

VdesmedT

I have three moteino in that situation.
Two of them just very briefly flash once at both power up time and at the beginning of the upload and one does flash as usual but in the three cases, I only see the RX led flashing three times on the FTDI (Arduino brand) and then the same error in the IDE (stk500_getsync() attempt 6 of 10: not in sync: resp=0x00)

Felix

If they are old Moteinos they might not have the lock fuses set.
The only way to really tell what's going on is to read the flash and compare the bootloaders.
Or just reflash the bootloader with an ISP programmer and set the lock bits.

VdesmedT

They are R4 bought in January 2014.  I guess I'm in for a AVR ISP MKii but is hard to find those days and is replaced by the AVR ICE which costs more than 100 eur. Do you know another source for cheaper yet sure quality ISP ?

Felix

I think those might not have the fuses :( so maybe your bootloaders are overwritten.
I can do it for you if you want to return them to me, if that's convenient.
Or there's other ways to do ISP programming using another Arduino, if you do that make sure you use 5v to VIN and 3.3v levels on the SPI/reset lines, so you dont fry the radio/flash.

VdesmedT

I just order the ATMEL AVR ICE kit. I guess it might come handy for other purpose as well like debugging isn't it ?  I should have it by then end of the week. I'll post some feedback during the weekend.  I think there are plenty of information on how to re burn the bootloader using AVR studio and the AVR ICE on the net but off course if you have any reference to a good post, it might come handy at some point :-)

Thanks for the support so far :-)