code: def erase(self):
          
          try:
              # This has to be in a try-catch, as the device may not be in a
              # state where it can halt, but we still want to try and erase.
              if not self.halted():
                  self.halt()
          except errors.JLinkException:
              # Can't halt, so just continue to erasing.
              pass
  
          res = self._dll.JLINK_EraseChip()
          if res < 0:
              raise errors.JLinkEraseException(res)
  
          return res
docs: Erases the flash contents of the device.
  
          This erases the flash memory of the target device.  If this method
          fails, the device may be left in an inoperable state.
  
          Args:
            self (JLink): the ``JLink`` instance
  
          Returns:
            Number of bytes erased.