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

@@ -38,6 +38,9 @@
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
;#define COM_ACCEPT_ALL_DEST 1
; ---------------------------------------------------------------------------
; LED
@@ -112,38 +115,8 @@ firmwareStart: rjmp main ; will be overwritten when flashing
main:
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
#if 1
; 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
#endif
rcall systemSetSpeed
; rjmp debugUsart2
rjmp bootLoader ; this routine is in modules/flash/bootloader2.asm
; rjmp debugEchoUart1
rjmp bootLoader ; this routine is in modules/bootloader/main.asm
@@ -151,8 +124,6 @@ main:
; ***************************************************************************
; includes
;.include "modules/uart_bitbang/bytelevel.asm"
;.include "modules/uart_bitbang/packetlevel.asm"
.include "modules/uart_hw/raw_uart1.asm"
.include "modules/com2/crc.asm"
.include "common/crc8.asm"
@@ -160,140 +131,12 @@ main:
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/bootloader2.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_uart1.asm"
.include "modules/flash/flash.asm"
.include "modules/flash/flashprocess.asm"
;.include "modules/flash/recv.asm"
;.include "modules/flash/send.asm"
.include "modules/flash/wait.asm"
;.include "modules/flash/hdl_flash_start.asm"
;.include "modules/flash/hdl_flash_data.asm"
;.include "modules/flash/hdl_flash_end.asm"
;include "modules/flash/flash_rsp.asm"
;include "modules/flash/flash_ready.asm"
#if 0
debugUsart1:
sbi LED_DDR, LED_PINNUM ; out
cbi LED_PORT, LED_PINNUM ; on
ldi r16, 3 ; (19.2Kb/s at 1MHz)
ldi r17, 0
sts UBRR1H, r17
sts UBRR1L, r16
ldi r16, (3<<UCSZ10)
sts UCSR1C, r16
lds r16, UCSR1B
cbr r16, (1<<UDRIE1) ; disable DRE interrupt
sbr r16, (1<<TXEN1) ; enable transmit
sts UCSR1B, r16
; ldi r16, (1<<UDRE1)
; sts UCSR1A, r16
clr r18
debugUsart1_loop:
debugUsart1_loop2:
lds r16, UCSR1A
sbrs r16,UDRE1
rjmp debugUsart1_loop2
; sbr r16, (1<<TXC1)
; sts UCSR1A, r16
sts UDR1, r18
cpi r18, 10
brne debugUsart1_skipLed
clr r18
rcall debugWaitFor100MilliSecs
sbi LED_PIN, LED_PINNUM ; toggle
debugUsart1_skipLed:
inc r18
rjmp debugUsart1_loop
#endif
debugUsart2:
sbi LED_DDR, LED_PINNUM ; out
cbi LED_PORT, LED_PINNUM ; on
ldi r16, 2 ; (19.2Kb/s at 1MHz)
; ldi r16, 25 ; (19.2Kb/s at 8MHz)
ldi r17, 0
sts UBRR1H, r17
sts UBRR1L, r16
ldi r16, (3<<UCSZ10)
sts UCSR1C, r16
lds r16, UCSR1B
cbr r16, (1<<UDRIE1) ; disable DRE interrupt
sbr r16, (1<<TXEN1) ; enable transmit
sts UCSR1B, r16
ldi xl, LOW(flashSendBuffer)
ldi xh, HIGH(flashSendBuffer)
rcall flashProcessWriteFlashReady ; (R16, R17, R18, R19, R20, Y, Z)
debugUsart2_loop:
rcall flashRawSendMsg ; (r16, r17, X)
rcall debugWaitFor100MilliSecs
sbi LED_PIN, LED_PINNUM ; toggle
rjmp debugUsart2_loop
#if 0
debugStop:
cli
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
ldi r18, 0
test_loop1:
ldi r16, 100
test_loop2:
ldi r17, 100
test_loop3:
Utils_WaitNanoSecs 10000, 0, r22
dec r17
brne test_loop3
dec r16
brne test_loop2
sbi LED_SIMPLE_PORTIN, LED_SIMPLE_PINNUM ; toggle
inc r18
mov r19, r18
andi r19, 1
brne test1
sbi COM_ATTN_DDR, COM_ATTN_PIN
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
rjmp test_loop1
test1:
cbi COM_ATTN_DDR, COM_ATTN_PIN
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
rjmp test_loop1
#endif
debugWaitFor100MilliSecs:
ldi r16, 10
debugWaitFor10MilliSecs_loop1:
ldi r17, 100
debugWaitFor10MilliSecs_loop2:
rcall Utils_WaitFor100MicroSecs ; 10ms
dec r17
brne debugWaitFor10MilliSecs_loop2
dec r16
brne debugWaitFor10MilliSecs_loop1
ret
.include "modules/bootloader/main.asm"
@@ -316,3 +159,89 @@ systemSetSpeed:
; debug
debugEchoUart1:
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
rcall systemSetSpeed
sbi LED_DDR, LED_PINNUM ; out
cbi LED_PORT, LED_PINNUM ; on
; set baudrate
.if clock == 8000000
ldi r16, 25 ; (19.2Kb/s at 8MHz)
ldi r17, 0
.endif
.if clock == 1000000
ldi r16, 3 ; (19.2Kb/s at 1MHz)
ldi r17, 0
.endif
sts UBRR1H, r17
sts UBRR1L, r16
; set character format (asynchronous USART, 8-bit, one stop bit, no parity)
ldi r16, (3<<UCSZ10)
sts UCSR1C, r16
; enable transceiver
lds r16, UCSR1B
; cbr r16, (1<<UDRIE1) ; disable DRE interrupt
ori r16, (1<<RXEN1) | (1<<TXEN1) ; enable transmit and receive
sts UCSR1B, r16
ldi zl, LOW(debugString*2)
ldi zh, HIGH(debugString*2)
rcall debugWriteString
debugEchoUart1_loop:
rcall debugReadByte
sbi LED_PIN, LED_PINNUM ; toggle
rcall debugWriteByte
rjmp debugEchoUart1_loop
debugReadByte:
lds r17, UCSR1A
sbrs r17, RXC1
rjmp debugReadByte
lds r16, UDR1
ret
debugWriteByte:
lds r17, UCSR1A
sbrs r17, UDRE1
rjmp debugWriteByte
; sbr r17, (1<<TXC1)
; sts UCSR1A, r17
sts UDR1, r16
ret
debugWriteString:
lpm r16, Z+
tst r16
breq debugWriteString_done
rcall debugWriteByte
rjmp debugWriteString
debugWriteString_done:
ret
debugString: .db "Hello", 13, 10, 0