summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-07-26 15:10:14 +0000
committerChristian Pointner <equinox@mur.at>2013-07-26 15:10:14 +0000
commitafc62937c6602ccce0ae1d1c49c85d3f3e5505a7 (patch)
tree3a83f9af7d1bd55624602b37acd5ec1ae86f4f62
parentyet another downloader update (diff)
updated to new PIC bootloader with support for SPI and 16F1847
git-svn-id: https://svn.spreadspace.org/mur.sat@811 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r--software/pic.bootloader/Makefile2
-rw-r--r--software/pic.bootloader/Makefile-IHU2
-rw-r--r--software/pic.bootloader/bootloader-IHU.asm12
-rw-r--r--software/pic.bootloader/cmds-16f1847.inc167
-rw-r--r--software/pic.bootloader/cmds-16f887.inc11
-rw-r--r--software/pic.bootloader/com-16f1847-spi.inc78
-rw-r--r--software/pic.bootloader/com-16f1847-uart.inc76
-rw-r--r--software/pic.bootloader/com-16f887-spi.inc73
-rw-r--r--software/pic.bootloader/com-16f887-uart.inc8
-rwxr-xr-xsoftware/pic.bootloader/downloader.py53
-rw-r--r--software/pic.bootloader/generic-defines.inc2
-rw-r--r--software/pic.bootloader/generic-init.inc6
-rw-r--r--software/pic.bootloader/generic-mainloop.inc7
-rw-r--r--software/pic.bootloader/ihexpic.py2
-rw-r--r--software/pic.bootloader/proto.txt5
15 files changed, 463 insertions, 41 deletions
diff --git a/software/pic.bootloader/Makefile b/software/pic.bootloader/Makefile
index fb91150..8743497 100644
--- a/software/pic.bootloader/Makefile
+++ b/software/pic.bootloader/Makefile
@@ -2,7 +2,7 @@
## spreadspace pic utils
##
##
-## Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+## Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
##
## This file is part of spreadspace pic utils.
##
diff --git a/software/pic.bootloader/Makefile-IHU b/software/pic.bootloader/Makefile-IHU
index 4689f83..f576f64 100644
--- a/software/pic.bootloader/Makefile-IHU
+++ b/software/pic.bootloader/Makefile-IHU
@@ -2,7 +2,7 @@
## spreadspace pic utils
##
##
-## Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+## Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
##
## This file is part of spreadspace pic utils.
##
diff --git a/software/pic.bootloader/bootloader-IHU.asm b/software/pic.bootloader/bootloader-IHU.asm
index bdf56f8..14824d7 100644
--- a/software/pic.bootloader/bootloader-IHU.asm
+++ b/software/pic.bootloader/bootloader-IHU.asm
@@ -2,7 +2,7 @@
;; spreadspace pic utils
;;
;;
- ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
;;
;; This file is part of spreadspace pic utils.
;;
@@ -29,7 +29,7 @@
;; -------------------------------------
;; DEFINES (chip/com specific)
-#define BOOTPIN PORTA,4
+#define BOOTPIN PORTC,7
USERVECT EQU H'100'
ISRVECT EQU USERVECT + H'4'
FLASH_BOUNDARY EQU b'00001111' ; flash write boundary is at 16 bytes boundaries
@@ -47,6 +47,7 @@ FSS EQU .16 ; writing is done 8 words at a time but 16
EEPROM_SIZE_L EQU H'00'
EEPROM_SIZE_H EQU H'01' ; 0x0100 -> 256 Bytes of EEPROM
MESS EQU .64 ; this limit is because of to combuff size and single byte len field for messages
+CFG EQU .2 ; anyway this is not read or writable for this chip
SUPPORTED_H EQU .0
SUPPORTED_L EQU b'00000110' ; only read/write flash is supported by now
@@ -65,6 +66,13 @@ csum EQU H'0071'
flags EQU H'007D'
cnt EQU H'007F'
+ ;; Boot Macro
+bootmacro macro
+ btfsc BOOTPIN
+ goto USERVECT
+ goto com_init
+ endm
+
;; -------------------------------------
;; DEFINES (defines)
#include "generic-defines.inc"
diff --git a/software/pic.bootloader/cmds-16f1847.inc b/software/pic.bootloader/cmds-16f1847.inc
new file mode 100644
index 0000000..bed54b9
--- /dev/null
+++ b/software/pic.bootloader/cmds-16f1847.inc
@@ -0,0 +1,167 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+ ;; flash read --------
+cmd_reset
+ movlw E_OK
+ call ack_cmd
+ movlb .3
+cmd_resset_wait_ack
+ btfss TXSTA,TRMT
+ goto cmd_resset_wait_ack
+ reset
+
+ ;; flash read --------
+cmd_r_flash
+ movlw FSS ; initialize EEADR:EEADRH and FSR
+ movwf cnt
+ movlb .3
+ movlw combuff + .2
+ movwf FSR
+ movf INDF,w
+ movwf EEADRL
+ incf FSR,f
+ movf INDF,w
+ movwf EEADRH
+read_flash_segment_loop
+ bcf EECON1,CFGS ; perform the actual read
+ bsf EECON1,EEPGD
+ bsf EECON1,RD
+ nop
+ nop
+ movf EEDATL,w ; load code word from EEDAT:EEDATH to combuff
+ movwf INDF
+ incf FSR,f
+ movf EEDATH,w
+ movwf INDF
+ incf FSR,f
+ incfsz EEADRL,f ; increment flash address
+ goto read_flash_segment_next
+ incf EEADRH,f
+read_flash_segment_next
+ decfsz cnt,f
+ goto read_flash_segment_loop
+ movlb .0
+ clrf combuff + .2 ; = E_OK
+ movlw .1 + .2*FSS ; bytes to send
+ call send_answer
+ goto wait_new_cmd
+
+ ;; flash write --------
+cmd_w_flash
+ movlw .2 ; if addr[15:8] < 2 -> boot loader section
+ subwf combuff + .3,w
+ btfss STATUS,C
+ goto address_prohibited
+ movlw FLASH_BOUNDARY ; addr on boundary?
+ andwf combuff + .2,w
+ btfss STATUS,Z
+ goto address_invalid
+ movlw FSS ; initialize EEADR:EEADRH and FSR
+ movwf cnt
+ movlb .3
+ movlw combuff + .2
+ movwf FSR
+ movf INDF,w
+ movwf EEADRL
+ incf FSR,f
+ movf INDF,w
+ movwf EEADRH
+ bcf EECON1,CFGS
+ bsf EECON1,EEPGD
+ bsf EECON1,WREN
+
+write_flash_segment_loop
+ incf FSR,f ; load code word into EEDAT:EEDATH
+ movf INDF,w
+ movwf EEDATL
+ incf FSR,f
+ movf INDF,w
+ movwf EEDATH
+
+ bsf EECON1,FREE ; erase row before writing
+ movlw H'55'
+ movwf EECON2
+ movlw H'AA'
+ movwf EECON2
+ bsf EECON1,WR
+ nop
+ nop
+ bcf EECON1,FREE ; now start the acutal write sequence
+ movf EEADRL,w
+ andlw FLASH_BOUNDARY
+ xorlw FLASH_BOUNDARY
+ btfss STATUS,Z
+ bsf EECON1,LWLO
+ btfsc STATUS,Z
+ bcf EECON1,LWLO
+ movlw H'55'
+ movwf EECON2
+ movlw H'AA'
+ movwf EECON2
+ bsf EECON1,WR
+ nop
+ nop
+ incfsz EEADRL,f ; increment flash address
+ goto write_flash_segment_next
+ incf EEADRH,f
+write_flash_segment_next
+ decfsz cnt,f
+ goto write_flash_segment_loop
+
+ bcf EECON1,WREN
+ movlw E_OK ; check if a write error occured
+ btfsc EECON1,WRERR
+ movlw E_FLASH_WERR
+ movlb .0
+ movwf combuff + .2 ; = E_OK or write error
+ movlw .1 ; bytes to send
+ call send_answer
+ goto wait_new_cmd
+
+ ;; read config --------
+cmd_r_config
+ movf combuff + .2,w
+ sublw CFG - .1
+ btfss STATUS,C
+ goto address_invalid
+ movf combuff + .2,w
+ movlb .3
+ addlw CONFIG_OFFSET
+ movwf EEADRL
+ clrf EEADRH
+ bsf EECON1,CFGS
+ bsf EECON1,RD
+ nop
+ nop
+ movf EEDATL,w
+ movlb .0
+ movwf combuff + .3
+ movlb .3
+ movf EEDATH,w
+ movlb .0
+ movwf combuff + .4
+ movlw E_OK
+ movwf combuff + .2 ; = E_OK
+ movlw .3 ; bytes to send
+ call send_answer
+ goto wait_new_cmd
diff --git a/software/pic.bootloader/cmds-16f887.inc b/software/pic.bootloader/cmds-16f887.inc
index 144150e..25889c3 100644
--- a/software/pic.bootloader/cmds-16f887.inc
+++ b/software/pic.bootloader/cmds-16f887.inc
@@ -2,7 +2,7 @@
;; spreadspace pic utils
;;
;;
- ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
;;
;; This file is part of spreadspace pic utils.
;;
@@ -99,19 +99,16 @@ write_flash_segment_loop
nop
bcf EECON1,WREN
bcf STATUS,RP0
- incfsz EEADR,f ; increment flash address
- goto write_flash_segment_next
- incf EEADRH,f
-write_flash_segment_next
+ incf EEADR,f ; increment flash address (no need to increment EEADRH -> flash bondaries!)
decfsz cnt,f
goto write_flash_segment_loop
bsf STATUS,RP0
- clrw ; check if a write error occured
+ movlw E_OK ; check if a write error occured
btfsc EECON1,WRERR
movlw E_FLASH_WERR
bcf STATUS,RP1
bcf STATUS,RP0
- movwf combuff + .2 ; = E_OK
+ movwf combuff + .2 ; = E_OK or Write Error
movlw .1 ; bytes to send
call send_answer
goto wait_new_cmd
diff --git a/software/pic.bootloader/com-16f1847-spi.inc b/software/pic.bootloader/com-16f1847-spi.inc
new file mode 100644
index 0000000..c8c3f1d
--- /dev/null
+++ b/software/pic.bootloader/com-16f1847-spi.inc
@@ -0,0 +1,78 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+ ;; --- transmit byte and add it to csum
+com_tx_byte
+ movlb .4
+ movwf SSP1BUF
+ movlb .0
+ bcf INTPIN
+ xorwf csum,f
+com_tx_byte_wait1
+ btfsc PORTB,5
+ goto com_tx_byte_wait1
+com_tx_byte_wait2
+ btfss PORTB,5
+ goto com_tx_byte_wait2
+ movlb .4
+ movf SSP1BUF,w
+ movlb .0
+ bsf INTPIN
+ return
+
+ ;; ---- wait for byte to be received
+com_rx_byte
+ movlb .4
+ btfsc SSP1STAT,BF
+ goto com_rx_got_byte
+ btfss SSP1CON1,SSPOV
+ goto com_rx_byte
+ movf SSP1BUF,w
+ bcf SSP1CON1,SSPOV
+ goto com_rx_byte
+
+com_rx_got_byte
+ movf SSP1BUF,w
+ movlb .0
+ return
+
+ ;; ----- initialize com (this is called by bootmacro, it's not a subroutine - no return at the end)
+com_init
+ movlb .3
+ bcf ANSELB,ANSB1 ; SDI as digital input
+ bcf ANSELB,ANSB4 ; SCK as digital input
+
+ movlb .1
+ movlw b'01110000' ; set internal OSC to 8MHz
+ movwf OSCCON
+ bcf TRISB,2 ; RB2(SDO) = out
+ bcf INTPIN ; interrupt line to master
+
+ movlb .4
+ movlw b'01000000' ; SMP=0,CKE=1
+ movwf SSP1STAT
+ movlw b'00100100' ; SSPEN=1,CKP=0,SSPM=0100(SPI Slave with SS)
+ movwf SSP1CON1
+ bcf SSP1CON3,BOEN
+
+ movlb .0
+ bsf INTPIN
diff --git a/software/pic.bootloader/com-16f1847-uart.inc b/software/pic.bootloader/com-16f1847-uart.inc
new file mode 100644
index 0000000..961827d
--- /dev/null
+++ b/software/pic.bootloader/com-16f1847-uart.inc
@@ -0,0 +1,76 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+ ;; --- transmit byte and add it to csum
+com_tx_byte
+ btfss PIR1,TXIF
+ goto com_tx_byte
+ movlb .3
+ movwf TXREG
+ xorwf csum,f
+ movlb .0
+ return
+
+ ;; ---- wait for byte to be received
+com_rx_byte
+ movlb .3
+ btfsc RCSTA,OERR
+ goto uart_rx_oe
+ movlb .0
+ btfss PIR1,RCIF
+ goto com_rx_byte
+ movlb .3
+ btfsc RCSTA,FERR
+ goto uart_rx_fe
+ movf RCREG,w
+ movlb .0
+ return
+
+uart_rx_oe ; recover from overflow
+ bcf RCSTA,CREN
+ bsf RCSTA,CREN
+ goto com_rx_byte
+
+uart_rx_fe ; recover from framing error
+ movf RCREG,w
+ goto com_rx_byte
+
+ ;; ----- initialize com (this is called by bootmacro, it's not a subroutine - no return at the end)
+com_init
+ movlb .1
+ movlw b'01110000' ; 8 MHz
+ movwf OSCCON
+
+ movlb .3
+ bcf ANSELB,ANSB1
+ movlw b'01001000' ; TX non-inverted, 16bit Baudrate, no auto baud detect
+ movwf BAUDCON
+ movlw b'00100100' ; Baudrate = High Speed, async mode, transmit enabled, 8bit
+ movwf TXSTA
+ movlw .34 ; Baudrate = 57600 (@ 8MHz) -> -0,79 % Error
+ ;; movlw .51 ; Baudrate = 38400 (@ 8MHz) -> -0,002 % Error
+ ;; movlw .103 ; Baudrate = 19200 (@ 8MHz) -> 0,16 % Error
+ movwf SPBRGL
+ clrf SPBRGH
+ movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection
+ movwf RCSTA
+ movlb .0
diff --git a/software/pic.bootloader/com-16f887-spi.inc b/software/pic.bootloader/com-16f887-spi.inc
new file mode 100644
index 0000000..4fb41c8
--- /dev/null
+++ b/software/pic.bootloader/com-16f887-spi.inc
@@ -0,0 +1,73 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+ ;; --- transmit byte and add it to csum
+com_tx_byte
+ movwf SSPBUF
+ bcf INTPIN
+ xorwf csum,f
+com_tx_byte_wait1
+ btfsc PORTA,5
+ goto com_tx_byte_wait1
+com_tx_byte_wait2
+ btfss PORTA,5
+ goto com_tx_byte_wait2
+ movf SSPBUF,w
+ bsf INTPIN
+ return
+
+ ;; ---- wait for byte to be received
+com_rx_byte
+ bsf STATUS,RP0
+ btfsc SSPSTAT,BF
+ goto com_rx_got_byte
+ bcf STATUS,RP0
+ btfss SSPCON,SSPOV
+ goto com_rx_byte
+ movf SSPBUF,w
+ bcf SSPCON,SSPOV
+ goto com_rx_byte
+
+com_rx_got_byte
+ bcf STATUS,RP0
+ movf SSPBUF,w
+ return
+
+ ;; ----- initialize com (this is called by bootmacro, it's not a subroutine - no return at the end)
+com_init
+ ;; bank 3 - we are already there, see bootmacro
+ ;; bank 1
+ bcf STATUS,RP1
+ movlw b'01110000' ; set internal OSC to 8MHz
+ movwf OSCCON
+ movlw b'01000000' ; SMP=0,CKE=1
+ movwf SSPSTAT
+ bcf TRISC,5 ; RC5(SDO) = out
+ bcf INTPIN ; interrupt line to master
+
+ ;; bank 0
+ bcf STATUS,RP0
+ btfsc BOOTPIN
+ goto USERVECT
+ movlw b'00100100' ; SSPEN=1,CKP=0,SSPM=0100(SPI Slave with SS)
+ movwf SSPCON
+ bsf INTPIN
diff --git a/software/pic.bootloader/com-16f887-uart.inc b/software/pic.bootloader/com-16f887-uart.inc
index b2b6812..d4603a9 100644
--- a/software/pic.bootloader/com-16f887-uart.inc
+++ b/software/pic.bootloader/com-16f887-uart.inc
@@ -2,7 +2,7 @@
;; spreadspace pic utils
;;
;;
- ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
;;
;; This file is part of spreadspace pic utils.
;;
@@ -48,13 +48,13 @@ uart_rx_fe ; recover from framing error
movf RCREG,w
goto com_rx_byte
- ;; ----- initialize com (not a subroutine, com_init is called by generic_init
+ ;; ----- initialize com (this is called by bootmacro, it's not a subroutine - no return at the end)
com_init
;; bank 3
bsf STATUS,RP0
bsf STATUS,RP1
- ;;movlw b'00001000' ; TX non-inverted, 16bit Baudrate, no auto baud detect
- movlw b'00011000' ; TX inverted, 16bit Baudrate, no auto baud detect
+ movlw b'00001000' ; TX non-inverted, 16bit Baudrate, no auto baud detect
+ ;; movlw b'00011000' ; TX inverted, 16bit Baudrate, no auto baud detect
movwf BAUDCTL
;; bank 1
diff --git a/software/pic.bootloader/downloader.py b/software/pic.bootloader/downloader.py
index 072ca46..12e9644 100755
--- a/software/pic.bootloader/downloader.py
+++ b/software/pic.bootloader/downloader.py
@@ -3,7 +3,7 @@
# spreadspace pic utils
#
#
-# Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+# Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
#
# This file is part of spreadspace pic utils.
#
@@ -30,6 +30,7 @@ VERSION_MIN = 1
def load_hex(file):
from ihexpic import IHexPic
+ import os
fin = file
if fin == '-':
@@ -85,10 +86,8 @@ def create_flash_segments(hexdata, fs, fss):
### Interface to Bootloader
def open_serial(device, baud):
- import os
- import tty
- import termios
import serial
+ import time
print >> sys.stderr, "opening %s (%s Baud)" % (device, baud)
@@ -96,6 +95,12 @@ def open_serial(device, baud):
dev = serial.Serial(port=device, baudrate=baud, timeout=3)
dev.flushInput()
dev.flushOutput()
+ dev.setDTR(True) # send a reset pulse
+ dev.setBreak(True) # boot into bootloader
+ time.sleep(0.1)
+ dev.setDTR(False)
+ time.sleep(0.01)
+ dev.setBreak(False)
return dev
except (ValueError, serial.SerialException), msg:
@@ -109,7 +114,6 @@ def calc_csum(str):
return cs
def exec_command(dev, cmd, param, answer):
- import struct
return_codes = { 0: "OK", 1: "invalid command", 2: "bad checksum",
3: "not implemented", 4: "flash write error",
@@ -166,9 +170,9 @@ def exec_command(dev, cmd, param, answer):
### low level commands
def cmd_identify(dev, name):
- data = exec_command(dev, 1, '', '<BB3sHHBHBH')
+ data = exec_command(dev, 1, '', '<BB3sHHBHBBH')
id = { 'ver_min': data[0], 'ver_maj': data[1], 'name': data[2], 'devid': data[3],
- 'fs': data[4], 'fss': data[5], 'es': data[6], 'mess': data[7], 'supported': data[8] }
+ 'fs': data[4], 'fss': data[5], 'es': data[6], 'mess': data[7], 'cfg': data[8], 'supported': data[9] }
if id['ver_maj'] != VERSION_MAJ:
print >> sys.stderr, "incompatible protocol version, expected: %d, got: %d" % (VERSION_MAJ, id['ver_maj'])
@@ -179,8 +183,8 @@ def cmd_identify(dev, name):
print >> sys.stderr, " right device?"
sys.exit(4)
- print >> sys.stderr, "connected with Bootloader '%s' Version %d.%d,\n (ID=%04X, %d words Flash, FSS=%d, %d bytes EEPROM, MESS=%d)\n" % \
- (id['name'], id['ver_maj'], id['ver_min'], id['devid'], id['fs'], id['fss'], id['es'], id['mess'])
+ print >> sys.stderr, "connected with Bootloader '%s' Version %d.%d,\n (ID=%04X, %d words Flash, FSS=%d, %d bytes EEPROM, MESS=%d, %d words Config)\n" % \
+ (id['name'], id['ver_maj'], id['ver_min'], id['devid'], id['fs'], id['fss'], id['es'], id['mess'], id['cfg'])
return id
def cmd_boot(dev):
@@ -251,6 +255,10 @@ def boot(dev, id, args):
print >> sys.stderr, "booting to user code"
cmd_boot(dev)
+def reset(dev, id, args):
+ print >> sys.stderr, "reseting MCU"
+ cmd_reset(dev,id)
+
def write_flash(dev, id, args):
hexdata = load_hex(args[0])
flashsegments = list(create_flash_segments(hexdata, id['fs'], id['fss']))
@@ -304,11 +312,19 @@ def verify_flash(dev, id, args):
else:
print >> sys.stderr, " *********** verify ok! **********\n"
+def read_config(dev, id, args):
+ nr = int(args[0])
+ print >> sys.stderr, "reading configuration word nr %d" % nr
+ print "0x%04X" % cmd_read_config(dev, id, nr)
+
+
commands = {
'boot': boot,
+ 'reset': reset,
'write': write_flash,
'read': read_flash,
- 'verify': verify_flash
+ 'verify': verify_flash,
+ 'read-config': read_config
}
### Main
@@ -316,21 +332,22 @@ commands = {
if __name__ == '__main__':
import getopt
import sys
- import os
import struct
usage = '''spreadspace simple pic downloader.
Usage:
python downloader.py [options] command [ command2 [ .. ] ]
- You can supply as many commands as you wish. Any command except boot
+ You can supply as many commands as you wish. Any command except 'boot'
may be supplied more than once. The commands will be executed in the
- order of appearence in the command line.
+ order of appearence at command line.
Mind that all commands after 'boot' will be ignored because the bootloader
- is no longer reachable. If verify detects an error the downloader will
- exit with '-1' immediatly, the remaining commands will get ignored.
+ is no longer reachable. The same may be true after a reset in which case,
+ depending on the state of BOOTPIN, the user code may get started.
+ If verify detects an error the downloader will exit with '-1' immediatly and
+ the remaining commands will get ignored.
If you don't specify any command the downloader will connect to the
- bootloader print some info and exit.
+ bootloader print some information and exit.
Options:
-h, --help this help message.
@@ -343,6 +360,8 @@ Commands:
--write=<hexfile> write <hexfile> to flash (use '-' for stdin).
--verify=<hexfile> compare flash with <hexfile> (use '-' for stdin).
--read=<hexfile> read flash and store in <hexfile> (use '-' for stdout).
+ --read-config=<nr> read the configuration word <nr> and print it on stdout.
+ --reset reset the MCU (this may start the user code area: BOOTPIN)
--boot boot to user code
'''
@@ -353,7 +372,7 @@ Commands:
try:
opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "version", "device=", "baud=", "name=", \
- "write=", "read=", "verify=", "boot" ])
+ "write=", "read=", "verify=", "read-config=", "reset", "boot" ])
for o, a in opts:
if o in ("-h", "--help"):
print >> sys.stderr, usage
diff --git a/software/pic.bootloader/generic-defines.inc b/software/pic.bootloader/generic-defines.inc
index 54ca01b..a298229 100644
--- a/software/pic.bootloader/generic-defines.inc
+++ b/software/pic.bootloader/generic-defines.inc
@@ -2,7 +2,7 @@
;; spreadspace pic utils
;;
;;
- ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
;;
;; This file is part of spreadspace pic utils.
;;
diff --git a/software/pic.bootloader/generic-init.inc b/software/pic.bootloader/generic-init.inc
index 4c51fa9..bc790ac 100644
--- a/software/pic.bootloader/generic-init.inc
+++ b/software/pic.bootloader/generic-init.inc
@@ -2,7 +2,7 @@
;; spreadspace pic utils
;;
;;
- ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
;;
;; This file is part of spreadspace pic utils.
;;
@@ -21,9 +21,7 @@
;;
org .0
- btfsc BOOTPIN
- goto USERVECT
- goto com_init
+ bootmacro
;; -------------------------------------
;; goto user ISR
diff --git a/software/pic.bootloader/generic-mainloop.inc b/software/pic.bootloader/generic-mainloop.inc
index 1e93648..1cecf3a 100644
--- a/software/pic.bootloader/generic-mainloop.inc
+++ b/software/pic.bootloader/generic-mainloop.inc
@@ -2,7 +2,7 @@
;; spreadspace pic utils
;;
;;
- ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;; Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
;;
;; This file is part of spreadspace pic utils.
;;
@@ -115,7 +115,7 @@ cmd_identify
movf combuff,w
call com_tx_byte
- movlw .19
+ movlw .20
call com_tx_byte
movlw E_OK
@@ -152,6 +152,9 @@ cmd_identify
movlw MESS
call com_tx_byte
+ movlw CFG
+ call com_tx_byte
+
movlw SUPPORTED_L
call com_tx_byte
movlw SUPPORTED_H
diff --git a/software/pic.bootloader/ihexpic.py b/software/pic.bootloader/ihexpic.py
index e30204c..a631c04 100644
--- a/software/pic.bootloader/ihexpic.py
+++ b/software/pic.bootloader/ihexpic.py
@@ -1,7 +1,7 @@
# spreadspace pic utils
#
#
-# Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+# Copyright (C) 2011-2013 Christian Pointner <equinox@spreadspace.org>
#
# This file is part of spreadspace pic utils.
#
diff --git a/software/pic.bootloader/proto.txt b/software/pic.bootloader/proto.txt
index 0e35e1e..61975cf 100644
--- a/software/pic.bootloader/proto.txt
+++ b/software/pic.bootloader/proto.txt
@@ -43,7 +43,7 @@ identify:
1 | len=3 | <csum>
answer:
- 1 | len=19 | <ret> | version | name | devid | fs | fss | es | mess | supported | <csum>
+ 1 | len=19 | <ret> | version | name | devid | fs | fss | es | mess | cfg | supported | <csum>
version:
2bytes, protocol version
@@ -79,6 +79,9 @@ identify:
read at once. Unlike <fss> value it is ok to write or read less than <mess>
bytes.
+ cfg:
+ 1byte, number of configuration words.
+
supported:
2bytes, a bitmap showing supported commands
The commands 'identify' and 'boot' are always supported by the bootloader,