Skip to content

Commit e252a8d

Browse files
committed
Fixed a bug when flashing hexfiles with USERID words.
1 parent 164d0b9 commit e252a8d

3 files changed

Lines changed: 76 additions & 20 deletions

File tree

software/README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
TODO
1+
# picchick
2+
A utility to aid in programming PIC microcontrollers
3+
4+
5+
## Overview
6+
7+
`piccchick` is a commandline utility written in python that attempts to implement Microchip's ICSP Low-Voltage with just a simple AVR device.
8+
9+
The function is the same as `avrdude`, i.e. to provide a way to flash a compiled .hex file onto a microcontroller. The typical development stack involving picchick looks like:
10+
11+
Development (nano) > Compiling (xc8-cc) > Flashing (picchick)
12+
13+
14+
## Installation
15+
16+
### Requirements
17+
- **`xc8` compiler installed to one of**:
18+
> (linux) /opt/microchip/xc8/
19+
20+
- **python >= 3.10**
21+
- pyserial
22+
23+
- **Arduino flashed with programmer firmware**
24+
25+
## Usage
26+
27+
```
28+
$> picchick -h
29+
30+
usage: picchick [options] [hexfile]
31+
32+
A utility for programming PIC microcontrollers
33+
34+
positional arguments:
35+
hexfile path to the hexfile
36+
37+
options:
38+
-h, --help show this help message and exit
39+
-f, --flash flash hexfile onto the device
40+
--read addr read specified address or chunk of memory
41+
--write addr word write word to specified address
42+
--erase [addr] erase device or specified address
43+
-d chipID, --device chipID
44+
device to be programmed
45+
-p port, --port port programmer serial port
46+
--baud baud serial connection baudrate
47+
--map display the hexfile
48+
--list-ports list available serial ports
49+
50+
flag arguments:
51+
[addr]: device memory address in hexadecimal
52+
'all' all device memory areas
53+
'flash' user flash area
54+
```

software/picchick/cli.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
parser.add_argument('--list-ports',
6868
action='store_true',
6969
help='list available serial ports')
70-
parser.add_argument('--list-devices',
71-
action='store_true',
72-
help='list available device configurations')
70+
# parser.add_argument('--list-devices',
71+
# action='store_true',
72+
# help='list available device configurations')
7373

7474
def parseArgv():
7575
args = parser.parse_args()
@@ -82,10 +82,12 @@ def parseArgv():
8282
programmer_reqd = both_reqd or (args.read or args.erase or args.write)
8383
# The map flag only requires the hexfile to be present
8484
hexfile_reqd = both_reqd or (args.map)
85+
# list_ports flag doesn't require anyhting
86+
nothing_reqd = (args.list_ports)
8587

8688
# If we don't need to do anything, print help because
8789
# the user needs it
88-
if not hexfile_reqd and not programmer_reqd:
90+
if not hexfile_reqd and not programmer_reqd and not nothing_reqd:
8991
parser.print_help()
9092
sys.exit(0)
9193

@@ -98,6 +100,7 @@ def parseArgv():
98100
sys.exit(1)
99101
elif args.device is None:
100102
print("Missing argument: -d, --device chipID")
103+
sys.exit(1)
101104
elif not os.path.isfile(args.hexfile):
102105
print(f"Could not find hexfile: { args.hexfile}")
103106
sys.exit(1)
@@ -150,21 +153,18 @@ def parseArgv():
150153
dev.erase(int(args.erase, base=16))
151154

152155
if args.flash:
153-
154-
155-
for start_address, row in hex_decoder.memory.items():
156-
if start_address < hexfile.USER_ID_START:
157-
dev.row(start_address, row)
158-
for start_address, word in hex_decoder.memory.items():
159-
if hexfile.USER_ID_START <= start_address < hexfile.CONFIG_WORD_START:
160-
dev.word(start_address, word[0])
161-
for start_address, word in hex_decoder.memory.items():
162-
if hexfile.CONFIG_WORD_START <= start_address:
163-
dev.word(start_address, word[0])
156+
for address in hex_decoder.memory:
157+
if address <= hex_decoder.device.flash.end:
158+
dev.row(address, hex_decoder.memory[address])
159+
else:
160+
dev.word(address, hex_decoder.memory[address][0])
164161
elif args.write:
165162
dev.word(int(args.write[0], base=16), int(args.write[1], base=16))
166163

167164
if args.read:
168165
dev.read(int(args.read, base=16))
169-
dev.stop()
166+
167+
dev.stop()
168+
169+
if programmer_reqd:
170170
dev.disconnect()

software/setup.cfg

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
[metadata]
22
name = picchick
3-
version = 0.1.0
3+
version = 0.1.1
44
author = Rex McKinnon
55
author_email = 0xff@rexploits.com
6-
description = A utility for programming PIC microntronllers
7-
url = https://github.com/rex--/picchick/tree/master/software
6+
description = A utility for programming PIC microntronllers.
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
url = https://github.com/rex--/picchick
10+
license = University of Illinois/NCSA Open Source License
811
classifiers =
912
Programming Language :: Python :: 3.10
1013
License :: OSI Approved :: University of Illinois/NCSA Open Source License

0 commit comments

Comments
 (0)