-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: stm32w flasher for Ubuntu 12.04 and later
- Loading branch information
Showing
9 changed files
with
1,975 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
*.log | ||
*.elf | ||
*.ihex | ||
*.pyc | ||
obj_* | ||
symbols.* | ||
Makefile.target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
# See comment in stm32w_flasher.py. | ||
# Extraction and little adaptation performed by E.Duble (CNRS, LIG). | ||
|
||
import struct | ||
|
||
|
||
class Error(Exception): | ||
"""Base class for exceptions in this module.""" | ||
args = None | ||
message = None | ||
|
||
class FileFormatError(Error): | ||
""" | ||
Exception raised for errors in the file format | ||
Attributes: | ||
filename -- filename with unknown format | ||
message -- format error message | ||
""" | ||
args = None | ||
message = None | ||
def __init__(self, filename, message): | ||
self.filename = filename | ||
self.message = message | ||
|
||
|
||
class fileFormatReader(object): | ||
def __init__(self, filename, startAddress=None): | ||
self.filename = filename | ||
self.startAddress = startAddress | ||
|
||
def getRawBinary(self): | ||
fileContent = None | ||
bytes = None | ||
f = open(self.filename, 'rb') | ||
if self.filename[-4:] == '.bin': | ||
bytesRaw = f.read() | ||
bytes = [] | ||
bytes.extend(struct.unpack(('B' * len(bytesRaw)), bytesRaw)) | ||
f.close() | ||
else: | ||
if self.filename[-4:] == '.s37': | ||
fillChar = 255 | ||
fileContent = f.readlines() | ||
f.close() | ||
startAddress = None | ||
currentAddress = None | ||
bytes = [] | ||
for line in fileContent: | ||
if line[:2] == 'S3': | ||
count = int(line[2:4], 16) | ||
if startAddress is None: | ||
startAddress = int(line[4:12], 16) | ||
currentAddress = startAddress | ||
address = int(line[4:12], 16) | ||
if currentAddress < address: | ||
bytes = (bytes + ([fillChar] * (address - currentAddress))) | ||
currentAddress = address | ||
else: | ||
if currentAddress > address: | ||
raise FileFormatError(self.filename, 'S37, Non progressing addresses detected') | ||
for i in range((count - 5)): | ||
bytes = (bytes + [int(line[(12 + (i * 2)):((12 + (i * 2)) + 2)], 16)]) | ||
continue | ||
currentAddress = (currentAddress + (count - 5)) | ||
continue | ||
else: | ||
if line[:2] == 'S0': | ||
continue | ||
else: | ||
if line[:2] == 'S7': | ||
break | ||
else: | ||
raise FileFormatError(self.filename, 'S37: unknown field type') | ||
self.startAddress = startAddress | ||
else: | ||
raise FileFormatError(self.filename, 'Unknown extension') | ||
return (self.startAddress, bytes) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
# See comment in stm32w_flasher.py. | ||
# Extraction and little adaptation performed by E.Duble (CNRS, LIG). | ||
|
||
import sys | ||
|
||
|
||
def errorMessage(msg, header=True): | ||
if header: | ||
sys.stderr.write('ERROR: ') | ||
sys.stderr.write(msg) | ||
sys.stderr.flush() | ||
|
||
def infoMessage(msg, header=True): | ||
if header: | ||
sys.stdout.write('INFO: ') | ||
sys.stdout.write(msg) | ||
sys.stdout.flush() | ||
|
||
def warningMessage(msg, header=True): | ||
if header: | ||
sys.stderr.write('WARNING: ') | ||
sys.stderr.write(msg) | ||
sys.stderr.flush() | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.