Skip to content

Commit

Permalink
Fixed a bug when flashing hexfiles with USERID words.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rex-- committed Mar 11, 2022
1 parent 164d0b9 commit e252a8d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 20 deletions.
55 changes: 54 additions & 1 deletion software/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
TODO
# picchick
A utility to aid in programming PIC microcontrollers


## Overview

`piccchick` is a commandline utility written in python that attempts to implement Microchip's ICSP Low-Voltage with just a simple AVR device.

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:

Development (nano) > Compiling (xc8-cc) > Flashing (picchick)


## Installation

### Requirements
- **`xc8` compiler installed to one of**:
> (linux) /opt/microchip/xc8/
- **python >= 3.10**
- pyserial

- **Arduino flashed with programmer firmware**

## Usage

```
$> picchick -h
usage: picchick [options] [hexfile]
A utility for programming PIC microcontrollers
positional arguments:
hexfile path to the hexfile
options:
-h, --help show this help message and exit
-f, --flash flash hexfile onto the device
--read addr read specified address or chunk of memory
--write addr word write word to specified address
--erase [addr] erase device or specified address
-d chipID, --device chipID
device to be programmed
-p port, --port port programmer serial port
--baud baud serial connection baudrate
--map display the hexfile
--list-ports list available serial ports
flag arguments:
[addr]: device memory address in hexadecimal
'all' all device memory areas
'flash' user flash area
```
32 changes: 16 additions & 16 deletions software/picchick/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
parser.add_argument('--list-ports',
action='store_true',
help='list available serial ports')
parser.add_argument('--list-devices',
action='store_true',
help='list available device configurations')
# parser.add_argument('--list-devices',
# action='store_true',
# help='list available device configurations')

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

# If we don't need to do anything, print help because
# the user needs it
if not hexfile_reqd and not programmer_reqd:
if not hexfile_reqd and not programmer_reqd and not nothing_reqd:
parser.print_help()
sys.exit(0)

Expand All @@ -98,6 +100,7 @@ def parseArgv():
sys.exit(1)
elif args.device is None:
print("Missing argument: -d, --device chipID")
sys.exit(1)
elif not os.path.isfile(args.hexfile):
print(f"Could not find hexfile: { args.hexfile}")
sys.exit(1)
Expand Down Expand Up @@ -150,21 +153,18 @@ def parseArgv():
dev.erase(int(args.erase, base=16))

if args.flash:


for start_address, row in hex_decoder.memory.items():
if start_address < hexfile.USER_ID_START:
dev.row(start_address, row)
for start_address, word in hex_decoder.memory.items():
if hexfile.USER_ID_START <= start_address < hexfile.CONFIG_WORD_START:
dev.word(start_address, word[0])
for start_address, word in hex_decoder.memory.items():
if hexfile.CONFIG_WORD_START <= start_address:
dev.word(start_address, word[0])
for address in hex_decoder.memory:
if address <= hex_decoder.device.flash.end:
dev.row(address, hex_decoder.memory[address])
else:
dev.word(address, hex_decoder.memory[address][0])
elif args.write:
dev.word(int(args.write[0], base=16), int(args.write[1], base=16))

if args.read:
dev.read(int(args.read, base=16))
dev.stop()

dev.stop()

if programmer_reqd:
dev.disconnect()
9 changes: 6 additions & 3 deletions software/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[metadata]
name = picchick
version = 0.1.0
version = 0.1.1
author = Rex McKinnon
author_email = 0xff@rexploits.com
description = A utility for programming PIC microntronllers
url = https://github.com/rex--/picchick/tree/master/software
description = A utility for programming PIC microntronllers.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/rex--/picchick
license = University of Illinois/NCSA Open Source License
classifiers =
Programming Language :: Python :: 3.10
License :: OSI Approved :: University of Illinois/NCSA Open Source License
Expand Down

0 comments on commit e252a8d

Please sign in to comment.