コード例 #1
0
def before_upload(source, target, env):
    upload_options = env.BoardConfig().get("upload", {})
    b_request = None
    exists = False
    id_vendor = None
    id_product = None
    wait_for_serial = False
    if "ardwiino_bootloader_teensy" in upload_options and upload_options["ardwiino_bootloader_teensy"] == "true":
        b_request = BOOTLOADER
    elif "ardwiino_bootloader" in upload_options and upload_options["ardwiino_bootloader"] == "true":
        b_request = BOOTLOADER
        wait_for_serial = True
    if "/arduino_uno_mega_usb" in str(source[0]):
        id_vendor = 0x03eb
        id_product = None
        b_request = BOOTLOADER
        if (libusb_package.find(idVendor=0x1209, idProduct=0x2883)):
            env.AutodetectUploadPort()
            env.TouchSerialPort("$UPLOAD_PORT", 1200)
    if "/arduino_uno/" in str(source[0]):
        if libusb_package.find(idVendor=0x1209, idProduct=0x2882):
            b_request = BOOTLOADER_SERIAL
            id_vendor = 0x1209
            id_product = 0x2883
            exists = libusb_package.find(idProduct=id_product, idVendor=id_vendor)
    before_ports = get_serial_ports()
    if b_request:
        # find our device
        dev = libusb_package.find(idVendor=0x1209, idProduct=0x2882)
        try:
            dev.detach_kernel_driver(0)
        except:
            pass
        try:
            dev.ctrl_transfer(0x21, b_request)
            dev.ctrl_transfer(0x21, 0x09, b_request)
        except:
            pass
    if id_vendor:
        args = {"idVendor": id_vendor}
        if id_product:
            args["idProduct"] = id_product
        
        while not libusb_package.find(**args):
            pass
        if not exists and id_product == 0x2883:
            wait_for_serial = True
    if wait_for_serial:
        env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports))
コード例 #2
0
ファイル: pyusb_backend.py プロジェクト: Shengliang/pyOCD
    def get_all_connected_interfaces():
        """@brief Returns all the connected CMSIS-DAP devices.

        returns an array of PyUSB (Interface) objects
        """
        # find all cmsis-dap devices
        try:
            all_devices = libusb_package.find(find_all=True, custom_match=FindDap())
        except usb.core.NoBackendError:
            if not PyUSB.did_show_no_libusb_warning:
                LOG.warning("CMSIS-DAPv1 probes may not be detected because no libusb library was found.")
                PyUSB.did_show_no_libusb_warning = True
            return []

        # iterate on all devices found
        boards = []
        for board in all_devices:
            new_board = PyUSB()
            new_board.vid = board.idVendor
            new_board.pid = board.idProduct
            new_board.product_name = board.product or f"{board.idProduct:#06x}"
            new_board.vendor_name = board.manufacturer or f"{board.idVendor:#06x}"
            new_board.serial_number = board.serial_number \
                    or generate_device_unique_id(board.idProduct, board.idVendor, board.bus, board.address)
            boards.append(new_board)

        return boards
コード例 #3
0
ファイル: pyusb_backend.py プロジェクト: Shengliang/pyOCD
    def open(self):
        assert self.closed is True

        # Get device handle
        dev = libusb_package.find(custom_match=FindDap(self.serial_number))
        if dev is None:
            raise DAPAccessIntf.DeviceError("Device %s not found" % self.serial_number)

        # get active config
        config = dev.get_active_configuration()

        # Get count of HID interfaces and create the matcher object
        hid_interface_count = len(list(usb.util.find_descriptor(config, find_all=True, bInterfaceClass=USB_CLASS_HID)))
        matcher = MatchCmsisDapv1Interface(hid_interface_count)

        # Get CMSIS-DAPv1 interface
        interface = usb.util.find_descriptor(config, custom_match=matcher)
        if interface is None:
            raise DAPAccessIntf.DeviceError("Device %s has no CMSIS-DAPv1 interface" %
                                            self.serial_number)
        interface_number = interface.bInterfaceNumber

        # Find endpoints
        ep_in, ep_out = None, None
        for endpoint in interface:
            if endpoint.bEndpointAddress & usb.util.ENDPOINT_IN:
                ep_in = endpoint
            else:
                ep_out = endpoint

        # Detach kernel driver
        self.kernel_driver_was_attached = False
        try:
            if dev.is_kernel_driver_active(interface_number):
                LOG.debug("Detaching Kernel Driver of Interface %d from USB device (VID=%04x PID=%04x).", interface_number, dev.idVendor, dev.idProduct)
                dev.detach_kernel_driver(interface_number)
                self.kernel_driver_was_attached = True
        except (NotImplementedError, usb.core.USBError) as e:
            # Some implementations don't don't have kernel attach/detach
            LOG.warning("USB Kernel Driver Detach Failed ([%s] %s). Attached driver may interfere with pyOCD operations.", e.errno, e.strerror)

        # Explicitly claim the interface
        try:
            usb.util.claim_interface(dev, interface_number)
        except usb.core.USBError as exc:
            raise DAPAccessIntf.DeviceError("Unable to open device") from exc

        # Update all class variables if we made it here
        self.ep_out = ep_out
        self.ep_in = ep_in
        self.dev = dev
        self.intf_number = interface_number

        # Start RX thread as the last step
        self.closed = False
        self.start_rx()
コード例 #4
0
ファイル: pyusb_v2_backend.py プロジェクト: Shengliang/pyOCD
    def open(self):
        assert self.closed is True

        # Get device handle
        dev = libusb_package.find(
            custom_match=HasCmsisDapv2Interface(self.serial_number))
        if dev is None:
            raise DAPAccessIntf.DeviceError("Device %s not found" %
                                            self.serial_number)

        # get active config
        config = dev.get_active_configuration()

        # Get CMSIS-DAPv2 interface
        interface = usb.util.find_descriptor(
            config, custom_match=_match_cmsis_dap_v2_interface)
        if interface is None:
            raise DAPAccessIntf.DeviceError(
                "Device %s has no CMSIS-DAPv2 interface" % self.serial_number)
        interface_number = interface.bInterfaceNumber

        # Find endpoints. CMSIS-DAPv2 endpoints are in a fixed order.
        try:
            ep_out = interface.endpoints()[0]
            ep_in = interface.endpoints()[1]
            ep_swo = interface.endpoints()[2] if len(
                interface.endpoints()) > 2 else None
        except IndexError:
            raise DAPAccessIntf.DeviceError(
                "CMSIS-DAPv2 device %s is missing endpoints" %
                self.serial_number)

        # Explicitly claim the interface
        try:
            usb.util.claim_interface(dev, interface_number)
        except usb.core.USBError as exc:
            raise DAPAccessIntf.DeviceError("Unable to open device") from exc

        # Update all class variables if we made it here
        self.ep_out = ep_out
        self.ep_in = ep_in
        self.ep_swo = ep_swo
        self.dev = dev
        self.intf_number = interface_number

        # Start RX thread as the last step
        self.closed = False
        self.start_rx()
コード例 #5
0
ファイル: usb.py プロジェクト: hdscmcu/pyOCD
    def get_all_connected_devices(cls):
        try:
            devices = libusb_package.find(find_all=True,
                                          custom_match=cls._usb_match)
        except usb.core.NoBackendError:
            common.show_no_libusb_warning()
            return []

        assert devices is not None
        intfList = []
        for dev in devices:
            try:
                intf = cls(dev)
                intfList.append(intf)
            except (ValueError, usb.core.USBError, IndexError,
                    NotImplementedError) as error:
                # Ignore errors that can be raised by libusb, just don't add the device to the list.
                pass

        return intfList
コード例 #6
0
ファイル: pyusb_v2_backend.py プロジェクト: Shengliang/pyOCD
    def get_all_connected_interfaces():
        """@brief Returns all the connected devices with a CMSIS-DAPv2 interface."""
        # find all cmsis-dap devices
        try:
            all_devices = libusb_package.find(
                find_all=True, custom_match=HasCmsisDapv2Interface())
        except usb.core.NoBackendError:
            common.show_no_libusb_warning()
            return []

        # iterate on all devices found
        boards = []
        for board in all_devices:
            new_board = PyUSBv2()
            new_board.vid = board.idVendor
            new_board.pid = board.idProduct
            new_board.product_name = board.product or f"{board.idProduct:#06x}"
            new_board.vendor_name = board.manufacturer or f"{board.idVendor:#06x}"
            new_board.serial_number = board.serial_number \
                    or generate_device_unique_id(board.idProduct, board.idVendor, board.bus, board.address)
            boards.append(new_board)

        return boards
コード例 #7
0
def launch_dfu():
    dev = libusb_package.find(idVendor=0x03eb)
    dev.ctrl_transfer(0xA1, 3, 0, 0, 8)
    command = [0x04, 0x03, 0x00]
    dev.ctrl_transfer(0x21, 1, 0, 0, command)
コード例 #8
0
        self.meta = ""


Import("env")
if "upload" in BUILD_TARGETS:
    upload_options = env.BoardConfig().get("upload", {})
    if "detect_frequency" in upload_options and upload_options[
            "detect_frequency"] == "true":
        print("Uploading script to detect speed")
        project_dir = env["PROJECT_DIR"]
        with fs.cd(project_dir):
            config = ProjectConfig.get_instance(
                os.path.join(project_dir, "platformio.ini"))
        config.validate()
        processor = EnvironmentProcessor(Context(), "microdetect", config,
                                         ["upload"], "", False, False, 1)
        processor.process()
        dev = None
        while not dev:
            dev = libusb_package.find(idVendor=0x1209, idProduct=0x2883)
            pass
        sleep(0.5)
        env.AutodetectUploadPort()
        port = env.subst("$UPLOAD_PORT")
        s = Serial(port=port, baudrate=115200)
        rate = f"{s.readline().decode('utf-8').strip()}000000"
        print(rate)
        # rate = usb.util.get_string(dev, dev.iProduct, 0x0409).split("\x00")[0].rpartition(" - ")[2]
        rate = f"{rate}L"
        env["BOARD_F_CPU"] = rate