avr: bootloader partially works now but stops after 3 messages...
This commit is contained in:
92
avr/modules/bootloader/main.asm
Normal file
92
avr/modules/bootloader/main.asm
Normal file
@@ -0,0 +1,92 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2025 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
; * This file is part of the project "AqHome". *
|
||||
; * Please see toplevel file COPYING of that project for license details. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
BOOTLOADER_BEGIN:
|
||||
|
||||
|
||||
|
||||
|
||||
bootLoader:
|
||||
cli
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
ldi r16, High(RAMEND)
|
||||
out SPH, r16 ; init MSB stack pointer
|
||||
.endif
|
||||
ldi r16, Low(RAMEND)
|
||||
out SPL, r16 ; init LSB stack pointer
|
||||
|
||||
; start by setting all ports as inputs and enable internal pull-up resistors
|
||||
ldi r16, 0xff
|
||||
clr r17
|
||||
.ifdef PORTA
|
||||
out DDRA, r17 ; all input
|
||||
out PORTA, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
.ifdef PORTB
|
||||
out DDRB, r17 ; all input
|
||||
out PORTB, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
.ifdef PORTC
|
||||
out DDRC, r17 ; all input
|
||||
out PORTC, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
rcall systemSetSpeed
|
||||
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
|
||||
|
||||
sbi LED_DDR, LED_PINNUM ; out
|
||||
cbi LED_PORT, LED_PINNUM ; on
|
||||
ldi r16, 30
|
||||
rcall flashWaitForMulti100ms
|
||||
rcall checkFlash ; (r16, r17, r18, r19, r20, r22, x, y, z)
|
||||
brcc bootLoader_startFirmware ; no flash process, try to start installed firmware
|
||||
rcall flashProcess ; received a FLASH START msg, handle flashing
|
||||
brcc bootLoader_waitAndRestartBootLoader
|
||||
; try to start firmware
|
||||
bootLoader_startFirmware:
|
||||
cbi LED_PORT, LED_PINNUM ; on
|
||||
rjmp firmwareStart
|
||||
bootLoader_waitAndRestartBootLoader:
|
||||
sbi LED_PORT, LED_PINNUM ; off
|
||||
ldi r16, 20
|
||||
rcall flashWaitForMulti100ms
|
||||
rjmp bootLoader
|
||||
|
||||
|
||||
|
||||
bootClcRet:
|
||||
clc
|
||||
bootRet:
|
||||
ret
|
||||
|
||||
bootSecRet:
|
||||
sec
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BOOTLOADER_END:
|
||||
.equ MODULE_SIZE_BOOTLOADER = BOOTLOADER_END-BOOTLOADER_BEGIN
|
||||
|
||||
|
||||
Reference in New Issue
Block a user