Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

atmega64a bootloading

Status
Not open for further replies.

pallavibsh

Newbie level 6
Joined
May 9, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,370
hi all

am doing a bootloading for atmega64a

my doubt is when we enable SPMIE than code enters into bootloader section later a file is downloaded than will the code run by itself in BLS or i need to write a separate bootloader program to erase chip and than boot_write with updated code.

ex

if (SPM enabled)

{
// Rx file through sim900 gsm AT-commands.

[ is bootloader progrm required here to erase chip and write the BLS with updated code ]

}

else

{

// normal application code.

}

pls help


regards,
pallavi
 

generally any AVR microcontroller, needs a separated bootloader program at the BLS, where you receive data and program the AppSection.. YOU CAN'T PROGRAM the App Section FROM the same AppSection!!! the SPM instruction doesn't work from other section than the BLS....

If you want to use the SPM interrupt (enabling SPMIE) your bootloader code should be in the BLS, and move your interrupts to the BLS, (change IVSEL) don't forget to restore IVSEL when your bootlader ends...

a common way is ALWAYS starts at the bootloader section (BOOTRST=0) and check some condition, if the condition is false, then restore IVSEL and jump to the APPSection, if you need to start the bootloader from the app section, just force the condition,and jump to the BLS, this way, if your main application gets corrupted, the bootloader will always works... (of course if you corrupt the BLS, there is nothing left to do... but what are the boot locking bits for?)
 

[

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
void erase_flash(void)
{
        int i = 0;
        int page = 0;
 
        cli();
 
        for(i=0; i < MAX_PAGES; page += 256, i++)
        {
                boot_page_erase(page);         /** 1 flash page of Atmega64A = 256 bytes  **/
                boot_spm_busy_wait();           /** Wait until the memory is erased **/
        }
    boot_rww_enable ();
        sei();
}
 
void write_to_flash(int start_page, char *response, int recv_bytes)
{
        int i = 0, data = 0;
        int page =0;
 
        /** Disable interrupts **/
        cli();
       
        for(page = start_page; (page < (start_page + recv_bytes)); page += 256, response += 256)
        {
                print_ssd_delay("WRITE FLASH",0,100);
                /** fill the bootloader temporary page buffer **/
                for(i=0; (i < FLASH_PAGESIZE) && (*response != '\0'); i+=2)
                {
                        data = *response++;
                        data += ((*response++) << 8);
 
                        boot_page_fill(page+i, data);
                }
                           boot_page_write (page);
                boot_spm_busy_wait();
        }
    boot_rww_enable ();
        sei();
}



]

jump bootloader, erase flash, read new firmware version correctly. But it is not written to the flash it does not start the new firmware after jmping to 0x00.and again bootloader section runs. this continious forever.

help pls!!!!
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top