Skip to content

Commit

Permalink
Merge pull request #261 from boramonideep/fix_xmc_flasher
Browse files Browse the repository at this point in the history
Fix xmc flasher
  • Loading branch information
boramonideep authored Jan 15, 2024
2 parents dc93efd + 54b8a52 commit 0709c2c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tools/xmc-flasher.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import argparse, serial, subprocess, os, sys, re, json, warnings
import argparse, subprocess, os, sys, re, warnings, winreg
from serial.tools.list_ports import comports
from xmc_data import xmc_master_data

version = '0.1.0'

jlinkexe = ''

def check_python_version():
major = sys.version_info.major
minor = sys.version_info.minor

if major != 3:
raise Exception(f"XMC Flasher requires Python3! Current version is {major}.{minor}")

def get_jlink_install_path():
location = winreg.HKEY_CURRENT_USER
try:
key = winreg.OpenKeyEx(location,'SOFTWARE\\SEGGER\\J-Link',reserved=0,access=winreg.KEY_READ)
except:
raise Exception("SEGGER JLink not installed!")
value = winreg.QueryValueEx(key,"InstallPath")
winreg.CloseKey(key)
return value[0]

def set_environment():
global jlinkexe
if sys.platform == 'linux' or sys.platform == 'linux2':
jlinkexe = 'JLinkExe'
elif sys.platform == 'win32' or sys.platform == 'cygwin':
jlinkexe = 'jlink'
jlinkexe = rf"{get_jlink_install_path()}\jlink.exe"
elif sys.platform == 'darwin':
jlinkexe = 'jlink'
print('warning: mac os not validated')
Expand Down Expand Up @@ -112,6 +129,9 @@ def get_mem_contents(addr, bytes, device, port):
reg_contents = re.findall('[0-9,A-F]+', line)
break

if not reg_contents:
raise Exception(f"Wrong COM Port selected! {port}\n")

reg_contents.remove(addr) # remove the addr from the list, just keep reg contents
reg_contents.reverse() # jlink returns LSB first, so reverse it to get MSB on the left side
reg_contents = ''.join(reg_contents)
Expand Down Expand Up @@ -239,5 +259,6 @@ def __call__(self, parser, namespace, values, option_string, **kwargs):

if __name__ == "__main__":
set_environment()
check_python_version()
parser()

0 comments on commit 0709c2c

Please sign in to comment.