summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-11 23:00:24 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2013-07-11 23:00:24 (GMT)
commitf82680da770a35b111f4ef71f4a21caa68e6fd88 (patch)
tree0526d00264016e7336c4ffad46ccd33e77b5eb01
parent086aae3198e74218f84d9d88facb2a1bba1e7ee4 (diff)
added support for config read for 16f1847
git-svn-id: https://svn.spreadspace.org/pic/trunk@83 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rw-r--r--bootloader/bootloader-947.asm3
-rw-r--r--bootloader/cmds-16f1847.inc30
-rwxr-xr-xbootloader/downloader.py14
3 files changed, 42 insertions, 5 deletions
diff --git a/bootloader/bootloader-947.asm b/bootloader/bootloader-947.asm
index 7575b13..1f9962c 100644
--- a/bootloader/bootloader-947.asm
+++ b/bootloader/bootloader-947.asm
@@ -33,6 +33,7 @@
USERVECT EQU H'200'
ISRVECT EQU USERVECT + H'4'
FLASH_BOUNDARY EQU b'00011111' ; flash write boundary is at 32 bytes boundaries
+CONFIG_OFFSET EQU H'07'
VERSION_MAJ EQU .0
VERSION_MIN EQU .1
@@ -56,7 +57,7 @@ SUPPORTED_L EQU b'00000111' ; only reset and read/write flash is suppo
#define HOOK_CMD_W_FLASH cmd_w_flash
#define HOOK_CMD_R_EEPROM cmd_not_impl
#define HOOK_CMD_W_EEPROM cmd_not_impl
-#define HOOK_CMD_R_CONFIG cmd_not_impl
+#define HOOK_CMD_R_CONFIG cmd_r_config
#define HOOK_CMD_W_CONFIG cmd_not_impl
;; Variables
diff --git a/bootloader/cmds-16f1847.inc b/bootloader/cmds-16f1847.inc
index 1f15c20..67775c5 100644
--- a/bootloader/cmds-16f1847.inc
+++ b/bootloader/cmds-16f1847.inc
@@ -129,7 +129,7 @@ write_flash_segment_next
goto write_flash_segment_loop
bcf EECON1,WREN
- clrw ; check if a write error occured
+ movlw E_OK ; check if a write error occured
btfsc EECON1,WRERR
movlw E_FLASH_WERR
movlb .0
@@ -137,3 +137,31 @@ write_flash_segment_next
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/bootloader/downloader.py b/bootloader/downloader.py
index e214171..3d93000 100755
--- a/bootloader/downloader.py
+++ b/bootloader/downloader.py
@@ -176,7 +176,7 @@ 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, %d words config)\n" % \
+ 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
@@ -305,12 +305,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
@@ -346,6 +353,7 @@ 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
'''
@@ -357,7 +365,7 @@ Commands:
try:
opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "version", "device=", "baud=", "name=", \
- "write=", "read=", "verify=", "reset", "boot" ])
+ "write=", "read=", "verify=", "read-config=", "reset", "boot" ])
for o, a in opts:
if o in ("-h", "--help"):
print >> sys.stderr, usage