Skip to content

Commit

Permalink
fixup! Fix issues found by flake8
Browse files Browse the repository at this point in the history
The files in bin were missed when running flake8 and the
other changes were previously ignored.

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
  • Loading branch information
hnez committed Mar 13, 2024
1 parent 1fe3354 commit 7c52bf9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
1 change: 0 additions & 1 deletion bin/lxa-iobus-lpc11xxcanisp-invoke
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-

import canopen
from time import sleep
import struct


Expand Down
35 changes: 8 additions & 27 deletions bin/lxa-iobus-lpc11xxcanisp-program
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import canopen
import struct
import sys
import time
import argparse
import logging
Expand Down Expand Up @@ -51,7 +50,7 @@ class IspSdoAbortedError(Exception):
def __str__(self):
text = "Code 0x{:08X}".format(self.code)
reason = self.str()
if not reason is None:
if reason is not None:
text += ", " + reason
return text

Expand Down Expand Up @@ -99,50 +98,28 @@ class CanIsp:

part_ids = {
0x041E502B: "LPC1111FHN33/101",
0x2516D02B: "LPC1111FHN33/101",
0x2516D02B: "LPC1111FHN33/102",
0x0416502B: "LPC1111FHN33/201",
0x2516902B: "LPC1111FHN33/201",
0x2516902B: "LPC1111FHN33/202",
0x00010013: "LPC1111FHN33/103",
0x00010012: "LPC1111FHN33/203",
0x042D502B: "LPC1112FHN33/101",
0x2524D02B: "LPC1112FHN33/101",
0x2524D02B: "LPC1112FHN33/102",
0x0425502B: "LPC1112FHN33/201",
0x2524902B: "LPC1112FHN33/201",
0x2524902B: "LPC1112FHN33/202",
0x2524902B: "LPC1112FHI33/202",
0x00020023: "LPC1112FHN33/103",
0x00020022: "LPC1112FHN33/203",
0x00020022: "LPC1112FHI33/203",
0x0434502B: "LPC1113FHN33/201",
0x2532902B: "LPC1113FHN33/201",
0x2532902B: "LPC1113FHN33/202",
0x0434102B: "LPC1113FHN33/301",
0x2532102B: "LPC1113FHN33/301",
0x2532102B: "LPC1113FHN33/302",
0x0434102B: "LPC1113FBD48/301",
0x2532102B: "LPC1113FBD48/301",
0x2532102B: "LPC1113FBD48/302",
0x00030030: "LPC1113FBD48/303",
0x00030032: "LPC1113FHN33/203",
0x00030030: "LPC1113FHN33/303",
0x0444502B: "LPC1114FHN33/201",
0x2540902B: "LPC1114FHN33/201",
0x2540902B: "LPC1114FHN33/202",
0x0444102B: "LPC1114FHN33/301",
0x2540102B: "LPC1114FHN33/301",
0x2540102B: "LPC1114FHN33/302",
0x2540102B: "LPC1114FHI33/302",
0x0444102B: "LPC1114FBD48/301",
0x2540102B: "LPC1114FBD48/301",
0x2540102B: "LPC1114FBD48/302",
0x00040040: "LPC1114FBD48/303",
0x00040042: "LPC1114FHN33/203",
0x00040040: "LPC1114FHN33/303",
0x00040060: "LPC1114FBD48/323",
0x00040070: "LPC1114FBD48/333",
0x00040070: "LPC1114FHN33/333",
0x00040040: "LPC1114FHI33/303",
0x2540102B: "LPC11D14FBD100/302",
Expand Down Expand Up @@ -331,8 +308,9 @@ class CanIsp:
logging.info("Send block %d", block_num)

start_offset = block_size * (block_num - start_sector)
end_offset = start_offset + block_size

block = data[start_offset : start_offset + block_size]
block = data[start_offset:end_offset]
logging.info("Block length %d", len(block))
self.write_to_ram(self.ram_offset, block) # Transfer data block to the RAM of the MCU

Expand All @@ -351,13 +329,16 @@ def fix_checksum(data):
For more info see: UM10398 26.3.3 Criterion for Valid User Code.
"""

vector_table = data[0 : 4 * 7] # First 7 entrys
size = 4 * 7
vector_table = data[0:size] # First 7 entrys
vector_table = struct.unpack("iiiiiii", vector_table)

checksum = 0 - (sum(vector_table))
checksum = struct.pack("i", checksum)

data = data[0 : 4 * 7] + checksum + data[4 * 8 :]
pre = 4 * 7
post = 4 * 8
data = data[0:pre] + checksum + data[post:]
return data


Expand Down
13 changes: 9 additions & 4 deletions lxa_iobus/lpc11xxcanisp/can_isp.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def console_log(self, *message):
self._console.append(message)

if len(self._console) > console_max_len:
self._console = self._console[len(self._console) - console_max_len :]
start = len(self._console) - console_max_len
self._console = self._console[start:]

self.server.rpc.worker_pool.run_sync(
partial(self.server.rpc.notify, "isp_console", self._console),
Expand Down Expand Up @@ -384,8 +385,9 @@ def flash_image(self, start, data):
logging.info("Send block %d", block_num)

start_offset = block_size * (block_num - start_sector)
end_offset = start_offset + block_size

block = data[start_offset : start_offset + block_size]
block = data[start_offset:end_offset]
logging.info("Block length %d", len(block))

# Transfer data block to the RAM of the MCU
Expand All @@ -410,13 +412,16 @@ def fix_checksum(self, data):
For more info see: UM10398 26.3.3 Criterion for Valid User Code.
"""

vector_table = data[0 : 4 * 7] # First 7 entries
size = 4 * 7
vector_table = data[0:size] # First 7 entries
vector_table = struct.unpack("iiiiiii", vector_table)

checksum = 0 - (sum(vector_table))
checksum = struct.pack("i", checksum)

data = data[0 : 4 * 7] + checksum + data[4 * 8 :]
pre = 4 * 7
post = 4 * 8
data = data[0:pre] + checksum + data[post:]

return data

Expand Down
7 changes: 5 additions & 2 deletions lxa_iobus/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ async def sdo_read(self, index, sub_index, timeout=DEFAULT_TIMEOUT):

# We get a packet where the size field is used
if response.readable_transfer_type == "DataWithSize":
return response.data[0 : 4 - response.number_of_bytes_not_used]
size = 4 - response.number_of_bytes_not_used
return response.data[0:size]

# We got a packet data uses the packet length as size
# Is not used in the firmware
Expand Down Expand Up @@ -277,11 +278,13 @@ async def sdo_write(self, index, sub_index, data, timeout=DEFAULT_TIMEOUT):
if len(data) == offset + length:
complete = True

end = offset + length

message = gen_sdo_segment_download(
node_id=self.node_id,
toggle=toggle,
complete=complete,
seg_data=data[offset : offset + length],
seg_data=data[offset:end],
)

response = await self._send_sdo_message(
Expand Down

0 comments on commit 7c52bf9

Please sign in to comment.