use this (http://svenpeter.blogspot.com/2009/08/pyftdi.html) wrapper for pyftdi
authorBernhard Urban <lewurm@gmx.net>
Sun, 3 Jan 2010 14:44:47 +0000 (15:44 +0100)
committerBernhard Urban <lewurm@gmx.net>
Sun, 3 Jan 2010 14:44:47 +0000 (15:44 +0100)
libftdi
(http://www.intra2net.com/en/developer/libftdi/documentation/functions_func.html)

why?
now we should able to use higher baud rates. however, it is even slower
now. actually i don't know what's the reason for that.

frprog.py
pkernel/uart.c

index 0ca52c57de1fd788e5b06f4af00be107e0549c6d..6e2ae018ee2aaa8a5730630171ac9f20b49d4324 100755 (executable)
--- a/frprog.py
+++ b/frprog.py
@@ -1,15 +1,15 @@
 #!/usr/bin/env python
-import sys, time
-from SerialPort_linux import *
+import sys, time, pyftdi
 
 # serial device to communicate with
-DEVICE="/dev/ttyUSB0"
+DEVICE1=0x0403
+DEVICE2=0x6001
 # baudrate used for initialization
 INIT_BAUDRATE=9600
 # baudrate used for communication with the internal bootloader after init
 BOOTLOADER_BAUDRATE=38400
 # baudrate used for communication with the pkernel program that does the flashing eventually
-KERNEL_BAUDRATE=115200
+KERNEL_BAUDRATE=1000000
 
 # contains the last received checksum from a READ, WRITE or CHECKSUM command
 last_checksum = 0
@@ -20,7 +20,7 @@ class FlashSequence(object):
                self.data = data
 
 def sendByte(byte):
-       tty.write(chr(byte))
+       tty.write_data(chr(byte))
 
 def sendWord(word):
        sendByte(word & 0xFF)
@@ -33,7 +33,10 @@ def sendDWord(dword):
        sendByte((dword >> 24) & 0xFF)
 
 def recvByte():
-       return ord(tty.read())
+       bla = tty.read_data(1)
+       while(len(bla) < 1):
+               bla = tty.read_data(1)
+       return ord(bla)
 
 def recvChecksum():
        global last_checksum
@@ -200,17 +203,20 @@ def main(argv=None):
 
        print "Initializing serial port..."
        global tty
-       tty = SerialPort(DEVICE, 100, INIT_BAUDRATE)
+       tty = pyftdi.FTDI()
+       tty.usb_open(DEVICE1, DEVICE2)
+       tty.set_baudrate(INIT_BAUDRATE)
+       #tty.set_latency_timer(100)
+       #print "latency:", tty.get_latency_timer()
 
        print "Please press RESET on your board..."
 
        while True:
-               tty.write('V')
-               tty.flush()
+               tty.write_data('V')
                try:
-                       if tty.read() == 'F':
+                       if tty.read_data(1) == 'F':
                                break
-               except SerialPortException:
+               except Exception: # hm... thats not true atm :/ no timeout here i think
                        # timeout happened, who cares ;-)
                        pass
 
@@ -221,7 +227,9 @@ def main(argv=None):
        bootromBAUDRATE(BOOTLOADER_BAUDRATE)
        time.sleep(0.1) # just to get sure that the bootloader is really running in new baudrate mode!
        del tty
-       tty = SerialPort(DEVICE, 100, BOOTLOADER_BAUDRATE)
+       tty = pyftdi.FTDI()
+       tty.usb_open(DEVICE1, DEVICE2)
+       tty.set_baudrate(BOOTLOADER_BAUDRATE)
 
        print "Transfering pkernel program to IRAM",
        # let the fun begin!
@@ -232,7 +240,6 @@ def main(argv=None):
                        continue
                #print "RAMing", len(seq.data), "bytes at address", hex(addr)
                bootromWRITE(addr, len(seq.data), seq.data)
-               tty.flush()
                sys.stdout.write(".")
                sys.stdout.flush()
        print
@@ -241,7 +248,9 @@ def main(argv=None):
        bootromCALL(0x30000)
        time.sleep(0.1) # just to get sure that the pkernel is really running!
        del tty
-       tty = SerialPort(DEVICE, None, KERNEL_BAUDRATE)
+       tty = pyftdi.FTDI()
+       tty.usb_open(DEVICE1, DEVICE2)
+       tty.set_baudrate(KERNEL_BAUDRATE)
 
        print "Performing ChipErase..."
        pkernCHIPERASE()
@@ -254,7 +263,6 @@ def main(argv=None):
                        continue
                #print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
                pkernWRITE(seq.address, len(seq.data), seq.data)
-               tty.flush()
                sys.stdout.write(".")
                sys.stdout.flush()
        print
index 53106a6107ed9c8af522bf06d16687bbeec88c6c..10630a6541eb2a5767f6c6d1713ae9262d0eb420 100644 (file)
@@ -3,7 +3,10 @@
 void InitUart4(void)
 {
        // Initialize UART asynchronous mode
-       BGR04 = 138; // 115200 Baud @ 16MHz
+       //BGR04 = 138; // 115200 Baud @ 16MHz
+       //BGR04 = 63; //  250000 Baud @ 16MHz
+       //BGR04 = 31; //  500000 Baud @ 16MHz
+       BGR04 = 15; // 1000000 Baud @ 16MHz
        SCR04 = 0x17; // 8N1
        SMR04 = 0x0d; // enable SOT3, Reset, normal mode
        SSR04 = 0x00; // LSB first