Pages: [1]   Go Down
Author Topic: Bootloader for Atmega32u4 (store new sketch and jump there)  (Read 466 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.

I trying to make new bootloader for my Arduino Leonardo (basically just Atmega 32u4), and make it simple as possible.
Just reading from serial (uart) and want to write the data into flash memory (new sketch).

So exactly now, I can read character from UART, that’s means I can just push hex files through putty to Atmega32u4, I am already done with this part.
On my bootloader it is a watchdog, who interrupt after 8 sec.
So I want to read from my UART and save the hex file and put them into flash memory. After 8 sec, in my ISR intterup, I want to quit the bootloader and go to start of my new sketch.

With the hex file, I means that I have already write very simple sketch and compile it with Arduino and I have the final hex file, who I want to push through putty to UART.

So I have 2 questions.
- How can I store hex file into flash memory?
Will this work?
Code:
    char *rxByte = (char*) malloc(sizeof(char));
    *rxByte = uart_getchar();
    char rxByteValue = *rxByte;
    if(rxByteValue != '\0'){
      char *flash[] PROGMEM = {rxByte};
     }
- How can I tell my ISR function, that I want to quit bootloader and go to start of sketch. Where is start of my new sketch and how can I jump there?

Thank you in advance
Logged

USA Washington state coast
Offline Offline
Full Member
***
Karma: 6
Posts: 184
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sketch must be loaded starting at location 0x00. A reset will start executing code at 0x00.
Logged

I'm not a complete idiot. Some parts are missing.

USA Washington state coast
Offline Offline
Full Member
***
Karma: 6
Posts: 184
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Something along these lines but I don't know if it will work.
Code:
word counter = 0;
    char *rxByte = (char*) malloc(sizeof(char));
    while (*rxByteValue  != "\0")
      {
      *rxByte = uart_getchar();
       char rxByteValue = *rxByte;
//   if(rxByteValue != '\0'){
       char *flash[counter++] PROGMEM = {rxByte};
       }
« Last Edit: July 02, 2014, 08:35:25 pm by pegwatcher » Logged

I'm not a complete idiot. Some parts are missing.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So that means that I have to store the sketch into memory space 0x00?
How can I specify my location? Because I thought PROGMEM will give me a random free space!
Do I need to specify this location?
If I store my sketch in 0x00, so where is my bootloader located then?
Do I need reset again after when the sketch is uploaded?
This means that I have go through the bootloader again!

 pegwatcher:
I can see any (signifintcal) differences between mine and your code!
Can you explain if I am Wrong.
« Last Edit: July 03, 2014, 12:37:11 am by arian88 » Logged

USA Washington state coast
Offline Offline
Full Member
***
Karma: 6
Posts: 184
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.atmel.com/images/doc1644.pdf
Logged

I'm not a complete idiot. Some parts are missing.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Thanks alot. I gonna read this article now, I will let you know. Do I need to read more?

By the way: Why I writing my own bootloader?
Is that any better solution for my problem?

My problem is 32u4 it a USB chip microcontroller (as you know)
and the most bootloader out there (for this chip) are based to read from D+/D- and write in into flash memory! But I want to read from UART and write in into flash memory.
So instead of using USB (most bootloader for this microcontroller to that), I want to read from UART and save the hex/sketch file into flash memory!

That’s why I decide to write my own bootloader and why I cant use USB as new sketch receiver.

Have anyone suggestion to how I can change the bootloader from Arduino (Caterina) to get the sketch from UART and not USB!?
I dont need necessary to build my own bootloader if I can get same point from other bootloaders!
Logged

Pages: [1]   Go Up
Jump to: