Skip to content

Commit 298ce30

Browse files
committedMar 8, 2025
updating workflow
1 parent a2e145e commit 298ce30

File tree

2 files changed

+49
-38
lines changed

2 files changed

+49
-38
lines changed
 

‎.github/workflows/pyinstaller-package.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,32 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
os: [ubuntu-24.04, ubuntu-22.04]
16+
os: [ubuntu-22.04]#, ubuntu-24.04]
1717

1818
steps:
19-
- uses: actions/checkout@v2
20-
- name: Setup Virtual Environment
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.10'
23+
cache: 'pip'
24+
25+
- name: Check Python Version
2126
run: |
22-
python -m venv venv
23-
source venv/bin/activate
24-
- name: Install dependencies
27+
python --version
28+
which python
29+
30+
- name: Install
2531
run: |
2632
python -m pip install --upgrade pip
2733
python -m pip install pyserial
28-
- name: Install
29-
run: |
34+
python -m pip install pyinstaller
3035
python -m pip install .
36+
37+
- name: Verify Installations
38+
run: |
39+
python -m pip show isp_programmer
40+
python -m pip show pyserial
41+
3142
- name: Make executable
3243
uses: sayyid5416/pyinstaller@v1
3344
with:

‎src/isp_programmer/ISPConnection.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
_log = logging.getLogger("isp_programmer")
1818

1919
kTimeout = 1
20-
21-
2220
BAUDRATES = (9600, 19200, 38400, 57600, 115200, 230400, 460800)
23-
24-
2521
NXPReturnCodes = {
2622
"CMD_SUCCESS": 0x0,
2723
"INVALID_COMMAND": 0x1,
@@ -83,7 +79,8 @@ def _raise_return_code_error(code: int, call_name: str) -> None:
8379

8480
@dataclass
8581
class Settings:
86-
safe_write: bool = True # Check to see if sector is already equal to RAM, if so skip
82+
# Check to see if sector is already equal to RAM, if so skip
83+
safe_write: bool = True
8784
flash_write_sleep: float = 0.01
8885
ram_write_sleep: float = 0.01
8986
return_code_sleep: float = 0.05
@@ -101,7 +98,7 @@ class ISPConnection:
10198

10299
kNewLine = "\r\n"
103100
StatusRespLength = len(kNewLine) + 1
104-
kWordSize = 4 # 32 bit device
101+
kWordSize = 4
105102
# Parity = None
106103
# DataBits = 8
107104
# StopBits = 1
@@ -212,7 +209,8 @@ def _get_return_code(self, command_string: str) -> int:
212209
if resp.strip() == command_string.strip():
213210
_log.debug("Command was echoed, Discarding line: %s", resp)
214211
resp = self._read_line()
215-
# if self.echo_on: # discard echo
212+
# discard echo
213+
# if self.echo_on:
216214
# _log.debug("ECHO ON, Discarding line: %s", resp)
217215
# resp = self._read_line()
218216
except TimeoutError:
@@ -262,7 +260,7 @@ def SetEcho(self, on: bool = True):
262260
"""
263261
ISP echos host when enabled
264262
"""
265-
command = f"A {on : d}"
263+
command = f"A {on:d}"
266264
response_code = self._write_command(command)
267265
_raise_return_code_error(response_code, "Set Echo")
268266
self.echo_on = on
@@ -281,14 +279,18 @@ def WriteToRam(self, start: int, data: bytes):
281279
# when transfer is complete the handler sends OK<CR><LF>
282280
response_code = self._write_command(f"W {start} {len(data)}")
283281
_raise_return_code_error(response_code, function_name)
284-
self._write(data) # Stream data after confirmation
282+
283+
# Stream data after confirmation
284+
self._write(data)
285285
# Ignore response, it's not reliable
286286

287287
def ReadMemory(self, start: int, num_bytes: int):
288288
"""
289289
Send command with newline, receive response code\r\n<data>
290290
"""
291-
assert num_bytes % self.kWordSize == 0 # On a word boundary
291+
292+
# On a word boundary
293+
assert num_bytes % self.kWordSize == 0
292294
function = "ReadMemory"
293295
command = f"R {start} {num_bytes}"
294296

@@ -334,9 +336,9 @@ def Go(self, address: int, thumb_mode: bool = False):
334336
if thumb_mode:
335337
mode = "T"
336338
response_code = self._write_command(f"G {address} {mode}")
337-
if (
338-
response_code != self.ReturnCodes["NoStatusResponse"]
339-
): # Don't expect a response code from this
339+
340+
# Don't expect a response code from this
341+
if response_code != self.ReturnCodes["NoStatusResponse"]:
340342
_raise_return_code_error(response_code, "Go")
341343

342344
def EraseSector(self, start: int, end: int):
@@ -467,7 +469,8 @@ def SetCrystalFrequency(self, frequency_khz: int):
467469
verified = False
468470
for _ in range(3):
469471
try:
470-
frame_in = self._read_line() # Should be OK\r\n
472+
frame_in = self._read_line()
473+
# Should be OK\r\n
471474
if self.SyncVerifiedString in frame_in:
472475
verified = True
473476
break
@@ -520,7 +523,7 @@ def SyncConnection(self):
520523
# self._flush()
521524
_log.debug(f"Echoing sync string, {repr(self.SyncStringBytes)}")
522525
time.sleep(0.1)
523-
self._write(self.SyncStringBytes) # echo SyncString
526+
self._write(self.SyncStringBytes)
524527
self.write_newline()
525528
self.write_newline()
526529
# > Synchronized\n
@@ -569,7 +572,7 @@ class ChipDescription:
569572
Wraps a chip description line and exposes it as a class
570573
"""
571574

572-
kWordSize = 4 # 32 bit
575+
kWordSize = 4
573576
kPageSizeBytes = 64
574577
SectorSizePages = 16
575578
CRCLocation = 0x000002FC
@@ -589,14 +592,13 @@ def __init__(self, descriptor: dict[str, typing.Any]):
589592
self.RAMBufferSize = int(descriptor.pop("RAMBufferSize"))
590593
self.SectorCount: int = int(descriptor.pop("SectorCount"))
591594
self.RAMStartWrite: int = int(descriptor.pop("RAMStartWrite"))
592-
self.CrystalFrequency = 12000 # khz == 30MHz
593-
self.kCheckSumLocation = 7 # 0x0000001c
595+
self.CrystalFrequency = 12000
596+
# 0x0000001c
597+
self.kCheckSumLocation = 7
594598

595599
assert self.RAMRange[0] > 0
596600
assert self.RAMRange[1] > self.RAMRange[0]
597-
598601
assert self.FlashRange[1] > self.FlashRange[0]
599-
600602
assert self.SectorCount > 0
601603

602604
@property
@@ -638,9 +640,7 @@ def RamRangeLegal(self, address, length):
638640

639641
# Script tools
640642

641-
assert (
642-
tools.calc_crc(bytes([0xFF] * 1024)) == 3090874356
643-
) # Check the software crc algorithm
643+
assert tools.calc_crc(bytes([0xFF] * 1024)) == 3090874356
644644

645645

646646
def RemoveBootableCheckSum(vector_table_loc: int, image: bytes) -> bytes:
@@ -667,7 +667,8 @@ def GetCheckSumedVectorTable(vector_table_loc: int, orig_image: bytes) -> bytes:
667667

668668
# calculate the checksum over the interrupt vectors
669669
intvecs_list = list(intvecs[:vector_table_size])
670-
intvecs_list[vector_table_loc] = 0 # clear csum value
670+
# clear csum value
671+
intvecs_list[vector_table_loc] = 0
671672
csum = tools.CalculateCheckSum(intvecs_list)
672673
intvecs_list[vector_table_loc] = csum
673674
vector_table_bytes = b""
@@ -678,7 +679,6 @@ def GetCheckSumedVectorTable(vector_table_loc: int, orig_image: bytes) -> bytes:
678679

679680
def MakeBootable(vector_table_loc: int, orig_image: bytes) -> bytes:
680681
vector_table_bytes = GetCheckSumedVectorTable(vector_table_loc, orig_image)
681-
682682
image = vector_table_bytes + orig_image[len(vector_table_bytes) :]
683683
return image
684684

@@ -791,7 +791,8 @@ def WriteFlashSector(
791791
def WriteSector(isp: ISPConnection, chip: ChipDescription, sector: int, data: bytes):
792792
assert len(data) > 0
793793

794-
if len(data) != chip.sector_bytes: # Fill data buffer to match write size
794+
# Fill data buffer to match write size
795+
if len(data) != chip.sector_bytes:
795796
data += bytes([0xFF] * (chip.sector_bytes - len(data)))
796797
WriteFlashSector(isp, chip, sector, data)
797798

@@ -820,10 +821,9 @@ def WriteBinaryToFlash(
820821
isp.Unlock()
821822
for sector in reversed(range(start_sector, start_sector + sector_count)):
822823
_log.info(f"\nWriting Sector {sector} / {sector_count}")
823-
data_chunk = image[
824-
(sector - start_sector) * chip.sector_bytes : (sector - start_sector + 1)
825-
* chip.sector_bytes
826-
]
824+
start = (sector - start_sector) * chip.sector_bytes
825+
end = (sector - start_sector + 1) * chip.sector_bytes
826+
data_chunk = image[start:end]
827827
WriteSector(isp, chip, sector, data_chunk)
828828
time.sleep(isp.settings.flash_write_sleep)
829829

0 commit comments

Comments
 (0)