avr: bootloader partially works now but stops after 3 messages...

This commit is contained in:
Martin Preuss
2025-01-20 23:47:13 +01:00
parent 0d7aca0060
commit 0a10d136d5
23 changed files with 398 additions and 1260 deletions

View File

@@ -9,6 +9,22 @@
; ***************************************************************************
; data
.dseg
flashDataBegin:
flashUid: .byte 4
flashSendBuffer: .byte 32
flashRecvBuffer: .byte FLASH_RECVBUFFER_MAXLEN
flashDataEnd:
; ***************************************************************************
; code
.cseg
@@ -23,15 +39,16 @@
; @clobbers r16, r20, X, (r17, r18, r19, r22, y, z)
checkFlash:
rcall flashInitIo ; (R16, R17)
rcall flashReadUidIntoSdram ; R16, X, Y
rcall ioRawInit ; (R16, R17)
ldi xl, LOW(flashSendBuffer)
ldi xh, HIGH(flashSendBuffer)
rcall flashProcessWriteFlashReady ; (R16, R17, R18, R19, R20, Y, Z)
rcall flashRawSendMsg ; (r16, r17, X)
rcall ioRawSendMsg ; (r16, r17, X)
ldi r16, CPRO_CMD_FLASH_START
ldi r20, 10 ; wait for up to 10s
rcall flashWaitForGivenMsg ; (r16, r17, r18, r19, r20, r22, X)
rcall ioWaitForGivenMsg ; (r16, r17, r18, r19, r20, r22, X)
brcc checkFlash_end
cpi r16, CPRO_CMD_FLASH_START
@@ -66,8 +83,8 @@ flashProcess:
flashProcess_loop1:
; wait up to 10s for incoming FLASH_DATA message
ldi r16, CPRO_CMD_FLASH_DATA
ldi r20, 5 ; wait for 5s
rcall flashWaitForGivenMsg ; (r16, r17, r18, r19, r20, r22, X)
ldi r20, 5 ; wait for 5s (not used!)
rcall ioWaitForGivenMsg ; (r16, r17, r18, r19, r20, r22, X)
brcc flashProcess_end ; no FLASH_DATA or FLASH_END msg
; either FLASH_DATA or FLASH_END received
ldi xl, LOW(flashRecvBuffer)
@@ -156,17 +173,17 @@ flashProcessHandleFlashData:
ld zh, X+ ; address (high)
adiw xh:xl, 2 ; ignore high bytes, points to first data byte now
push zl
push zh
flashProcessHandleFlashData_loop:
ld r0, X+
ld r1, X+
rcall Flash_WriteIntoPage ; (R15, R16, Z+)
subi r18, 2
brne flashProcessHandleFlashData_loop
pop zh
pop zl
rcall Flash_FinishPage ; (R15, R16, R20)
; push zl
; push zh
;flashProcessHandleFlashData_loop:
; ld r0, X+
; ld r1, X+
; rcall Flash_WriteIntoPage ; (R15, R16, Z+)
; subi r18, 2
; brne flashProcessHandleFlashData_loop
; pop zh
; pop zl
; rcall Flash_FinishPage ; (R15, R16, R20)
clr r16
rjmp flashProcessHandleFlashData_sendResponse
flashProcessHandleFlashData_badData:
@@ -210,7 +227,7 @@ flashProcessSendFlashResponse:
ldi xl, LOW(flashSendBuffer)
ldi xh, HIGH(flashSendBuffer)
rcall flashProcessWriteFlashRsp ; (R16, R17, R18, R19, R20, X)
rjmp flashRawSendMsg ; (R16, R17, X)
rjmp ioRawSendMsg ; (R16, R17, X)
; @end