code: def set_speed(self, speed=None, auto=False, adaptive=False):
          
          if speed is None:
              speed = 0
          elif not util.is_natural(speed):
              raise TypeError('Expected positive number for speed, given %s.' % speed)
          elif speed > self.MAX_JTAG_SPEED:
              raise ValueError('Given speed exceeds max speed of %d.' % self.MAX_JTAG_SPEED)
          elif speed < self.MIN_JTAG_SPEED:
              raise ValueError('Given speed is too slow.  Minimum is %d.' % self.MIN_JTAG_SPEED)
  
          if auto:
              speed = speed | self.AUTO_JTAG_SPEED
  
          if adaptive:
              speed = speed | self.ADAPTIVE_JTAG_SPEED
  
          self._dll.JLINKARM_SetSpeed(speed)
  
          return None
docs: Sets the speed of the JTAG communication with the ARM core.
  
          If no arguments are present, automatically detects speed.
  
          If a ``speed`` is provided, the speed must be no larger than
          ``JLink.MAX_JTAG_SPEED`` and no smaller than ``JLink.MIN_JTAG_SPEED``.
          The given ``speed`` can also not be ``JLink.INVALID_JTAG_SPEED``.
  
          Args:
            self (JLink): the ``JLink`` instance
            speed (int): the speed in kHz to set the communication at
            auto (bool): automatically detect correct speed
            adaptive (bool): select adaptive clocking as JTAG speed
  
          Returns:
            ``None``
  
          Raises:
            TypeError: if given speed is not a natural number.
            ValueError: if given speed is too high, too low, or invalid.