HI
i use my own bootloader ,but i notice that when use arduino code
the code not run as long i not cycle power to the board , i knot it jump to application code
but not seem to run
have check for make sure IVSEL = 0 but still clue less
also have try to use watchdog but still need to cycle power for make it run ???
this is the interesting part of my code ....
so reset vector jump to boot ,if MCUSR was clear we stay in boot
if MCUSR have some bit set (reset ,watchdog ,power ) we check if the flash checksum match
if match go to application ,if not we stay in boot and wait for encrypted hex file via RTU modbus ...
any idea ??? ( that boot work whit other code that arduino )
.org 0x3e00 ;BSTART
RESET:
wdr
; INITIALIZE Stack Pointer
ldi temp,low(RAMEND)
out SPL,temp
ldi temp,high(RAMEND)
out SPH,temp
ldi temp, 0xff
out DDRD,temp
sbi PORTD ,2 ; flag pin for know we are in boot (only for debog)
cli
ldi temp, (1<<RXEN0)|(1<<TXEN0) ; enable the reciever and the ransmitter
sts UCSR0B, temp
ldi temp, BAUDDIVH ; baudrate
sts UBRR0H, temp
ldi temp, BAUDDIVL
sts UBRR0L, temp
ldi temp,0b00000000 ; ALL timer stoped
out tccr0A,temp
clr r10 ; used for end of file detected
sbi DDRC_485,DIR_485
cbi PORT_485,DIR_485
ser temp
mov RC4_KEYINITD,temp ; set RC-4 as un-initialized
in temp,MCUSR ; if aplication call bootloader syat in boot ..
tst temp
breq BOOTLOADER ; if reset source is clear stay in boot
rcall Flash_Check_SUM ; Test Checksum If Bad Go Bootloader
clr R17 ; Good Checksum so jump to aplication
out MCUSR,r17 ;clear the reset source
cbi ddrb,1
sbi portB,1
nop
sbic pinB,1 ; if MOSI pin is low stay in boot
jmp 0x0000
BOOTLOADER:
mov HEX_type,r10
cpi HEX_type,$21 ; got last line of new to flash
brne GET_RTU_Frame ; no so stay in boot for next line
jmp 0x0000 ; yes so go in application
;----------------------------------------------------------------------------;
Flash_Check_SUM:
clr ZH
clr ZL
clr XH
clr XL
FCK_1:
wdr
lpm R1,z+
add XL,R1
brcc FCK_2
inc XH ;carry set so inc Hi Bit
FCK_2:
cpi ZH,HIGH(BSTART*2 -16)
brne FCK_1
cpi ZL,LOW(BSTART*2 -16)
brne FCK_1
lpm R0,Z+
lpm R1,Z
cp R0,XH
brne CK_Fail
cp R1,XL
brne CK_Fail
ret
CK_Fail:
sbi PORTD ,3 ; check sum fail
rjmp BOOTLOADER ;Flash is Corup go self update .....