avr: t03 runs in basic mode now, flashing of AtTiny841 finally works!!
This commit is contained in:
@@ -115,7 +115,6 @@ firmwareStart: rjmp main ; will be overwritten when flashing
|
||||
|
||||
|
||||
main:
|
||||
; rjmp debugEchoUart1
|
||||
rjmp bootLoader ; this routine is in modules/bootloader/main.asm
|
||||
|
||||
|
||||
@@ -124,16 +123,16 @@ main:
|
||||
; ***************************************************************************
|
||||
; includes
|
||||
|
||||
.include "modules/uart_hw/raw_uart1.asm"
|
||||
;.include "modules/uart_hw/raw_uart1.asm"
|
||||
.include "modules/com2/crc.asm"
|
||||
.include "common/crc8.asm"
|
||||
.include "common/utils_wait_fixed.asm"
|
||||
.include "common/utils_copy_from_flash.asm"
|
||||
.include "common/utils_copy_sdram.asm"
|
||||
.include "modules/flash/defs.asm"
|
||||
.include "modules/flash/eeprom.asm"
|
||||
.include "modules/flash/io.asm"
|
||||
.include "modules/flash/io_uart1.asm"
|
||||
.include "modules/flash/flash.asm"
|
||||
.include "modules/flash/flash4p.asm"
|
||||
.include "modules/flash/flashprocess.asm"
|
||||
.include "modules/flash/wait.asm"
|
||||
.include "modules/bootloader/main.asm"
|
||||
@@ -158,184 +157,3 @@ 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
|
||||
|
||||
|
||||
|
||||
debugPrintLoop:
|
||||
sbi LED_PORT, LED_PINNUM ; off
|
||||
; enable transceiver
|
||||
lds r17, UCSR1B
|
||||
; cbr r17, (1<<UDRIE1) ; disable DRE interrupt
|
||||
ori r17, (1<<RXEN1) | (1<<TXEN1) ; enable transmit and receive
|
||||
sts UCSR1B, r17
|
||||
|
||||
debugPrintLoop1:
|
||||
push r16
|
||||
rcall debugPrintHexByte
|
||||
ldi r16, 13
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r16, 10
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r16, 10
|
||||
rcall flashWaitForMulti100ms
|
||||
pop r16
|
||||
rjmp debugPrintLoop1
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine debugPrintHexByte
|
||||
;
|
||||
; Convert a give byte into HEX and write it to USART1.
|
||||
;
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @param R16 byte to convert to print
|
||||
; @clobbers r16, r20 (r17)
|
||||
|
||||
debugPrintHexByte:
|
||||
mov r20, r16
|
||||
swap r16
|
||||
rcall debugNibbleToAscii ; write high nibble (r17)
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
brcc debugPrintHexByte_error
|
||||
mov r16, r20
|
||||
rcall debugNibbleToAscii ; write low nibble (r17)
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
brcc debugPrintHexByte_error
|
||||
sec
|
||||
ret
|
||||
debugPrintHexByte_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine debugNibbleToAscii
|
||||
;
|
||||
; Convert a nibble to an ASCII char.
|
||||
; @return R16 ASCII representation of that nibble (e.g. '0' for 0)
|
||||
; @param R16 byte (in bits 0-3)
|
||||
; @clobbers r17
|
||||
|
||||
debugNibbleToAscii:
|
||||
andi r16, 0xf
|
||||
cpi r16, 10
|
||||
brcs debugNibbleToAscii_l1
|
||||
ldi r17, 7
|
||||
add r16, r17
|
||||
debugNibbleToAscii_l1:
|
||||
ldi r17, '0'
|
||||
add r16, r17
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine debugPrintOneChar
|
||||
;
|
||||
; Write one byte to UART1.
|
||||
; @param R16 byte to send
|
||||
; @clobbers r17
|
||||
|
||||
debugPrintOneChar:
|
||||
lds r17, UCSR1A
|
||||
sbrs r17, UDRE1
|
||||
rjmp debugPrintOneChar
|
||||
sbr r17, (1<<TXC1)
|
||||
sts UCSR1A, r17
|
||||
sts UDR1, r16
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user