Clean-up routine before new program upload ?

Hello all,

I am new to the Arduino world, even if i have a long experience (30 years already :o) as professional developper.

I understand that the bootloader calls once the setup() routine, then it calls the loop() routine forever.

I wonder if it can call some clean-up routine when the PC contacts it to upload a new program ? Or would it call the destructor method of global objects ? Or does it just stop abruptly the running program ?

I would like to stop cleanly before uploading new sketch: clean-up lcd and stop currently playing midi notes for example.

Thanx for your help.

I think you're imagiing that the AVR has more capabilities than it actually has.

When you upload a new sketch, you simply reset the processor, the bootloader runs and handshakes with the PC.

Anything that was running in the lower 14K of memory stops as soon as the bootloader starts.

If you want to stop at a known point before engaging the bootloader, you'll need to tell your sketch explicitly.