Help Porting Wireless Bootloader to MEGA (1280)?


hey guys...

anyone want me tackle project of porting bootloader mega 1280?

http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=122

i've got working what... it's accepting bytes streamer , completes... however... it's not starting program.  wonder if it's fuse setting or makefile changes (don't think so) or bootloader (highly likely).

this should quick port... need set of eye on it...  we post results on sparkfun site.

danny

changes made work on mega 1280 (still not working 100% -- won't start program):
code: [select]

#include <avr/io.h>
#include <avr/boot.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>

//define baud rate
#define baud   19200 //works internal osc
//#define baud   38400 //works internal osc
//#define baud   57600 //does not work internal osc
#define myubrr (((((cpu_speed * 10) / (16l * baud)) + 5) / 10) - 1)

//here calculate wait period inside getch(). few cycles , xbee may not able send character in time. long , sketch take long time boot after powerup.
#define cpu_speed      16000000
#define max_character_wait      15 //10 works. 20 works. 5 throws sorts of retries, work.
#define max_wait_in_cycles ( ((max_character_wait * 8) * cpu_speed) / baud )

//i have found flow control not needed implementation of wireless bootloading.
//adding flow control wireless support
//#define sbi(port_name, pin_number)   (port_name |= 1<<pin_number)
//#define cbi(port_name, pin_number)   (port_name &= (uint8_t)~(1<<pin_number))
//#define cts            2 //this input xbee. if low, xbee busy - wait.
//#define rts            3 //this output xbee. if we're busy, pull line low tell xbee not transmit characters atmega's uart

#define true      0
#define false      1

//status led
/* onboard led connected pin pb7 (e.g. crumb128, probomega128, savvy128, arduino mega) */
#define led_ddr  ddrb
#define led_port portb
#define led_pin  pinb
#define led      pinb7


//function prototypes
void putch(char);
char getch(void);
void flash_led(uint8_t);
void onboard_program_write(uint32_t page, uint8_t *buf);
void (*app_start)(void) = 0x0000;

//variables
uint8_t incoming_page_data[256];
uint8_t page_length;
uint8_t retransmit_flag = false;

union page_address_union {
     uint16_t word;
     uint8_t  byte[2];
} page_address;

int main(void)
{
     uint8_t check_sum = 0;
     uint16_t i;

   //setup usart baud rate
   ubrr0h = myubrr >> 8;
   ubrr0l = myubrr;
   ucsr0a = 0x00;
     ucsr0c = 0x06;
     //ucsr0b = _bv(txen0)|_bv(rxen0);
   ucsr0b = (1<<rxen0)|(1<<txen0);

   /* enable internal pull-up resistor on pin d0 (rx), in order
           to supress line noise prevents bootloader from
           timing out (dam: 20070509) */
           /* feature added arduino mega --dc: 080930 */
           ddre &= ~_bv(pine0);
     porte |= _bv(pine0);

     //set led pin output
     led_ddr |= _bv(led);

     //flash onboard led signal entering of bootloader
     flash_led(1);

     //start bootloading process

     putch(5); //tell world can bootloaded

     //check see if computer responded
     uint32_t count = 0;
     while(!(ucsr0a & _bv(rxc0)))
     {
           count++;
           if (count > max_wait_in_cycles)
           {
                 app_start();
           }
     }

     if(udr0 != 6) app_start(); //if computer did not respond correctly ack, jump user's program

     while(1)
     {
           //determine if last received data or bad
       if (check_sum != 0) //if check sum not compute, tell computer resend same line
restart:
           putch(7); //ascii character bell
       else
           putch('t'); //tell computer ready next line

       while(1) //wait computer initiate transfer
           {
                 if (getch() == ':') break; //this "gimme next chunk" command
                 if (retransmit_flag == true) goto restart;
           }

       page_length = getch(); //get length of block
           if (retransmit_flag == true) goto restart;

       if (page_length == 's') //check see if done - "all done" command
           {
                 boot_rww_enable (); //wait flash writes complete?
                 app_start();
           }

           //get memory address @ store block of data
           page_address.byte[0] = getch(); if (retransmit_flag == true) goto restart;
           page_address.byte[1] = getch(); if (retransmit_flag == true) goto restart;

       check_sum = getch(); //pick check sum error dectection
           if (retransmit_flag == true) goto restart;

           for(i = 0 ; < page_length ; i++) //read program data
           {
           incoming_page_data[i] = getch();
                 if (retransmit_flag == true) goto restart;
           }

       //calculate checksum
           for(i = 0 ; < page_length ; i++)
           check_sum = check_sum + incoming_page_data[i];

       check_sum = check_sum + page_length;
       check_sum = check_sum + page_address.byte[0];
       check_sum = check_sum + page_address.byte[1];

       if(check_sum == 0) //if have transmission, put in ink
           onboard_program_write((uint32_t)page_address.word, incoming_page_data);
     }

}

#define spm_pagesize 128
void onboard_program_write(uint32_t page, uint8_t *buf)
{
     uint16_t i;
     uint8_t sreg;

     // disable interrupts.

     sreg = sreg;
     cli();

     eeprom_busy_wait ();

     boot_page_erase (page);
     boot_spm_busy_wait ();      // wait until memory erased.

     for (i=0; i<spm_pagesize; i+=2)
     {
           // set little-endian word.

           uint16_t w = *buf++;
           w += (*buf++) << 8;

           boot_page_fill (page + i, w);
     }

     boot_page_write (page);     // store buffer in flash page.
     boot_spm_busy_wait ();       // wait until memory written.

     // reenable rww-section again. need if want jump back
     // application after bootloading.

     boot_rww_enable ();

     // re-enable interrupts (if ever enabled).

     sreg = sreg;
}

void putch(char ch)
{
     //adding flow control - xbee testing
     //while( (pind & (1<<cts)) != 0); //don't send xbee, thinking

     while (!(ucsr0a & _bv(udre0)));
     udr0 = ch;
}

char getch(void)
{
     retransmit_flag = false;

     //adding flow control - xbee testing
     //cbi(portd, rts); //tell xbee okay send serial characters

     uint32_t count = 0;
     while(!(ucsr0a & _bv(rxc0)))
     {
           count++;
           if (count > max_wait_in_cycles) //
           {
                 retransmit_flag = true;
                 break;
           }
     }

     //adding flow control - xbee testing
     //sbi(portd, rts); //tell xbee hold serial characters, busy doing other things

     return udr0;
}

void flash_led(uint8_t count)
{
     uint8_t i;

     for (i = 0; < count; ++i) {
           led_port |= _bv(led);
           //_delay_ms(100);
           led_port &= ~_bv(led);
           //_delay_ms(100);
     }
}



original working code 328p available here:
http://www.sparkfun.com/tutorial/wirelessbootloader/wireless_bootloader_atmega328.c

so have saving program space... however, it's not placing bytes in correct areas shown below:

code: [select]
:20000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
:20002000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0
:20004000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0
:20006000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa0
:200080000c942e010c942e010c942e010c942e010c9424030c942e010c942e010c942e01f0
:2000a0000c942e010c942e010c942e010c942e010c942e010c942e010c942e010c942e01c8
:2000c0000c942e010c942e010c942e010c9465030c942e010c942e010c94a6030c942e01f5
:2000e0000c942e0100002100240027002a002d003000330001010000040107010a010000f1
:20010000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
:20012000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdf
:20014000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbf
:20016000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9f
:20018000204010204080020102010804020101020408102040808040201008040201800478
:2001a000020180402010080402010804020101020408102040800102040810204080000030
:2001c000090a02080b0c0d07060304010000000000000000000000000000000000000000c9
:2001e00000000000000000000000100f0e00000000000000000000000000000000000000d2
:20020000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
:20022000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffde
:20024000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbe
:20026000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9e
:2002800080e090e00e94ad018091070260e00e945802c80163e072e00e94f00668ee73e049
:2002a00080e090e00e94ad011f910f9108958091070261e00e9438028de294e040e05be4b8
:2002c00060e070e00e94e70308951f920f920fb60f9211242f933f938f939f93af93bf93fc
:2002e0008091180290911902a0911a02b0911b0230911c020196a11db11d232f2d5f2d37a8
:20030000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd
:20032000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdd
:20034000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbd
:20036000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9d


any ideas why?  


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Help Porting Wireless Bootloader to MEGA (1280)?


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums