Skip to content

Commit

Permalink
Added --device flag to specify device to be programmed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rex-- committed Mar 6, 2022
1 parent d1c7909 commit 41646e4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 11 deletions.
12 changes: 7 additions & 5 deletions software/picchick/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
parser.add_argument('--write',
nargs=2,
metavar=('addr', 'word'),
help='write word to specified address or chunk of memory')
help='write word to specified address')
parser.add_argument('--erase',
nargs='?',
const='all',
metavar='addr',
help='erase device or specified address')

# parser.add_argument('-d', '--device',
# metavar='dev',
# help='device to be programmed')
parser.add_argument('-d', '--device',
metavar='chipID',
help='device to be programmed')
parser.add_argument('-p', '--port',
metavar='port',
help='programmer serial port')
Expand Down Expand Up @@ -90,12 +90,14 @@ def parseArgv():
if args.hexfile is None:
print(f"Missing argument: hexfile")
sys.exit(1)
elif args.device is None:
print("Missing argument: -d, --device chipID")
elif not os.path.isfile(args.hexfile):
print(f"Could not find hexfile: { args.hexfile}")
sys.exit(1)
else:
print(f"Using hexfile: { args.hexfile }")
hex_decoder = hexfile.HexfileDecoder(args.hexfile)
hex_decoder = hexfile.HexfileDecoder(args.hexfile, args.device)

# We now have all the hexfile reqs, so take care of the actions
# that only require the hexfile
Expand Down
67 changes: 67 additions & 0 deletions software/picchick/devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import configparser
import pathlib


class MemoryRange:

size = None
start = None
end = None

def configure(self, size=None, addr_range=None):

if size and not addr_range:
self.size = int(size, base=16)
self.start = 0
self.end = self.size - 1

if addr_range and not size:
self.start = int(addr_range.split('-')[0], base=16)
self.end = int(addr_range.split('-')[1], base=16)
self.size = self.end - self.start + 1


# This class holds the device data needed for flashing etc.
class Device:

flash = MemoryRange()
config = MemoryRange()

def __init__(self, chip_id):

self.chip_id = chip_id.upper()

def readDeviceFile(self, ccpath):
self.device_file_path = ccpath / 'pic/dat/ini' / (self.chip_id.lower() + '.ini')
self.device_file = configparser.ConfigParser(strict=False)
self.device_file.read(self.device_file_path)
self.flash.configure(size=self.device_file.get(self.chip_id, 'ROMSIZE'))
self.config.configure(addr_range=self.device_file.get(self.chip_id, 'CONFIG'))


XC8_COMMON_PATHS = [
'/opt/microchip/xc8'
]

# This class handles searching the local filesystem for the xc8 compiler so
# we can use its device files
class XC8Manager:

# xc8_paths = []

def findXC8Installs():

found_installs = []

for common_path in XC8_COMMON_PATHS:
path = pathlib.Path(common_path)

if path.is_dir():
found_installs += [p for p in path.iterdir() if p.is_dir()]

# self.xc8_paths += found_installs
return found_installs




18 changes: 12 additions & 6 deletions software/picchick/hexfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@

import copy

PFM_START = 0x0000
USER_ID_START = 0x8000
CONFIG_WORD_START = 0x8007
from . import devices

# PFM_START = 0x0000
# USER_ID_START = 0x8000
# CONFIG_WORD_START = 0x8007


class HexfileDecoder:

def __init__(self, path):
def __init__(self, path, device):
self.path = path

self.device = devices.Device(device)
self.device.readDeviceFile(devices.XC8Manager.findXC8Installs()[0])

self.ascii_records = self._readHexfile(path)
self.records = self._decodeAsciiRecords(self.ascii_records)
self.word_list = self._decodeWordsFromRecords(self.records)

self.userflash_words = [addr for addr in self.word_list.keys() if addr < USER_ID_START]
self.config_words = [addr for addr in self.word_list.keys() if addr > USER_ID_START]
self.userflash_words = [addr for addr in self.word_list.keys() if addr <= self.device.flash.end]
self.config_words = [addr for addr in self.word_list.keys() if addr > self.device.flash.end]

self.memory = self._separateRows(self.word_list)

Expand Down

0 comments on commit 41646e4

Please sign in to comment.