Browse Source

Implement E and I commands

As with the other commands that take a range of flash sectors, the end
is optional.  I returns None if the sectors are blank, or an offset and
value if the sectors are not blank.
Clara Hobbs 6 years ago
parent
commit
addcf9286f
1 changed files with 32 additions and 0 deletions
  1. 32
    0
      alpaca_isp/__init__.py

+ 32
- 0
alpaca_isp/__init__.py View File

@@ -217,6 +217,38 @@ class LPC:
217 217
         """
218 218
         self._writeline("G {} {}\r\n".format(address, mode).encode("utf-8"))
219 219
 
220
+    def erase(self, start, end=None):
221
+        """Erase the given flash sector(s)
222
+
223
+        If end is not specified, only the start sector is erased.
224
+        """
225
+        if end is None:
226
+            end = start
227
+        self._send_command("E {} {}\r\n".format(start, end).encode("utf-8"))
228
+
229
+    def blank_check(self, start, end=None):
230
+        """Check if the given flash sectors are blank
231
+
232
+        If end is not specified, only the start sector is checked.
233
+
234
+        Returns None if the sector is blank, or a tuple containing the offset
235
+        and value of the first non-blank word location if the sector is not
236
+        blank.  If CRP is enabled, the offset and value are always reported as
237
+        zero.
238
+        """
239
+        if end is None:
240
+            end = start
241
+        try:
242
+            self._send_command("I {} {}\r\n".format(start, end).encode(
243
+                "utf-8"))
244
+        except ISPError as e:
245
+            # Return a tuple for SECTOR_NOT_BLANK
246
+            if e.args[0][0] == ReturnCode.SECTOR_NOT_BLANK:
247
+                offset = int(self._readline().strip())
248
+                value = int(self._readline().strip())
249
+                return (offset, value)
250
+            raise
251
+
220 252
 
221 253
 class ReturnCode(Enum):
222 254
     """LPC ISP return codes

Loading…
Cancel
Save