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.
-import sys, time
-from SerialPort_linux import *
+import sys, time, pyftdi
# serial device to communicate with
# serial device to communicate with
+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
# 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
# contains the last received checksum from a READ, WRITE or CHECKSUM command
last_checksum = 0
# contains the last received checksum from a READ, WRITE or CHECKSUM command
last_checksum = 0
self.data = data
def sendByte(byte):
self.data = data
def sendByte(byte):
+ tty.write_data(chr(byte))
def sendWord(word):
sendByte(word & 0xFF)
def sendWord(word):
sendByte(word & 0xFF)
sendByte((dword >> 24) & 0xFF)
def recvByte():
sendByte((dword >> 24) & 0xFF)
def recvByte():
+ bla = tty.read_data(1)
+ while(len(bla) < 1):
+ bla = tty.read_data(1)
+ return ord(bla)
def recvChecksum():
global last_checksum
def recvChecksum():
global last_checksum
print "Initializing serial port..."
global tty
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:
print "Please press RESET on your board..."
while True:
- tty.write('V')
- tty.flush()
+ if tty.read_data(1) == 'F':
- except SerialPortException:
+ except Exception: # hm... thats not true atm :/ no timeout here i think
# timeout happened, who cares ;-)
pass
# timeout happened, who cares ;-)
pass
bootromBAUDRATE(BOOTLOADER_BAUDRATE)
time.sleep(0.1) # just to get sure that the bootloader is really running in new baudrate mode!
del tty
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!
print "Transfering pkernel program to IRAM",
# let the fun begin!
continue
#print "RAMing", len(seq.data), "bytes at address", hex(addr)
bootromWRITE(addr, len(seq.data), seq.data)
continue
#print "RAMing", len(seq.data), "bytes at address", hex(addr)
bootromWRITE(addr, len(seq.data), seq.data)
sys.stdout.write(".")
sys.stdout.flush()
print
sys.stdout.write(".")
sys.stdout.flush()
print
bootromCALL(0x30000)
time.sleep(0.1) # just to get sure that the pkernel is really running!
del tty
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()
print "Performing ChipErase..."
pkernCHIPERASE()
continue
#print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
pkernWRITE(seq.address, len(seq.data), seq.data)
continue
#print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
pkernWRITE(seq.address, len(seq.data), seq.data)
sys.stdout.write(".")
sys.stdout.flush()
print
sys.stdout.write(".")
sys.stdout.flush()
print
void InitUart4(void)
{
// Initialize UART asynchronous mode
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
SCR04 = 0x17; // 8N1
SMR04 = 0x0d; // enable SOT3, Reset, normal mode
SSR04 = 0x00; // LSB first