Skip to content

Commit

Permalink
Fix: stm32w flasher for Ubuntu 12.04 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
eduble committed Nov 9, 2012
1 parent ecdbbae commit 7905316
Show file tree
Hide file tree
Showing 9 changed files with 1,975 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.log
*.elf
*.ihex
*.pyc
obj_*
symbols.*
Makefile.target
Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32w108/Makefile.stm32w108
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ endif



FLASHER = sudo $(CONTIKI)/tools/stm32w/stm32w_flasher/stm32w_flasher
FLASHER = sudo $(CONTIKI)/tools/stm32w/stm32w_flasher/py_files/stm32w_flasher.py

# Check if we are running under Windows
ifeq ($(HOST_OS),Windows)
Expand Down
83 changes: 83 additions & 0 deletions tools/stm32w/stm32w_flasher/py_files/file_utils.py
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)



25 changes: 25 additions & 0 deletions tools/stm32w/stm32w_flasher/py_files/messages.py
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()

287 changes: 287 additions & 0 deletions tools/stm32w/stm32w_flasher/py_files/prodeng.py

Large diffs are not rendered by default.

Loading

0 comments on commit 7905316

Please sign in to comment.