Here it is everyone, thanks to Collin's tutorial at:
DevDot » Iphone Serial Port Tutorial, I modified it so it actually runs on a 2.2 jailbroken iPhone/iPod Touch. Here are the directions to get 3.3v UART access.
1) Jailbreak your 2.2 iPhone/iPod Touch.
2) Using Cydia, install "OpenSSH".
3) Using Cydia, install the "iPhone 2.0 Toolchain"
4) Ensure SSH is running
5) Using WinSCP, extract the serial folder found
here to anywhere on your phone (ie "/" root).
4) Using Putty or whatever console app you chose, run:
Code:
# ./(install directory)/serial (ie "./serial/serial")
5) That will establish a 9600 N-8-1 serial connection over USB.
UPDATE: You do not need to create the "*" handshake if your using firmware after 1.1, nor do you need to do the strobe hack mentioned in Collin's tutorial.
If you make changes to it, compiling is as simple as:
Code:
# cd /(install directory)/ (ie "cd /serial/")
# make
If my link goes down, here is the serial.c code with minimal comments:
Code:
//////////////////////////////////////////////////////////////////////////
// Iphone Serial I/O demo. see DevDot.wikispaces.com for more info
// ---------------------------------------------------------------------------------------
// By Collin Meyer (TheRain)
// 12-09-2007 revision 1
// Feel free to reuse this code.
//
// Modified by Chris K.
//////////////////////////////////////////////////////////////////////////
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
static struct termios gOriginalTTYAttrs;
static int OpenSerialPort() {
int fileDescriptor = -1;
int handshake;
struct termios options;
fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fileDescriptor != -1) {
if (ioctl(fileDescriptor, TIOCEXCL) != -1) {
if (fcntl(fileDescriptor, F_SETFL, 0) != -1) {
if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) != -1) {
options = gOriginalTTYAttrs;
printf("Current input baud rate is %dn", (int) cfgetispeed(&options));
printf("Current output baud rate is %dn", (int) cfgetospeed(&options));
return fileDescriptor;
} else {
printf("Error getting tty attributes %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
if (fileDescriptor != -1) {
close(fileDescriptor);
}
return -1;
}
} else {
printf("Error clearing O_NONBLOCK %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
if (fileDescriptor != -1) {
close(fileDescriptor);
}
return -1;
}
} else {
printf("Error setting TIOCEXCL on %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
if (fileDescriptor != -1) {
close(fileDescriptor);
}
return -1;
}
} else {
printf("Error opening serial port %s - %s(%d).n", "/dev/tty.iap", strerror(errno), errno);
if (fileDescriptor != -1) {
close(fileDescriptor);
}
return -1;
}
return fileDescriptor;
}
int main(int args, char *argv[]) {
int fd;
char somechar[8];
fd = OpenSerialPort();
if(fd >- 1) {
write(fd,"*",1);
///////////////////////////////////////////////////////////////////////////////////////////////////
// After this, our device or our PC program should be strobing serial ground to gain access to the Iphone Serial Line
//////////////////////////////////////////////////////////////////////////////////////////////////
read(fd,&somechar[0],1);
if(somechar[0]=='*') {
printf("Serial connection established! n");
while(1) {
read(fd,&somechar[0],1);
putchar(somechar[0]);
}
}
}
return 0;
}
...and here is the make file:
Code:
CC=gcc
TARGET=serial
LD=$(CC)
LDFLAGS = -framework CoreFoundation
-framework Foundation
-framework UIKit
-framework CoreGraphics
-lobjc
all: $(TARGET)
$(TARGET): $(TARGET).o
@$(LD) $(LDFLAGS) -o $@ $^
@ldid -S $(TARGET)
clean:
@rm -f *.o $(TARGET)