help me with that bootloader

For problems with Gamebuino itself, NOT your project

Re: help me with that bootloader

Postby jonnection » Tue Jul 01, 2014 10:46 am

albertinjo wrote:The bootloader works really weird on my aruino, the loader sketch works fine, I can read files from my sd card with the SDfat library. Only problem is that I cant invoke the loader sketch while holding the C button on startup??


I got interested and looked at the code.

The bootloader code does not "wait" to read the state of the C button at all, it is checking the state once and almost immediately after reset.

My suspicion is that there is nothing wrong with the code, but that your C button, reason or another, is not low when the bootloader runs (line 307 in gamebuino_boot.c in GitHub). It can pick up interference from an adjacent pin or something. Another factor overlooked sometimes is that breadboarded circuits behave slightly differently to circuitboarded circuits due to the electrical characteristics of a breadboard. This can affect the volatility of a pin, especially directly after a reset. (Myndale can correct me if I'm talking rubbish).

I would try these two tricks:

1) Force the button C (PC3, arduino pin A03) into low state by binding it to GND through a 10k resistor. Then reset and see if loader comes up.

2) If this helps, remove resistor and write a small waiting loop around the C button state check on line 307 in gamebuino_boot.c
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: help me with that bootloader

Postby ripper121 » Tue Jul 01, 2014 10:59 am

jonnection wrote:
albertinjo wrote:The bootloader works really weird on my aruino, the loader sketch works fine, I can read files from my sd card with the SDfat library. Only problem is that I cant invoke the loader sketch while holding the C button on startup??


I got interested and looked at the code.

The bootloader code does not "wait" to read the state of the C button at all, it is checking the state once and almost immediately after reset.

My suspicion is that there is nothing wrong with the code, but that your C button, reason or another, is not low when the bootloader runs (line 307 in gamebuino_boot.c in GitHub). It can pick up interference from an adjacent pin or something. Another factor overlooked sometimes is that breadboarded circuits behave slightly differently to circuitboarded circuits due to the electrical characteristics of a breadboard. This can affect the volatility of a pin, especially directly after a reset. (Myndale can correct me if I'm talking rubbish).

I would try these two tricks:

1) Force the button C (PC3, arduino pin A03) into low state by binding it to GND through a 10k resistor. Then reset and see if loader comes up.

2) If this helps, remove resistor and write a small waiting loop around the C button state check on line 307 in gamebuino_boot.c


I think there is a internal PullUp/Down resistor that you can activate
User avatar
ripper121
 
Posts: 224
Joined: Fri Apr 04, 2014 2:02 pm
Location: Germany

Re: help me with that bootloader

Postby rodot » Tue Jul 01, 2014 11:04 am

jonnection wrote:1) Force the button C (PC3, arduino pin A03) into low state by binding it to GND through a 10k resistor. Then reset and see if loader comes up.

The microcontroller resets once the loader is loaded... so it will enter in an infinite loop where it continuously flash the loader (an wear out the flash memory). You won't even have time to see the loader screen before it starts to flash the loader again. If I were you I would NOT DO THAT.

ripper121 wrote:I think there is a internal PullUp/Down resistor that you can activate

The atmega has internal 20k pull up resistors on each pin you can activate (or not). They are already activated in the bootloader, so you just have to bridge the input to the GND to set it to LOW (just like in schematics).
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: help me with that bootloader

Postby jonnection » Tue Jul 01, 2014 5:46 pm

rodot wrote:
jonnection wrote:1) Force the button C (PC3, arduino pin A03) into low state by binding it to GND through a 10k resistor. Then reset and see if loader comes up.

The microcontroller resets once the loader is loaded... so it will enter in an infinite loop where it continuously flash the loader (an wear out the flash memory). You won't even have time to see the loader screen before it starts to flash the loader again. If I were you I would NOT DO THAT.


Rodot is right. When C is pressed after reset it goes directly to load_loader, inputs LOADER.hex as filename, jumps to load_file, loads LOADER.hex and flashes it to memory. Then reboots with watchdog set to 16ms.

... wait a minute ...

So is there nothing stopping the AVR from flashing the Loader.hex (worst case) 62,5 times per second, if I hold down the C button for 1 sec too long while booting ? Shouldn't there at least be a check that C button has been released before repeating the loop ? I'm sorry for being such an ass, but what if someone holds the C button down continuously, out of stupidity ?

Also, couldn't the load_loader first check whether LOADER.hex is already in program memory before reflashing, to avoid reflashing for no good reason ?
Last edited by jonnection on Tue Jul 01, 2014 5:56 pm, edited 1 time in total.
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: help me with that bootloader

Postby rodot » Tue Jul 01, 2014 5:51 pm

jonnection wrote:but what if someone holds the C button down continuously, out of stupidity ?

What if someone powers its Gamebuino with 220V :3
Well it won't flash the loader 60 times per second, because it takes a few seconds to load it. But yes you can holding down the C buttons will continuously flash the loader. I just wonder why someone would hold down the C buttons for weeks until the flash memory wears out :P
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: help me with that bootloader

Postby jonnection » Tue Jul 01, 2014 6:01 pm

rodot wrote:
jonnection wrote:but what if someone holds the C button down continuously, out of stupidity ?

What if someone powers its Gamebuino with 220V :3
Well it won't flash the loader 60 times per second, because it takes a few seconds to load it. But yes you can holding down the C buttons will continuously flash the loader. I just wonder why someone would hold down the C buttons for weeks until the flash memory wears out :P


On the contrary. Jammed keys is usually always somehow taken into account. You can test this with almost any device, you will find there is some sort of fail-safe mechanism.

EDIT: In any case, Rodot is right. Do not pull down C with a resistor as I said, that was bad advice

I'm going to build and burn the bootloader myself and start digging into it, perhaps I will find out something for Albertinjo. I will dig into the SPI communication between the bootloader and the SD card with my logic analyzer to get a better idea of whats going on.
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: help me with that bootloader

Postby DFX2KX » Wed Jul 02, 2014 6:24 pm

jonnection wrote:
rodot wrote:
jonnection wrote:but what if someone holds the C button down continuously, out of stupidity ?

What if someone powers its Gamebuino with 220V :3
Well it won't flash the loader 60 times per second, because it takes a few seconds to load it. But yes you can holding down the C buttons will continuously flash the loader. I just wonder why someone would hold down the C buttons for weeks until the flash memory wears out :P


On the contrary. Jammed keys is usually always somehow taken into account. You can test this with almost any device, you will find there is some sort of fail-safe mechanism.

EDIT: In any case, Rodot is right. Do not pull down C with a resistor as I said, that was bad advice

I'm going to build and burn the bootloader myself and start digging into it, perhaps I will find out something for Albertinjo. I will dig into the SPI communication between the bootloader and the SD card with my logic analyzer to get a better idea of whats going on.


You mean, like after a loop or two giving a 'faulty key' error of some sort?
DFX2KX
 
Posts: 250
Joined: Mon Apr 14, 2014 3:48 am

Re: help me with that bootloader

Postby rodot » Wed Jul 02, 2014 8:04 pm

Problem is that it was pretty tight to fit the bootloader in 2048B, I'm afraid I won't be able to add this security to prevent people from continuously flashing the loader.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: help me with that bootloader

Postby jonnection » Wed Jul 02, 2014 9:58 pm

Code: Select all
while (PINC & (1<<PC3)) {}


before reboot ? That will catch situation where C is still pressed after flashing and prevent infinite loop.

But I'm confident you are right, the user will notice the flashing going on ( is there some indication btw ? ) and understand to release the key.

You see, I haven't actually tried it out yet / do not have the Gamebuino in hardware, so I don't know what it feels like yet. I'm sure its self evident when you try it on the real hardware.
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: help me with that bootloader

Postby rodot » Wed Jul 02, 2014 10:23 pm

Well the current version of the bootloader works fine and I don't want to change it the day before I receive 1000 gamebuino, I think it's too risky, I don't want to ship gamebuino with a broken bootloader. I never had the problem of holding down the C buttons, neither did any person who used a Gamebuino. If on day it appears to be a major problem I'll work on that, but for now I'm pretty busy writing the documentation and assembling gameubinos to be on time :(
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

PreviousNext

Return to Installation & Troubleshooting

Who is online

Users browsing this forum: No registered users and 10 guests

cron