Example #1
0
def main():
    """Read whole SRAM"""
    parser = argparse.ArgumentParser()
    parser.add_argument('file', help='file name to save screen-shot')
    parser.add_argument("-z",
                        "--zoom",
                        type=int,
                        default=1,
                        help="zoom picture multiplicator")
    parser.add_argument("-b",
                        "--border",
                        type=int,
                        default=0,
                        help="add border around screenshot")
    args = parser.parse_args()
    print(args)
    dev = swd.Swd()
    memory = bytes(dev.read_mem(SRAM_START, SRAM_SIZE))
    frame_buffer = find_framebuffer(memory, FB_MAGIC_WORD, FB_OFFSET, FB_SIZE)
    frame_buffer = rotate_bytes(frame_buffer, WIDTH, HEIGHT)
    img = PIL.Image.frombytes('1', (WIDTH, HEIGHT), frame_buffer, 'raw')
    if args.border > 0:
        img = PIL.ImageOps.expand(img, args.border)
    if args.zoom > 1:
        img = img.resize((img.width * args.zoom, img.height * args.zoom))
    img.save(args.file)
Example #2
0
def main():
    """Main func"""
    dev = swd.Swd()
    button_up_last = None
    button_dw_last = None
    exit_time = 0
    while True:
        try:
            gpiob_inputs = dev.get_mem32(0x48000410)
            button_up = not bool(gpiob_inputs & (1 << 5))
            button_dw = not bool(gpiob_inputs & (1 << 4))
            if button_up != button_up_last or button_dw != button_dw_last:
                button_up_last = button_up
                button_dw_last = button_dw
                print("up: %d  dw: %d" % (button_up, button_dw))
            time.sleep(.1)
            if button_up and button_dw:
                exit_time += 1
                if exit_time > 10:
                    print("done")
                    break
            else:
                exit_time = 0
        except KeyboardInterrupt:
            print("exit")
            break
Example #3
0
 def start(self):
     """Application start point"""
     try:
         self._swd = swd.Swd(swd_frequency=self._swd_frequency,
                             serial_no=self._serial_no)
         # reading ID code can generate exception
         # and stop pyswd if no MCU is connected
         self._swd.get_idcode()
         self._cortexm = swd.CortexM(self._swd)
         self.print_device_info()
         self.process_actions()
     except swd.stlinkcom.StlinkComNotFound:
         logging.error("ST-Link not connected.")
     except swd.stlinkcom.StlinkComMoreDevices as err:
         logging.error(
             "ST-Link Found more devices with these serial numbers:\n  %s",
             "\n  ".join(err.serial_numbers))
         logging.error("Use parameter: -s serial_no")
     except PyswdException as err:
         logging.error("pyswd error: %s.", err)
     except swd.stlink.StlinkException as err:
         logging.critical("Stlink error: %s.", err)
     except swd.stlinkcom.StlinkComException as err:
         logging.critical("StlinkCom error: %s.", err)
     else:
         return 0
     return 1
Example #4
0
 def start(self):
     """Application start point"""
     try:
         self._swd = swd.Swd(swd_frequency=self._swd_frequency)
         self.print_device_info()
         self.process_actions()
     except swd.stlinkcom.StlinkComNotFound:
         logging.error("ST-Link not connected.")
     except PyswdException as err:
         logging.error("pyswd error: %s.", err)
     except swd.stlink.StlinkException as err:
         logging.critical("Stlink error: %s.", err)
     except swd.stlinkcom.StlinkComException as err:
         logging.critical("StlinkCom error: %s.", err)
     else:
         return 0
     return 1
Example #5
0
    def __init__(self, freq):
        try:
            self.dev = swd.Swd(swd_frequency=freq)
            self.cortex_m = swd.CortexM(self.dev)
            logger.info('Device found: {}'.format(self.dev.get_version()))
            logger.debug('Target Voltage: {} volts'.format(
                self.dev.get_target_voltage()))
            logger.debug('IDCODE: {}'.format(hex(self.dev.get_idcode())))

        except swd.stlink.usb.NoDeviceFoundException:
            logger.error('No debug interface detected')
            exit()
        except swd.stlink.usb.StlinkUsbException:
            logger.error('USB Error: Try reconnecting STLink')
            exit()
        except swd.stlink.StlinkException:
            logger.error(
                'Could not connect to target, ensure the target is powered')
            exit()
Example #6
0
File: _app.py Project: juergs/pyswd
 def start(self):
     """Application start point"""
     try:
         self._swd = swd.Swd(
             swd_frequency=self._swd_frequency,
             serial_no=self._serial_no,
             debug=self._debug)
         self.print_info(self._swd.get_version(), level=2)
         idcode = self._swd.get_idcode()
         if idcode == 0:
             raise PyswdException(
                 "No IDCODE, probably MCU is not connected")
         self._cortexm = swd.CortexM(self._swd)
         was_halted = self._cortexm.is_halted()
         if was_halted:
             self.print_info("Core is halted.")
         if self._actions:
             self.process_actions()
             is_halted = self._cortexm.is_halted()
             if was_halted != is_halted:
                 if is_halted:
                     self.print_info("Core stay halted.")
                 else:
                     self.print_info("Core is running.")
     except swd.stlink.usb.NoDeviceFoundException:
         self.print_error("ST-Link not connected.")
     except swd.stlink.usb.MoreDevicesException as err:
         self.print_error(
             f"ST-Link Found more devices with these serial numbers:")
         for serial_number in err.serial_numbers:
             self.print_error(serial_number, prefix="  ")
         self.print_error("Use parameter: -s serial_no", prefix="")
     except PyswdException as err:
         self.print_error(f"pyswd error: {err}.")
     except swd.stlink.StlinkException as err:
         self.print_error(f"Stlink error: {err}.")
     except swd.stlink.usb.StlinkUsbException as err:
         self.print_error(f"StlinkCom error: {err}.")
     else:
         return 0
     return 1
Example #7
0
File: _app.py Project: gyohng/pyswd
 def start(self):
     """Application start point"""
     try:
         self._swd = swd.Swd(
             swd_frequency=self._swd_frequency,
             serial_no=self._serial_no)
         # reading ID code can generate exception
         # and stop pyswd if no MCU is connected
         self.print_info(self._swd.get_version())
         self._swd.get_idcode()
         self._cortexm = swd.CortexM(self._swd)
         was_halted = self._cortexm.is_halted()
         if was_halted:
             self.print_noquite("Core is halted.")
         if self._actions:
             self.process_actions()
             is_halted = self._cortexm.is_halted()
             if was_halted != is_halted:
                 if is_halted:
                     self.print_noquite("Core stay halted.")
                 else:
                     self.print_noquite("Core is running.")
     except swd.stlinkcom.NoDeviceFoundException:
         logging.error("ST-Link not connected.")
     except swd.stlinkcom.MoreDevicesException as err:
         logging.error(
             "ST-Link Found more devices with these serial numbers:\n  %s",
             "\n  ".join(err.serial_numbers))
         logging.error("Use parameter: -s serial_no")
     except PyswdException as err:
         logging.error("pyswd error: %s.", err)
     except swd.stlink.StlinkException as err:
         logging.critical("Stlink error: %s.", err)
     except swd.stlinkcom.StlinkComException as err:
         logging.critical("StlinkCom error: %s.", err)
     else:
         return 0
     return 1
Example #8
0
 def setUp(self):
     self._drv = DrvMock()
     self._swd = swd.Swd(driver=self._drv)