Go Down

Topic: bootloader callable from sketch? (Read 11478 times) previous topic - next topic

tim7


That is correct. The AVR datasheet cautions against trying to use that method.


I must admit I thought the reset circuitry prevented the possibility of an imperfect reset.
Could you point me to the relevant part of the datasheet?

Grumpy_Mike

All this would not be necessary if you ran your code under bitlash
http://bitlash.net/wiki/start
With this system you can run code directly off an SD card.

Quote
I must admit I thought the reset circuitry prevented the possibility of an imperfect reset.

This is because before the reset has time to complete it is removed because the output pin driving it is tristated. This is common for all micro controller chips I have ever seen.

tim7


This is because before the reset has time to complete it is removed because the output pin driving it is tristated. This is common for all micro controller chips I have ever seen.


That much is inevitable.  But internally the reset is surely held for some minimum time.  Otherwise an indecisively pushed reset-button would cause chaos.

P.47 of the data sheet seems to show that the reset sources set a latch.  Any signal long enough to get through the spike-filter will cause a complete reset; whilst shorter signals will do nothing at all.  I can't see any circumstance in which an incomplete reset is possible.

Grumpy_Mike

Quote
But internally the reset is surely held for some minimum time.

No
Quote
Otherwise an indecisively pushed reset-button would cause chaos.

It would if you get a reset that is not held down long enough yes. I have worked on a few systems where this is true.

Quote
I can't see any circumstance in which an incomplete reset is possible.

Trying to reset a processor with the output of it's own pin is one. No engineer would ever do it.
I have been in this business over 40 years you know.

tim7


Quote
But internally the reset is surely held for some minimum time.

No
I have been in this business over 40 years you know.


I bow to your superior age, but do you think you could expand a bit on "no"?  I've copied the relevant diagrams below.




Grumpy_Mike

Quote
• External Reset. The MCU is reset when a low level is present on the RESET pin for longer than the minimum pulse length.


Quote
The port pins are tri-stated when reset condition becomes active, even if no clocks are running.


The section 13.2
13.2.1 Ports as General Digital I/O
Shows a diagram. You will see the reset connected to the ~clear input of a flip flop. This means that as soon as (accounting for propagation delays) the reset is brought low the pin is tristated and thus can not hold the pin low for the minimum reset pulse length of 2.5uS.

Grumpy_Mike

Found some one who actually tried it:-

Quote
At first glance, it seems it may be possible to simply connect up a digital pin to the reset pin. In theory simply setting the digital pin to low would cause the reset. However, Atmel discourage this approach because as the chip starts it's reset, it sets digital pins tri-state, which stops the reset condition possibly leaving the chip in a half-reset state. Indeed, in all the tests we've done, this approach doesn't seem to work.


From:-
http://electronicsfordogs.com/articles/self-resetting-atmel-atmega-328

tim7


This means that as soon as (accounting for propagation delays) the reset is brought low the pin is tristated and thus can not hold the pin low for the minimum reset pulse length of 2.5uS.


That "reset" signal is unlikely to be the external reset pin, because then other reset sources would not clear the ports.  More likely it's the internal reset, in which case there's no problem.


Found some one who actually tried it:-


Oookay.  That person doesn't say they actually tried it, at least not without extra circuitry.  I have (on an Uno R2 with the auto-reset track cut so that the capacitor doesn't interfere with the signals), and it worked perfectly every time.

I can imagine CPUs without proper reset circuitry can get in a pickle after a too-short reset, but in the case of the ATmega328 I don't think there's a problem.

Grumpy_Mike

Quote
That person doesn't say they actually tried it,

Read the words again !!!
Quote
Indeed, in all the tests we've done, this approach doesn't seem to work.


Quote
I have (on an Uno R2 with the auto-reset track cut so that the capacitor doesn't interfere with the signals), and it worked perfectly every time.

Because the reset is still pulled up with a 10K resistor and it is not connected to a GPIO pin.

Quote
but in the case of the ATmega328 I don't think there's a problem.

Well I suppose you are entitled to your opinion but in this case you are wrong.
My God, do you believe anything you are told or read. Just don't try peddling your clap trap round here.
Bye.

tim7


Read the words again !!!
Quote
Indeed, in all the tests we've done, this approach doesn't seem to work.


My apologies, I missed that sentence.  However that is not consistent with my experience, or my best interpretation of the AVR data-sheets.  I'd be glad if someone could point me to an AVR reference on the matter.   My test sketch is attached below.  I don't believe the 10k pull-up resistor affected the reset pulse duration.

Code: [Select]
#define PIN_R 2 // pin-2 connected to Reset; auto-reset disconnected

void setup() {
  digitalWrite(PIN_R,HIGH);
  pinMode(PIN_R,OUTPUT);
  Serial.begin(19200);
  Serial.println("Start");
  delay(2000);
  digitalWrite(PIN_R,LOW); 
}

void loop() {
}


Quote

My God, do you believe anything you are told or read.

Certainly not.  In fact it appears to be my enquiring nature which is causing you pain.  I'm sorry if I offended you, and I hope you do not feel the need to be rude to me again.

retrolefty

Quote
I'd be glad if someone could point me to an AVR reference on the matter.


I've read it enough times to know it's something that AVR specifically cautions against doing. Do you own research and decide if you should throw caution to the wind or follow the recommendations. I have no need to convince you, as I have little interest if your design is successful or not.

Lefty


smeezekitty


My God, do you believe anything you are told or read. Just don't try peddling your clap trap round here.

LOL @ clap trap. But realistically, if everyone believed everything they read or were told, we would not be where we are now.
I suspect you would need to activate some sort of capacitive latch but the brain is not working right now on how to do it exactly.
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

tim7


I have no need to convince you, as I have little interest if your design is successful or not.


There's not much one can say to that, is there?  Searching through nearly 4000 pages of Atmel documentation I'm unable to find the reference you're so coy about giving.  I did find a post on AVRfreaks by somebody called Retrolefty, but he didn't seem to know the answer either.

SirNickity

I find this very interesting.  I'm also insatiably curious, and tend toward the "trust, but verify" side of taking common knowledge at face value.  After all, that's how cargo-cult habits get to where they are.

If I had to guess, I would've figured the reset pin was latched, so that by the time the pins were tri-stated, the dominoes would be falling and there's no going back.  I don't know if I ever would've had an occasion to use such a trick, but I love that I happened to stumble upon the topic.

I hope you guys are patient enough to both accept wisdom and challenge the status quo.  There's much to be gained by seeing for yourself if, how, or why something works.  Maybe not in this case, but often enough. 8)

retrolefty

http://support.atmel.com/bin/customer.exe?=&action=viewKbEntry&id=21

Lefty

Go Up