[Solved] Linux: iggie01 uploader + danni bootloader: reset problem

1 post / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello. I search for simple and tiny serial software loader for AVR and Linux. I found this combination [1], [2] because it was recommended at avrfreaks forum somewhere. I test it, and it works exactly as i expect.

But it will not work (more precisely, uploader make huge delays at bootloader presence detection time) when two conditions occurs, 1) bootloader activated by RESET, i.e. not by just AVR PowerOn; and 2) AVR is transmitting serial stream during normal work.

"1" condition is unavoidable when one uses bluetooth serial bridge (HC-05 modules are simplest), for both normal data transfer and AVR software update. After PowerOn, it is rarely possible to HC-05 to boot and paired in just 0.3s allowed in bootloader. So additional AVR RESET should be applied after HC-05s interconnect, or during normal work when HC-05 already connected. (i use Reed switch to "remote" reset without opening box, but it is irrelevant) I.e. to update the software during normal work, one starts the uploader command, then apply RESET, as usual.

But uploader software is not so tolerant to existing serial stream issued by AVR, or more precisely, to received serial data exist in OS receive buffer before it starts. Happily, it can be easily fixed by one-liner: (pseudo-diff of 'bootloader.c')

		if (*reboot_chars) {
			usleep(10000);//wait 10ms
// During awaiting for RESET of AVR, in contrast of awaiting for its POWER_ON,
// there are transmitted chars may be issued by AVR during this period.
// They stucks in input buffers of OS and USB-Serial converter (128 to 1024 bytes?),
// and until they are not fully  readed, bootloader can't read correct answer.
// This gives huge delays before AVR bootloader's answer can be correctly detected.
// So flush of input buffer is needed.
// Also see https://stackoverflow.com/questions/13013387/clearing-the-serial-ports-buffer
// to see why direct flush of input buffer, when using USB-Serial, is not adequate.
while (com_getc(10) != -1) {} //ADDED: manually flush input buffer
		in = com_getc(0);

And this is not disturb other functions of software.
Hope that helps.

P.S. For beginners: this all is not tested/intended for Arduino, and/or USB upload cable.

[1] https://www.avrfreaks.net/projects/linux-bootloader-uploader?module=Freaks%20Academy&func=viewItem&item_id=1927&item_type=project
[2] https://www.avrfreaks.net/projects/fast-tiny-mega-uart-bootloader?module=Freaks%20Academy&func=viewItem&item_id=1008&item_type=project