Main function.

    Args:
      jlink_serial (str): the J-Link serial number
      device (str): the target CPU

    Returns:
      ``None``

    Raises:
      JLinkException: on error

def main(jlink_serial, device):
    """Main function.

    Args:
      jlink_serial (str): the J-Link serial number
      device (str): the target CPU

    Returns:
      ``None``

    Raises:
      JLinkException: on error
    """
    buf = StringIO.StringIO()
    jlink = pylink.JLink(log=buf.write, detailed_log=buf.write)
    jlink.open(serial_no=jlink_serial)

    jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
    jlink.connect(device, verbose=True)

    # Figure out our original endianess first.
    big_endian = jlink.set_little_endian()
    if big_endian:
        jlink.set_big_endian()

    print('Target Endian Mode: %s Endian' % ('Big' if big_endian else 'Little'))