changeset 131:04e45faafd1d

Added register view
author Windel Bouwman
date Sat, 19 Jan 2013 18:41:49 +0100
parents 654093a9a1e3
children 205578c96a79
files python/ide.py python/st-util.py python/stm32.py
diffstat 3 files changed, 55 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/python/ide.py	Sat Jan 19 18:16:04 2013 +0100
+++ b/python/ide.py	Sat Jan 19 18:41:49 2013 +0100
@@ -1,9 +1,7 @@
 #!/usr/bin/python
 
 import sys, os, base64
-if sys.version_info.major != 3:
-   print("Needs to be run in python version 3.x")
-   sys.exit(1)
+assert sys.version_info.major == 3, "Needs to be run in python version 3.x"
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
@@ -13,6 +11,7 @@
 import ppci
 from astviewer import AstViewer
 from codeeditor import CodeEdit
+stutil = __import__('st-util')
 
 lcfospng = base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\n/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJEhMKBk7B678AAAA/SURBVFjD\n7dbBCQAgDATBi9h/y7EFA4Kf2QLCwH1S6XQu6sqoujublc8BAAAAAAAAAAB8B+zXT6YJAAAAAKYd\nWSgFQNUyijIAAAAASUVORK5CYII=\n')
 
@@ -149,6 +148,9 @@
     self.builderrors.sigErrorSelected.connect(self.errorSelected)
     self.projectview = addComponent('Project explorer', ProjectView())
     self.projectview.sigLoadFile.connect(self.loadFile)
+    self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer())
+    self.regview = addComponent('Registers', stutil.RegisterView())
+    self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice)
 
     # About dialog:
     self.aboutDialog = AboutDialog()
--- a/python/st-util.py	Sat Jan 19 18:16:04 2013 +0100
+++ b/python/st-util.py	Sat Jan 19 18:41:49 2013 +0100
@@ -17,6 +17,41 @@
          fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString))
          fl.addRow('Status:', QLabel(parent.stl.StatusString))
 
+class RegisterModel(QAbstractTableModel):
+   def __init__(self):
+      super().__init__()
+      self.regCount = 15
+      self.device = None
+   def rowCount(self, parent):
+      if parent.isValid():
+         return 0
+      if self.device:
+         return 21 # TODO make variable
+      else:
+         return 0
+   def setDevice(self, dev):
+      self.device = dev
+      self.modelReset.emit()
+   def columnCount(self, parent):
+      if parent.isValid():
+         return 0
+      return 2
+   def data(self, index, role):
+      if index.isValid():
+         row, col = index.row(), index.column()
+         if role == Qt.DisplayRole:
+            if col == 0:
+               return 'R{0}'.format(row)
+            elif col == 1:
+               v = self.device.iface.read_reg(row)
+               return '0x{0:X}'.format(v)
+
+class RegisterView(QTableView):
+   def __init__(self):
+      super().__init__()
+      self.mdl = RegisterModel()
+      self.setModel(self.mdl)
+
 class DeviceTreeModel(QAbstractItemModel):
    def __init__(self):
       super().__init__()
--- a/python/stm32.py	Sat Jan 19 18:16:04 2013 +0100
+++ b/python/stm32.py	Sat Jan 19 18:41:49 2013 +0100
@@ -20,22 +20,12 @@
 FLASH_F4_CR_SNB_MASK = 0x38
 FLASH_F4_SR_BSY = 16
 
-@registerDevice(0x10016413)
 class Stm32F4(Device):
    """
       Implementation of the specifics of the STM32F4xx device series.
    """
    def __init__(self, iface):
       super().__init__(iface)
-      # Assert the proper size for this device:
-      assert self.FlashSize == 0x100000
-      """
-         from 0x8000000 to 0x80FFFFF
-         4 sectors of 0x4000 (16 kB)
-         1 sector of 0x10000 (64 kB)
-         7 of 0x20000 (128 kB)
-      """
-      self.sectorsizes = [0x4000] * 4 + [0x10000] + [0x20000] * 7
    def __str__(self):
       return 'STM32F4 device size=0x{1:X} id=0x{0:X}'.format(\
          self.UID, self.FlashSize)
@@ -236,3 +226,18 @@
             raise STLinkException(msg)
       return sr & mask == mask
 
+@registerDevice(0x10016413)
+class Stm32F40x(Stm32F4):
+   """ STM32F40x and STM32F41x device series """
+   def __init__(self, iface):
+      super().__init__(iface)
+      # Assert the proper size for this device:
+      assert self.FlashSize == 0x100000
+      """
+         from 0x8000000 to 0x80FFFFF
+         4 sectors of 0x4000 (16 kB)
+         1 sector of 0x10000 (64 kB)
+         7 of 0x20000 (128 kB)
+      """
+      self.sectorsizes = [0x4000] * 4 + [0x10000] + [0x20000] * 7
+