Skip to content

Commit 3a1bcec

Browse files
committed
removing pandas, adding 'test'
workflow specifying python 3.9 adding venv adding venv rebasing master updating workflow updating workflow updating workflow updating workflow updating workflow updating workflow updating workflow updating workflow
1 parent 220c99b commit 3a1bcec

File tree

7 files changed

+76
-61
lines changed

7 files changed

+76
-61
lines changed

.github/workflows/pyinstaller-package.yml

+18-8
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,30 @@ jobs:
1313

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

1818
steps:
19-
- uses: actions/checkout@v2
20-
- name: Install dependencies
21-
run: |
22-
python -m pip install --upgrade pip
23-
python -m pip install flake8 pytest pylint
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-python@v5
21+
with:
22+
#python-version: '>=3.9 <3.14'
23+
python-version: '3.9'
24+
2425
- name: Install
2526
run: |
26-
python -m pip install .
27+
python3 -m pip install --upgrade pip
28+
python3 -m pip install pyserial
29+
python3 -m pip install pyinstaller
30+
python3 -m pip install .
31+
32+
- name: Verify Installations
33+
run: |
34+
python3 -m pip show isp_programmer
35+
python3 -m pip show pyserial
36+
2737
- name: Make executable
2838
uses: sayyid5416/pyinstaller@v1
2939
with:
30-
python-version: 3.12
3140
spec: 'packaging/gui-tklinux.spec'
3241
upload_exe_with_name: 'isp-programmer-${{ matrix.os }}'
42+
python_ver: '3.9'

packaging/gui-tklinux.spec

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ binaries = []
66
hiddenimports = []
77
tmp_ret = collect_all('isp_programmer')
88
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
9-
tmp_ret = collect_all('pyserial')
10-
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
119
tmp_ret = collect_all('serial')
1210
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
1311

@@ -23,7 +21,7 @@ a = Analysis(
2321
runtime_hooks=[],
2422
excludes=[],
2523
noarchive=False,
26-
optimize=0,
24+
optimize=2,
2725
)
2826
pyz = PYZ(a.pure)
2927

@@ -36,8 +34,8 @@ exe = EXE(
3634
name='isp-programmer',
3735
debug=False,
3836
bootloader_ignore_signals=False,
39-
#strip=False,
40-
strip=True,
37+
strip=False,
38+
#strip=True,
4139
upx=True,
4240
upx_exclude=[],
4341
runtime_tmpdir=None,

pyproject.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors = [
88
license = {file="LICENSE"}
99
readme = "README.md"
1010

11-
requires-python = ">=3.6"
11+
requires-python = ">=3.9"
1212
keywords = ["isp", "nxp", "program", "uart"]
1313
classifiers = [
1414
"Programming Language :: Python :: 3",
@@ -19,8 +19,6 @@ dependencies = [
1919
"intelhex>=2.3.0",
2020
"pycrc>=0.10.0",
2121
"click>=8.0.0",
22-
"pandas>=2.2.0",
23-
"numpy>=1.26.0"
2422
]
2523

2624
[project.urls]

src/isp_programmer/ISPConnection.py

+30-30
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
_log = logging.getLogger("isp_programmer")
1717

1818
kTimeout = 1
19-
20-
2119
BAUDRATES = (9600, 19200, 38400, 57600, 115200, 230400, 460800)
22-
23-
2420
NXPReturnCodes = {
2521
"CMD_SUCCESS": 0x0,
2622
"INVALID_COMMAND": 0x1,
@@ -82,7 +78,8 @@ def _raise_return_code_error(code: int, call_name: str) -> None:
8278

8379
@dataclass
8480
class Settings:
85-
safe_write: bool = True # Check to see if sector is already equal to RAM, if so skip
81+
# Check to see if sector is already equal to RAM, if so skip
82+
safe_write: bool = True
8683
flash_write_sleep: float = 0.01
8784
ram_write_sleep: float = 0.01
8885
return_code_sleep: float = 0.05
@@ -100,7 +97,7 @@ class ISPConnection:
10097

10198
kNewLine = "\r\n"
10299
StatusRespLength = len(kNewLine) + 1
103-
kWordSize = 4 # 32 bit device
100+
kWordSize = 4
104101
# Parity = None
105102
# DataBits = 8
106103
# StopBits = 1
@@ -211,7 +208,8 @@ def _get_return_code(self, command_string: str) -> int:
211208
if resp.strip() == command_string.strip():
212209
_log.debug("Command was echoed, Discarding line: %s", resp)
213210
resp = self._read_line()
214-
# if self.echo_on: # discard echo
211+
# discard echo
212+
# if self.echo_on:
215213
# _log.debug("ECHO ON, Discarding line: %s", resp)
216214
# resp = self._read_line()
217215
except TimeoutError:
@@ -265,7 +263,7 @@ def SetEcho(self, on: bool = True):
265263
"""
266264
ISP echos host when enabled
267265
"""
268-
command = f"A {on : d}"
266+
command = f"A {on:d}"
269267
response_code = self._write_command(command)
270268
_raise_return_code_error(response_code, "Set Echo")
271269
self.echo_on = on
@@ -284,14 +282,18 @@ def WriteToRam(self, start: int, data: bytes):
284282
# when transfer is complete the handler sends OK<CR><LF>
285283
response_code = self._write_command(f"W {start} {len(data)}")
286284
_raise_return_code_error(response_code, function_name)
287-
self._write(data) # Stream data after confirmation
285+
286+
# Stream data after confirmation
287+
self._write(data)
288288
# Ignore response, it's not reliable
289289

290290
def ReadMemory(self, start: int, num_bytes: int):
291291
"""
292292
Send command with newline, receive response code\r\n<data>
293293
"""
294-
assert num_bytes % self.kWordSize == 0 # On a word boundary
294+
295+
# On a word boundary
296+
assert num_bytes % self.kWordSize == 0
295297
function = "ReadMemory"
296298
command = f"R {start} {num_bytes}"
297299

@@ -337,9 +339,9 @@ def Go(self, address: int, thumb_mode: bool = False):
337339
if thumb_mode:
338340
mode = "T"
339341
response_code = self._write_command(f"G {address} {mode}")
340-
if (
341-
response_code != self.ReturnCodes["NoStatusResponse"]
342-
): # Don't expect a response code from this
342+
343+
# Don't expect a response code from this
344+
if response_code != self.ReturnCodes["NoStatusResponse"]:
343345
_raise_return_code_error(response_code, "Go")
344346

345347
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
@@ -526,7 +529,7 @@ def SyncConnection(self):
526529
# self._flush()
527530
_log.debug(f"Echoing sync string, {repr(self.SyncStringBytes)}")
528531
time.sleep(0.1)
529-
self._write(self.SyncStringBytes) # echo SyncString
532+
self._write(self.SyncStringBytes)
530533
self.write_newline()
531534
self.write_newline()
532535
# > Synchronized\n
@@ -575,7 +578,7 @@ class ChipDescription:
575578
Wraps a chip description line and exposes it as a class
576579
"""
577580

578-
kWordSize = 4 # 32 bit
581+
kWordSize = 4
579582
kPageSizeBytes = 64
580583
SectorSizePages = 16
581584
CRCLocation = 0x000002FC
@@ -595,14 +598,13 @@ def __init__(self, descriptor: dict[str, typing.Any]):
595598
self.RAMBufferSize = int(descriptor.pop("RAMBufferSize"))
596599
self.SectorCount: int = int(descriptor.pop("SectorCount"))
597600
self.RAMStartWrite: int = int(descriptor.pop("RAMStartWrite"))
598-
self.CrystalFrequency: int = 12000 # khz == 30MHz
599-
self.kCheckSumLocation: int = 7 # 0x0000001c
601+
self.CrystalFrequency = 12000
602+
# 0x0000001c
603+
self.kCheckSumLocation = 7
600604

601605
assert self.RAMRange[0] > 0
602606
assert self.RAMRange[1] > self.RAMRange[0]
603-
604607
assert self.FlashRange[1] > self.FlashRange[0]
605-
606608
assert self.SectorCount > 0
607609

608610
@property
@@ -644,9 +646,7 @@ def RamRangeLegal(self, address, length):
644646

645647
# Script tools
646648

647-
assert (
648-
tools.calc_crc(bytes([0xFF] * 1024)) == 3090874356
649-
) # Check the software crc algorithm
649+
assert tools.calc_crc(bytes([0xFF] * 1024)) == 3090874356
650650

651651

652652
def RemoveBootableCheckSum(vector_table_loc: int, image: bytes) -> bytes:
@@ -673,7 +673,8 @@ def GetCheckSumedVectorTable(vector_table_loc: int, orig_image: bytes) -> bytes:
673673

674674
# calculate the checksum over the interrupt vectors
675675
intvecs_list = list(intvecs[:vector_table_size])
676-
intvecs_list[vector_table_loc] = 0 # clear csum value
676+
# clear csum value
677+
intvecs_list[vector_table_loc] = 0
677678
csum = tools.CalculateCheckSum(intvecs_list)
678679
intvecs_list[vector_table_loc] = csum
679680
vector_table_bytes = b""
@@ -684,7 +685,6 @@ def GetCheckSumedVectorTable(vector_table_loc: int, orig_image: bytes) -> bytes:
684685

685686
def MakeBootable(vector_table_loc: int, orig_image: bytes) -> bytes:
686687
vector_table_bytes = GetCheckSumedVectorTable(vector_table_loc, orig_image)
687-
688688
image = vector_table_bytes + orig_image[len(vector_table_bytes) :]
689689
return image
690690

@@ -797,7 +797,8 @@ def WriteFlashSector(
797797
def WriteSector(isp: ISPConnection, chip: ChipDescription, sector: int, data: bytes):
798798
assert len(data) > 0
799799

800-
if len(data) != chip.sector_bytes: # Fill data buffer to match write size
800+
# Fill data buffer to match write size
801+
if len(data) != chip.sector_bytes:
801802
data += bytes([0xFF] * (chip.sector_bytes - len(data)))
802803
WriteFlashSector(isp, chip, sector, data)
803804

@@ -826,10 +827,9 @@ def WriteBinaryToFlash(
826827
isp.Unlock()
827828
for sector in reversed(range(start_sector, start_sector + sector_count)):
828829
_log.info(f"\nWriting Sector {sector} / {sector_count}")
829-
data_chunk = image[
830-
(sector - start_sector) * chip.sector_bytes : (sector - start_sector + 1)
831-
* chip.sector_bytes
832-
]
830+
start = (sector - start_sector) * chip.sector_bytes
831+
end = (sector - start_sector + 1) * chip.sector_bytes
832+
data_chunk = image[start:end]
833833
WriteSector(isp, chip, sector, data_chunk)
834834
time.sleep(isp.settings.flash_write_sleep)
835835

src/isp_programmer/parts_definitions.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
consistent with other formats
44
"""
55

6-
import pandas
7-
import numpy as np
8-
96
column_names = [
107
"part id",
118
"name",
@@ -55,20 +52,23 @@ def read_lpcparts_string(string: str) -> dict[str, list]:
5552
except ValueError:
5653
df_dict[column].append(read)
5754

58-
for col in df_dict:
59-
df_dict[col] = np.array(df_dict[col])
60-
61-
df = pandas.DataFrame(df_dict)
62-
df["RAMEnd"] = np.array(df["RAMStart"]) + np.array(df["RAMSize"]) - 1
63-
df["FlashEnd"] = np.array(df["FlashStart"]) + np.array(df["FlashSize"]) - 1
64-
df["RAMStartWrite"] = np.array(df["RAMStart"]) + np.array(df["RAMBufferOffset"])
55+
df = df_dict
56+
df["RAMEnd"] = [
57+
start + size - 1 for start, size in zip(df["RAMStart"], df["RAMSize"])
58+
]
59+
df["FlashEnd"] = [
60+
start + size - 1 for start, size in zip(df["FlashStart"], df["FlashSize"])
61+
]
62+
df["RAMStartWrite"] = [
63+
start + offset for start, offset in zip(df["RAMStart"], df["RAMBufferOffset"])
64+
]
6565

6666
df["RAMRange"] = list(zip(df["RAMStart"], df["RAMEnd"]))
6767
df["FlashRange"] = list(zip(df["FlashStart"], df["FlashEnd"]))
6868
return df
6969

7070

71-
def ReadChipFile(fname: str) -> pandas.DataFrame:
71+
def ReadChipFile(fname: str) -> dict:
7272
"""
7373
Reads an lpcparts style file to a dataframe
7474
"""
@@ -79,9 +79,9 @@ def ReadChipFile(fname: str) -> pandas.DataFrame:
7979

8080
def GetPartDescriptorLine(fname: str, partid: int) -> dict[str, str]:
8181
entries = ReadChipFile(fname)
82-
for _, entry in entries.iterrows():
83-
if partid == entry["part id"]:
84-
return entry
82+
for i, line_part_id in enumerate(entries["part id"]):
83+
if partid == line_part_id:
84+
return {key: entries[key][i] for key in entries}
8585
raise UserWarning(f"PartId {partid} not found in {fname}")
8686

8787

tests/lpctools_parts.def

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../src/isp_programmer/lpctools_parts.def

tests/test_read_lpcparts_file.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from isp_programmer import parts_definitions
22

3+
def_file = "lpctools_parts.def"
4+
35
if __name__ == "__main__":
4-
df = parts_definitions.ReadChipFile("../lpctools_parts.def")
6+
df = parts_definitions.ReadChipFile(def_file)
57
print(df)
8+
9+
line = parts_definitions.GetPartDescriptorLine(fname=def_file, partid=0x00008041)
10+
print(line)
11+
12+
line = parts_definitions.GetPartDescriptorLine(fname=def_file, partid=0x0000804)
13+
print(line)

0 commit comments

Comments
 (0)