Home
USB HOST CONTROLLER FOR A MICROCONTROLLER
Contents
1. define LED D1 ON LED PORT amp 1 lt lt LED_PIN LED sdefine LED D1 OFF LED PORT 1 lt dED PIN define PROM PT CHECK 2 define PROM PT AND ERROR CHECK 1 define PROM PT OK 1 define FILE NEW 0 define FILE APPEND 1 define TIMEOUT READ WRITE 5 buffer is full define TIMEOUT COMMUNICATION 5 Timeout if no communication has happened 00 Number of read write tests if 82 define FILE BUFFER SIZE 100 Buffer size is at least 100 fimware c ee KKK EK KKK KKK KK KK include firmware h defines macros define VNC BUFFER SIZE 160 Transmit receive buffer size is at least 60 60 struct vnc struc char receive buffer VNC BUFFER SIZE Receive buffer char send buffer VNC BUFFER SIZE Send buffer unsigned char status Status Y struct vnc struc vnc instantiate vnc struc RR RR HR KK AA RR RR RR RR RA A A A A A EK KK KKK HK VNCIL Sending a command Parameter wr cmd command address Return status 0 2command accepted by VNCIL J EARE K KKK K KKK KKK K KKK KK KK KKK K KKK KEKEKE KEK KKK KKK K KEK KEK KE KEE E KEEKEKE EKK EE K unsigned char vnc wr cmd UART c
2. unsigned char vnc wr cmd UART char wr cmd unsigned char offset vnc offset length of command for offset 2strlen wr cmd offset offset while UCSR1A amp 1 lt lt UDRE1 0 UDRI wr cmd wr cmd HH send carrage return a command to monitor ends with OxOD while UCSR1A amp 1 lt lt UDRE1 0 UDR1 0x0D return 0 JJ EE KKK KKK K KKK K KKK KKK K KKK KKE K KE E KE KK K KKK KK K KKK KEEF EKK KKK KKK A A KK K KKK KEE VNCIL Receive a string Wait until the monitor returns info from firmware ex Firmware Version Device Detected Return status 0 string was received from VNCIL J A A K K FK AK AK Ak k K K k A A k K K K K K K K K K K K K K K K K K K KK K K K K K K KK K K K K K K K K K K K K K K K K K K K K K K unsigned char vnc_wait_for_VNC1L_UART char count x 102 Wait for VNC1L to respond with firmware version and message if a device is detected for int z 0 z 44 z wait until a byte has been received while UCSR1A amp 1 lt lt RXC1 0 vnc receive buffer z UDR1 printing in this loop could cause the program to break Il fprintf stdout n r c vnc receive buffer z get the length of the string and it s last character index count strlen vnc receive_buffer 1 for x 0 x count x if vnc receive buffer x r fprintf stdout An vnc receive buffer x fprintf stdout
3. VNCIL Convert hex string to a number Example 11 22 33 44 DA gt 0x44332211 Maximum file length 64 kByte easily expandable to 32 bit Parameter value Address of hex string Return file_length 16 bit 0 error FJ EEKE K KKK RRR HRA KK K EEKE KK KK KK KK OR RR RR E KK KKK A HR KK K KKK KEE unsigned int str_to_int_UART char value unsigned char temp 4 unsigned char position 0 unsigned char nibble 0 unsigned char error 0 unsigned char mid_byte 0 for position 4 position position if value 0 amp amp value 1 value 2 skip 00 if value value 1 skip mid byte 4 temp position 1 20 for nibble 22 nibble nibble if value gt a amp amp value lt f value 2 value 0x20 X Convert to uppercase if value gt A amp amp value lt F value 2 value 0x07 normalize hex based if value lt 0 value gt error 21 error temp position 1 value 0x30 mid byte string to a number subtract 0x30 from gg a character 0 9 mid byte 4 next lower 4 bits out of a byte value44 value if temp 1 0 temp 0 0 error 1 error gt 16 bit if error value 16 20x00 No response necessary via buffer temp 2 20 temp 3 20 89 return temp 2 256 temp 3 RRR RR RR
4. 0x01 GET REPORT 0x09 SET REPORT OxOA SET IDLE 3 Get Report Request Part Description bmRequestType 10100001 bRequest GET_REPORT wValue Report Type and Report ID wIndex Interface wLength Report Length Data Report Excerpted from Device Class Definition for Human Interface Devices HID on page 50 Excerpted from Device Class Definition for Human Interface Devices HID on page 51 34 Valid values for Report Type in the wValue field 01 Input 01 Output 4 Set Report Request Part Description bmRequestType 00100001 bRequest SET REPORT wValue Report Type and Report ID wIndex Interface wLength Report Length Data Report 5 Set Idle Request Part Description bmRequestType 00100001 bRequest SET IDLE wValue Duration and Report ID wIndex Interface wLength 0 zero Data Not applicable 2 Excerpted from Device Class Definition for Human Interface Devices HID on page 52 4 Excerpted from Device Class Definition for Human Interface Devices HID on page 52 35 Appendix B User s Manual 1 Before the microcontroller is powered up a USB device should be connected to the VDIP1 which is powered by Vcc from the M CU board 2 Two jumper pin headers on the VDIP1 need to have two jumpers placed correctly to pull down or pull up the ACBUS5 VNCIL pin 46 and ACBUS6 VNCIL pin 37 depending on which interface is used SPI or UART 3 For the emulated SPI interface differe
5. Check for the presence of VDAP firmware on VNCIL if vnc wait for VDAP vnc error message 20 1 check confirmation Wait until a USB drive is plugged and detected if vnc wait for Device Detected vnc error message 21 2 check confirmation Wait for the first prompt that monitor returns D gt for HID devices do not run prompt check here vnc status vnc prompt check check confirmation if vnc status vnc error message vnc status 3 error message get the length of the string and it s last character index count strlen vnc receive buffer 1 for x count x gt 0 x if vnc receive_buffer x r fprintf stdout An vnc receive_buffer x fprintf stdout c vnc receive_buffer x else fprintf stdout c vnc receive_buffer x if x 0 break run IPA command before running ECS command Monitor commands in ASCII IPA mode 63 vnc status vnc_wr_cmd IPA if vnc status vnc error message 1 5 error command was not accepted by VNC1L vnc status vnc prompt check check if monitor returns prompt if vnc status vnc error message vnc status 5 Extented Command Set vnc status vnc_wr_cmd ECS if vnc status vnc_error_message 1 4 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 4 monitor returns prompt if c
6. VNC1L USB HOST CONTROLLER M ega1284 M aster VNC1L Slave VDAP firmware version 3 68 or 3 69 67 SPI interface VDIP1 J umper Set J3 Pulldown J4 Pullup for SPI include lt avr io h gt include lt string h gt include lt stdio h gt include lt stdlib h gt include lt avr interrupt h gt include util delay h for LCD include uart c UART include Icd lib c LCD include firmware c VNCIL APIs define F CPU 16000000UL timeout value for a task define t1 50 50ms works fine volatile unsigned int time1 timeout counter the task subroutine void task1 void RRR RRR KKK KKK A KK RR RR RR RR RK KK KK A KK KK timer 0 compare ISR ISR TIM ERO COMPA vect Decrement the time if it is not already zero if time120 timel LED PBO LCD PORT C NNC SCLK PA3 SDI PA4 l SDO PA5 l CS PA6 l RS PA7 UART file descriptor putchar and getchar are in uart c FILE uart str ZFDEV SETUP STREAM uart putchar uart getchar FDEV SETUP RW 68 const int8 t LCD initialize PROGM EM LCD Initialized 0 const int8 t LCD VNCIL PROGM EM z VNCIL Test 0 const int8 t LCD megal284 PROGM EM AVR Atmega1284V0 const int8 t LCD success PROGM EM VNC1L success V0 int8 tlcd buffer 17 LCD display buffer volatile int test 16 volatile int pre 0 volatile int pre x 0 volatile int pre y 0 volatile int pre wheel
7. Return status error number 0 OK EREK K KKK KK KKK KK KKR KK KRKK KKK KEEK KKK KE KKK KKK KKK EKEK KK KE KEKEKE KEE KKK KEE KK unsigned char vnc wr binfile char file name char file content unsigned int file length 58 unsigned int vnc i 0 unsigned char wr_steps 0 unsigned char status 0 if file length OXxFFFF return 51 error file is too long do if wr steps 4 return 0 done OK the last prompt character exists switch wr steps write process case 0 Open or create a file sprintf amp vnc send buffer 0 OPW 96s file name if vnc wr cmd vnc send buffer return 1 Error command was not accepted break case 1 Seek offset byte position of 0 in the open file you can also choose other offset if vnc wr cmd SEK 0 return 1 Error command was not accepted break case 2 Write the number of bytes to an open file sprintf amp vnc send buffer 0 WRF 96d file length if vnc wr cmd vnc send buffer return 1 Error command was not accepted No check for buffer limit if necessary expand it for vnc i 20 vnc i file length vnc_i if vnc wr byte file content return 1 Error command was not accepted file content4 break case 3 close file sprintf amp vnc send buffer 0 CLF s file name if vnc wr cmd vnc send buffer return 1 Error command was not accepted break Switch wr_steps next step status vnc_rd_answ
8. UART channel 1 lt gt VNC1L include Icd lib c LCD include firmware c VNCIL APIs define F CPU 16000000UL LED PBO LCD PORTC VNC TX PD3 RX PD4 UART file descriptor putchar and getchar are in uart c FILE uart_str FDEV_SETUP_STREAM uart_putchar uart getchar FDEV SETUP RW const int8 t LCD initialize PROGM EM LCD Initialized VO const int8 t LCD VNCIL PROGM EM z VNCIL Test 0 const int8 t LCD mega1284 PROGM EM AVR Atmega1284 0 const int8 t LCD success PROGM EM VNCI1L success V0 int8 tlcd buffer 17 LCD display buffer Textfile 1 char file1 VNC1L USB Drive test n r 76 It can write to and read from a USB flash drive Anr Text file 1 VNCILVDIP1 n r a a is the EOF end of file VO Y Textfile 2 char file2 Text file 2 n r Another text file to be created n r a Textfile 3 char file3 Text file 3 can be appended to an existing file n r a Bin file char file4 OxFA 0x89 0x11 0xFF 0xAA 0x02 0x00 0x1F 0x1D 0xBA 0xA6 0x24 0x99 0x2D 0x1E 0x1F 0x0D 0x0C 0xA0 0x55 0x30 0x1F 0x16 0xEF 0x04 0x22 0x00 0x00 0xCF 0x12 0x5F OxDF 0x69 0x00 0x00 0x1F 0xEF 0x15 0x3F 0xCF Ox5F 0x44 0x1F 0x1F 0xBF 0x16 0x13 0x7F 0x00 0x10 0x1F 0xDF 0x1F 0x8F 0x16 0xDF Ox1F 0x32 0x3F 0x56 0x1F 0x19 0x17 0xFF Ox3F 0x42 0xFE 0x46 0x6F 0x99 0x10 0xAF Ox6F 0x62 0x36 0x66 0x10 0xAA 0xBB 0xCC Textfile 5 char fi
9. Status bit 0 Accepted 1 Rejected SCLK H SCLK L End sequence CS VNC L SPl Interface inactive SCLK_H SCLK_L count if status delay us 150 Pause if a byte transfer has not be confirmed while status amp amp count fdef USART MONITORING fprintf stdout c wr byte endif ifdef LCD_MONITORING sprintf lcd buffer 965 wr byte LCDGotoXY 0 0 LCDstring lcd buffer strlen Icd_buffer endif return status 0 no error JJ AA KKK KKK KK KK HRA E KEEK KKK KKK A OR RR RK RA A A KKK A AK K KEEKEKE VNC1L 13 Bit SPI receiving a character SPI Mode Parameter rd byte type of read byte 0 Data byte 1 Status byte Store the data byte in the vnc receive buffer of vnc struct variable Return status 0 2new byte in the buffer OK 1 a new byte is not available from VNCIL Ji EREKE KEK KKK KKK KK KK K KKK K KE KK KRKK KEK KK KKK KEK KEKE KKK KE KKK KK KK KKK KK K KKE K kE unsigned char vnc rd spi unsigned char rd byte unsigned char bit_pos data status unsigned int count count TIM EOUT SPI timeout after unsuccessful number of attempts to write do data 0 CS VNC H SPl Interface active 46 SDI H Start bit always 1 SCLK_H SCLK_L falling rising edge SDI H Read Write bit 1 Read SCLK_H SCLK_L if rd byte SDI H else SDI L ADDR 0 Data 1 SPI Status information SCLK H SCLK L receive 8 data bits M SB fi
10. file content4 file length The characters read are now in the buffer and can be evaluated break case 3 close file sprintf amp vnc send buffer 0 CLF s file name if vnc wr cmd vnc send buffer return 1 Error command was not accepted break Switch rd steps44 next step status vnc rd answer PROM PT AND ERROR CHECK while status PROMPT OK Testing for next prompt character gt return status error number while 0 OK Ceeekeleieiereleleielelelelelelelelelelelelelelelererererererererereererelelelelelelelolelelelelelelerelererererererererererererek VNCIL Convert hex string to a number Example 11 22 33 44 D gt gt 0x44332211 Maximum file length 64 kByte easily expandable to 32 bit Parameter value Address of hex string Return file_length 16 bit 0 error RRR RR RR HRA A KK A AA RR OR RR RR RA A A A A A EK KKK AK KK unsigned int str_to_int char value unsigned char temp 4 unsigned char position 0 unsigned char nibble 0 unsigned char error 0 unsigned char mid_byte 0 for position 4 position position 56 if value 0 amp amp value 1 value 422 skip 00 if value value 4 1 skip mid byte 4 temp position 1 20 for nibble 22 nibble nibble if value gt a amp amp value lt f value value 0x20 X Convert to uppercase if value g
11. rd answer count TIM EOUT COMMUNICATION TIMEOUT error abort if necessary reply 0 for status VNC BUFFER SIZE 1 status status vnc receive buffer status 0 clear buffer using status variable while rd answer count not reached timeout limit 1 status vnc rd byte if status new character is now available switch buffer_check case 1 Command Failed if vnc receive buffer 3 i amp amp vnc receive buffer 2 l amp amp vnc receive buffer 1 e amp amp vnc receive buffer 0 d reply 22 Bad Command if vnc receive buffer 3 m amp amp vnc receive buffer 2 a amp amp vnc receive buffer 1 n amp amp vnc receive buffer 0 d reply 23 Disk Full if vnc receive_buffer 3 F amp amp vnc receive buffer 2 u amp amp vnc receive buffer 1 l amp amp vnc receive buffer 0 l reply 24 Invalid Filename 51 if vnc receive buffer 3 a amp amp vnc receive buffer 2 l amp amp vnc receive buffer 1 i amp amp vnc receive buffer 0 d reply 25 Read Only if vnc receive buffer 3 O amp amp vnc receive buffer 2 n amp amp vnc receive buffer 1 l amp amp vnc receive buffer 0 y reply 26 File Open if vnc receive buffer 3 O amp amp vnc receive buffer 2 p amp amp vnc receive buffer 1 e amp amp vnc receive bu
12. return 0 Done OK last prompt character exists switch wr_steps write process case 0 Open or create file sprintf amp vnc send_buffer 0 OPW s file_name if vnc_wr_cmd vnc send_buffer return 1 Error command was not accepted break case 1 Seek offset byte position of 0 in the open file if option new file if vnc wr cmd SEK 0 return 1 Error command was not accepted break else wr steps H skip to case 2 append at the end of existing file case 2 Write the number of bytes to an open file sprintf amp vnc send buffer 0 WRF u file length if vnc wr cmd vnc send buffer return 1 Error command was not accepted file ptr file content for vnc i 20 vnc i file length file CR vnc_i if file ptr hide NULL termination if vnc wr byte file ptr return 1 Error command was not accepted file_ptr break 54 case 3 Close file sprintf amp vnc send buffer 0 CLF 96s file name if vnc wr cmd vnc send buffer return 1 Error command was not accepted break Switch Wr steps 4 next step status vnc rd answer PROM PT AND ERROR CHECK while status PROMPT OK Testing for next prompt character gt return status error number while 0 2OK X Cekeeelekeierelelelelelelelelelelelelelelelelelelererererererererereererelelelelelelelelelelelelelelelerererererererererererererek VNC1L Reading a file of
13. K K K E K KK K K K eee K K K K K K K K K KK K K K K K KKK KK KK KK K unsigned char vnc rd file UART char file name char file content unsigned int file length unsigned char rd steps 0 unsigned char status 0 if file length gt FILE_BUFFER_SIZE 1 return 50 error buffer is too small Open file for reading sprintf amp vnc send buffer 0 OPR s file name status vnc wr cmd UART vnc send buffer status vnc prompt check UART Seek offset byte position of 0 in the open file you can also choose other offset status vnc wr cmd UART SEK 0 status vnc prompt check UART Read the number of bytes from an open file sprintf amp vnc send buffer 0 RDF 96d file length status vnc wr cmd UART vnc send buffer status vnc prompt check UART while file length wait until a byte has been received while UCSR1A amp 1 lt lt RXC1 0 file content UDR1 file content4 file length The characters read are now in the buffer and can be evaluated close file sprintf amp vnc send buffer 0 CLF s file name status vnc wr cmd UART vnc send buffer status vnc prompt check UART return 0 0 2 OK 88
14. KK KKK KKK KK KKK KKK EEE KEE KEKEE E KEEK KEK KK KKK KKK ERE EEEE KEE E EKEK KKK K VNC1L Get USB related info of a device Return 0 Prompt received TEER EKE K KKK K KRKK KRKK K RKKK EE REE E EEE KK KKK KE EEE EKE EE E EEE E EKEK EKEK KRKE EE EEEE unsigned char vnc query device UART void int z count get message from VNC1L and check prompt for z 20 z 135 z wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 hl fprintf stdout n r c vnc receive buffer z count strlen vnc receive_buffer 1 for z 20 z count z for x 20 x count x if vnc receive buffer z r fprintf stdout An vnc receive buffer z fprintf stdout c vnc receive buffer z else fprintf stdout c vnc receive buffer z return 0 J AEREE K KKK K KKK KKK AK K K KK KK EKK KKK K EKK K KKK K KK KKK KREE E KE KKK K KKK KKK KEK KKE KKE VNCIL Get class specific report Return 0 Prompt received S EERE KER KKK K KK KK KRKK KEKEKE KEE E E K E EERE E EEK EE KKK K KK KEKEKE E K RRE E KEEKEKE KEKE unsigned char vnc_get_report_UART char HID_class int z This includes prompt check as well as parsing a report for z 20 z HID class z 106 wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 Il fprintf stdout n r c vnc receive buffer z
15. Left Alt Left Shift Left Ctrl Byte1 Reserved Byte2 Key array 0 Byte3 Key array 1 Byte4 Key array 2 Byte5 Key array 3 Byte6 Key array 4 Byte7 Key array 5 Table 3 USB keyboard input report format 16 Excerpted from AVR271 USB Keyboard Demonstration by Atmel 24 Caps Lock Scroll Lock 5to7 Constant Table 4 USB keyboard output report One thing to be noted is that the keycode Key array elements in a report from a keyboard is not the same as ASCII values of printable characters For example when the key j is pressed the report returns a value OxOD not 0x6A which is an ASCII character value for a lowercase j firmware h files in both projects list key codes for a USB keyboard which is taken from HID Usage Tables More detailed information on USB protocols related to HID devices can be obtained from documents such as Device Class Definition for Human Interface Devices HID and HID Usage Tables on the USB IF website USB HID Device Mouse A USB mouse can be a good choice as an input device for projects that allow users to play games M aking mega1284 a USB host over a USB mouse as a slave was implemented using both SPI and USART interface to the VNC1L and they proved to work well equally For both projects polling a report from a mouse every 50ms using a timer and timer compare ISR worked nicely Other than employing the different types of serial communication interface both projects work the
16. RIGHT SHIFT fprintf stdout in rRight SHIF nr break pre vnc receive buffer FIRST KEY pre special 2vnc receive buffer SPECIAL KEY fimware h define LED PIN 0 define LED PORT PORTB define LED DDR DDRB define RTS DDR DDRA define RTS PORT PORTA define RTS PIN 0 98 define CTS DDR DDRA define CTS PORT PORTA define CTS PIN 1 RRR RRR RR KK KKK KKK K K K K K K K EEK KK K K K K K KK K K K K K K K K KK K K K K KKK k RRR RRR KKK KKK IGlelelelelelelelelelelelololelelololoierererererererererererererejeleleleleleleleleleleleloleleleloiere define LED D1 ON LED PORT amp 1 lt lt LED_PIN LED define LED D1 OFF LED PORT 1 lt dED PIN define PROM PT CHECK 2 define PROM PT AND ERROR CHECK 1 define PROMPT OK 1 define TIMEOUT READ WRITE 5 buffer is full 00 Number of read write tests if define TIM EOUT COMMUNICATION 5 Timeout if no communication has happened define FILE BUFFER SIZE 100 Buffer size is at least 100 define NO KEY PRESSED 0 define KEY CTRL 0x01 define KEY SHIFT 0x02 define KEY ALT 0x04 define KEY GUI 0x08 define KEY LEFT CTRL 0x01 define KEY LEFT SHIFT 0x02 define KEY LEFT ALT 0x04 define KEY LEFT GUI 0x08 define KEY RIGHT CTRL 0x10 define KEY RIGHT SHIFT 0x20 define KEY RIGHT ALT 0x40 define KEY RIGH
17. RR KKK A A A RR RR RR RR RA A A A AK KK KK KKK VNCIL DIR determines file length Maximum 64 kByte Parameters file name Address of file name II file_content Address of the intermediate stores temporary use file length Address of the length of the file to be played back Return 0 OK EAK KK KKK KKK KK KKK K AK K KK KKK EK K K EEE EKK KKK K K KE KEKEKE E EE E EKK KK KK KKK KE KKK KEKE unsigned char vnc rd dir UART char file name unsigned int file length unsigned int file name length unsigned char status 0 unsigned int buff_index 0 char start Address of hex strings beginning int vnc i sprintf amp vnc send buffer 0 DIR s file name status vnc wr cmd UART vnc send buffer status vnc prompt check UART clean up the buffer for int k 20 k 60 k vnc receive buffer k 0 DIR file name command returns two CRs the file name followed by xx xx xx xx CR and a prompt for vnc i 20 vnc i file name length 22 vnc_i file name length 18 4 wait until a byte has been received while UCSR1A amp 1 lt lt RXC1 0 vnc receive buffer vnc i UDR1 Response string to DIR is read char strchr const char s int c it locates the first occurrence of c in the string pointed to by s II it returns a pointer to the byte or a null pointer if the byte was not found 90 start strchr vnc receive_buffer find the index of the f
18. VU OA Ur 21 USB HID Device Keyboard sn 23 USB HID Device MOUSE isis edd Xo GRO D D AU CHR HURQC RO RD AERE OHLEQA EPOR 25 Results meeec TET 26 Concl slofiS si Dru a vis Eig Aie i i E a A Ga KC DB EN RR C CO DR ri 30 References cionepdddispno rad dau eU ER DU Fd VM a CO Cri CALO D EMEN UND CARNEGIE 31 Appendix A USB Device Requests vincris kis diiit aio eo cnc Ro x PR C nc E E 33 Appendix B User s Manual oii co ci cni a e e d C ccr D C Ev en 36 Appendix CeCodB a tins ia Rica uE Ex ER MGE A EIRETM NC EE ERE TL uS ERE EIN HU UR AR CTI ELXNU EA NR EI RET 37 Introduction ECE 4760 class teaches students how to design various digital systems using Atmel AVR ATmega microcontrollers such as M ega1284 A prototype board that has a type B USB connector for serial communication is loaned to students at the beginning of the class This allows students to have the USB connection for serial communication between their running program and the PC that runs PuTTY for debugging and taking user inputs for their programs In this configuration the PC is a USB host and the microcontroller takes the role of a slave device For their final projects students in ECE 4760 class design and produce hardware and software combined systems that could require many different kinds of user interfaces Previously students used items such as push buttons keypads microphones and light detecting phototransistors Although these items worked quite well as user input devices
19. any of Shift Ctrl or Alt keys is pressed as shown in Table 3 However all projects created for a USB keyboard check only the Key array 0 in Byte 2 and this works well with the polling method In other words it does not miss a keystroke and also it does not read the same keystroke twice when a user types at a fast pace Although not all devices support set report requests when it is sent by the M CU through SSU it can turn on one of three LEDs on a keyboard The bitmap of an OUT report is tabularized in Table 4 6 Bytes 1 Byte 1 Byte Reserved Modifier Report IN Keycode 1 6 for OEM 1 Byte Leds Figure 13 USB keyboard report structure A USB keyboard must send a report to a host whenever it receives a get_report request or at a set idle rate regardless of no changes in the key codes Although Device Class Definition for Human Interface Devices HID document states that the recommended default idle rate for keyboards is 500ms in this setting many keystrokes are missed Thus the duration of the wValue field in the set idle request for this project is set to indefinite which means that only when there is a change in the report data a new report can be sent to a host In this setting whenever the M CU polls a report every 50ms using the SSU command the keyboard sends out a report Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 Byte0 Right GUI Right Alt Right Shift Right Ctrl Left GUI
20. be asserted low to choose an active slave device Master Slave SCLK SPI MOSI Lo x 2 s ls el7 Lo x 2 sj 4 s el 7 Master MISO SS Figure 7 Buses between a host and a slave and hardware setup for SPI Four I O pins on VNC1L are used for SPI SCLK SPI clock input SDI SPI serial data input SDO SPI serial data output and CS SPI chip select input The timings of a read operation and a write operation of VNCIL are illustrated in the next two figures First during the entire read or write cycle CS must be held high Once the operation is over CS must be pulled low for at least one clock period after the transaction is completed The first bit on SDI is the write read bit where a 1 is for read from VNCIL and a 0 is for write to VNC1L The second bit on SDI is the address bit where a 1 meansthat the status register will be read from or be written to and a 0 means that the data register will be read from or be written to During the read cycle a byte of data is output on SDO with M SB most significant bit first During the write cycle a byte of data is input to SDI with M SB first The last status bit on SDO for the read cycle is set to a 1 to indicate that the data read is old data and a 0 for new data The last status bit on SDO for the write cycle is set to a 0 to indicate that the data write was accepted and a 1 to indicate that the internal buffer is full and the write operation must be
21. device uses a USB transfer to send and receive data for communication Each transfer has a defined format for sending data status and control information and more There are four types of USB transfers control bulk interrupt and isochronous transfers All USB 7 devices must support control transfer which is used for identification and configuration of a device USB devices such as USB flash drives and printers use bulk transfer that does not guarantee latency while HID devices such as USB keyboards and USB mice use interrupt transfer that does guarantee low latency Except for control transfer interrupt transfer is the only way low speed devices such as a USB mouse can transfer data Important elements of a USB transfer are called endpoints and there is a pair of endpoints IN and OUT Once a transfer is scheduled all data on a USB bus travels to or from a device endpoint Simply put endpoints are buffers that store bytes which are received or waiting to be transmitted While a host device has buffers to hold received data and data waiting to be transmitted only a slave device has device endpoints Before any data can be exchanged between a host and a slave they must establish a pipe A pipe connects endpoints of a device to a host Any transfer type is allowed to use IN and OUT transactions Enumeration Once a USB slave device is connected to a USB host the host needs to learn about the device before any application can communicate wit
22. modes Extended mode and Short mode In the extended mode commands are entered using printable characters such as a string of alphabet letters plus numerical numbers In the short mode commands are entered using binary values expressed in hexadecimal numbers For example DSD 10 01 02 03 04 05 06 07 08 09 0a and Excerpted from Vinculum Firmware M anual on page 66 Figure 8 2 Excerpted from Vinculum Firmware M anual on page 14 Figure 4 1 13 83 20 0a 0d 01 02 03 04 05 06 07 08 09 0a are the same command Device Send Data with the data size 10 in ASCII M ode for the first case and in Binary M ode for the latter The data to be sent 01 02 03 04 05 06 07 08 09 0a is in binary values for both cases and Od represent a carriage return CR There are also two numerical modes available for monitor commands as shown in the example above They are independent of a selected command set either extended or short ASCII M ode can be invoked by the command IPA and Binary M ode can be set by the command IPH The ASCII mode uses printable characters while the binary mode uses binary values In the ASCII mode unless a number starts with a prefix or 0x which represent hexadecimal values a number parameter data to accompany a command is assumed to be decimal An important thing to be noted is that all outputs from the monitor are LSB first regardless of which numerical mode it is in Essential Monitor Commands The Fir
23. nclude uart1 c UART channel 1 VNCIL include Icd lib c LCD include firmware c VNCIL APIs 92 define F CPU 16000000UL define KEYBOARD 22 define FIRST KEY 12 define SPECIAL KEY 10 timeout value for a task define t1 50 50ms works fine LED PBO LCD PORT C VNC TX PD3 l RX PD4 UART file descriptor putchar and getchar are in uart c FILE uart_str FDEV_SETUP_STREAM uart_putchar uart getchar FDEV SETUP RW const int8 t LCD initialize PROGM EM LCD Initialized 0 const int8 t LCD VNCIL PROGM EM z VNCIL Test 0 const int8 t LCD mega1284 PROGM EM AVR Atmega1284V0 const int8 t LCD success PROGM EM VNCI1L success V0 int8 tlcd buffer 17 LCD display buffer volatile unsigned int time1 timeout counter volatile int pre 20 previous key stroke volatile int pre special 20 previous SHIFT CONTROL key stroke the task subroutine void task1 void RRR RRR KR KK RK KRKK KK KK KK RR RR RR ERK KK KKK KK KK timer 0 compare ISR ISR TIM ERO COMPA vect Decrement the time if it is not already zero if time120 timel RRR RRR RRR KK RK KR RRR RR RR RR RK KK KK KKE K KKK LCD setup void init Icd void 93 LCDinit initialize the display LCDcursorOFF LCDclr clear the display LCDGotoXY 0 0 CopyStringtoLCD LCD initialize 0 0 system initialization void init_system void LED for debugging
24. optional Data follow on data Table 2 Monitor Command Set There are a few important facts to be noted for a successful execution of monitor commands e Before writing to a file or reading from a file the file has to be open by OPW or OPR After writing to a file or reading from a file the file has to be closed by CLF e Before using RDF to read from a file DIR file command should be executed first to find out the size of the file to be read e Before using SSU to set or get report of a HID device SC with a device number should be executed first to set the device as a current device so that all output from SSU can be routed to that device For more detailed descriptions on functions of any of those commands or error messages that the monitor returns when a command fails to execute Vinculum Firmware M anual offers examples on how they can be used Serial Communications VNCIL provides configuration options to interface to the Command Monitor via UART SPI or FIFO When the data and control buses of VNC1L are configured in the UART mode the interface implements an asynchronous serial UART port with flow control When the buses are configured in the SPI mode the interface operates as an SPI slave and thus it will need a master to provide the clock In this project both SPI and USART are employed for the serial communication between the microcontroller host mega1284 and the VNCIL on the VDIP1 which is connected to a USB slave
25. project proposal The final working products of the project indicate that this was a successful project overall The first half of the main bulk of the project development time was spent on researches and studies on the extensive USB protocols The second half of the development time was spent on coding the APIs in the libraries and debugging them Although FTDI the manufacture of VNCIL and VDIP1 claims that VNCIL provides a ready to use USB interfacing solution and their development module for VCN1L is ideal for rapid prototyping and development of VNCIL designs which is true to a certain extent learning about and understanding functions of its firmware and the monitor commands was not an easy task It was rather a somewhat time consuming process because it turned out that much more knowledge on the USB protocols than recognizing a few technical vocabulary from the protocols is required to use the firmware commands correctly Not all USB HID devices responded the way USB specification documents from the USB IF explained Despite the challenges throughout the process of the project development time this project has been an interesting and exciting one all along with the good results at the end 30 References Books 1 Axelson Jan USB Complete The Developer s Guide Madison Lakeview Research LLC 2009 Print 2 Axelson Jan USB Mass Storage Designing and Programming Devices and Embedded Hosts M adison Lakeview Research
26. rLeft click else if test 10 2 fprintf stdout n rRight click else if test 10 4 fprintf stdout n rWheel else ll fprintf stdout n rNo movement n r if pre_x test 11 amp amp test 11 0 X coordinate fprintf stdout n rX d test 11 if pre_y test 12 amp amp test 12 20 Y coordinate fprintf stdout n rY d test 12 if pre_wheel test 13 amp amp test 13 0 wheel rotation 1 pre test 10 pre x test 11 pre y test 12 pre wheel test 13 fprintf stdout n rWheel d test 13 4 VNCIL USB drive UART Original project by Matthias Kahnt az51 gmx net Modified by Terry Young Kim ATmegal1284 VNC1L VDIP1 Vinculum Port2 75 VNC1L USB HOST CONTROLLER M ega1284 M aster VNCIL Slave VDAP firmware version 3 69 USART interface VDIP1 Jumper Set J3 Pullup J4 Pullup for UART VNC1L connect CTS AD3 to ground pull down low or connect CTS AD3 and RTS AD2 WARNING if the prompt check is carried out properly the program will hang A file name must be at least two characters long otherwise vnc rd dir UART won t work include avr io h include lt string h gt include lt stdio h gt include lt stdlib h gt include lt avr interrupt h gt include util delay h for LCD include uart c UART channel 0 gt PuTTy include uart1 c
27. repeated Copied from Wikipedia on Serial Peripheral Interface Bus 16 R W ADD D7 De D5 D4 D3 D2 D1 SPICLK vannin SPI CS TAE ENNNENE SPI Data In ft fi ar SPI Data Out Start Status Figure 8 SPI Slave Data Read Cycle R W ADD D7 De DS D4 D3 D2 D1 DO p Po N Tobai SPI CS SPI Data In SPI Data Out Start Status Figure 9 SPI Slave Data Write Cycle M ega1284 allows four port pins to be configured as SCLK Port B7 MISO Port B6 MOSI Port B5 and SS Port B4 for SPI and provides corresponding registers However in this project five pins on Port A are used to emulate the SPI interface Port A3 SCLK Port A4 SDI from VDIP1 Port A5 SDO from VDIP1 Port A6 CS equivalent to SS and Port A7 RE The difference between using SPI pins on Port B with the data and control registers for SPI and emulating the SPI interface is that Port A3 for the clock must be pulled up and down manually every time a host M CU wants to transmit any data to a slave VNCIL when in emulation The benefit of using the SPI mode is that both USART channels on megal1284 are freed to be used for other purposes V Excerpted from VDIP1 datasheet on page 9 1 Excerpted from VDIP1 datasheet on page 10 17 Two three way jumper pin headers on the VDIP1 module should be correctly configured for SPI interface The red lines next to J3 and J4 in the figure below show how the jumpers sh
28. status 8 monitor returns prompt if command executed correctly count strlen vnc receive_buffer 1 for x count x gt 0 x if vnc receive_buffer x r fprintf stdout An vnc receive_buffer x fprintf stdout c vnc receive_buffer x else fprintf stdout c vnc receive_buffer x if x 0 break Set current device vnc status vnc_wr_cmd SC 0 if vnc status vnc_error_message 1 9 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 9 monitor returns prompt if command executed correctly 65 fprintf stdout n r s n r vnc receive buffer Device Send Setup Data Set Idle vnc status vnc wr cmd SSU 210A000000000000 no interrupt transfer unless there is a change in the keycode 210A007D00000000 gt interrupt transfer every 500ms 500ms 4ms 0x7D if vnc status vnc_error_message 1 120 vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 120 CopystringtoLCD LCD_success 0 1 start at char 0 line fprintf stdout n rStart polling n r If you reached here then no error has occured LED blinks every second main task scheduler loop while 1 reset time and call task if time1 90 time1x1 task1 LED D1 ON delay ms 1000 1 sec LED D
29. the firmware installed on a VNCIL You can download the ROM programmer tool and the ROM files from FTDI website and program the chip via a PC serial port or an FT232 FT245 or ft2232 device This is demonstrated in the next figure only as a reference in case students use only a VNCIL chip instead of a VDIP1 or VDIP2 module The easiest way to upgrade the firmware on a VNCIL on a development module is to use a USB flash drive First download the latest firmware version from FTDI website and save it in a USB flash drive You must change the Excerpted from VDIP1 datasheet on page 17 Figure 6 1 11 name of the file to FTRFB FTD before you insert the drive to the USB connector Port 2 on a development module M ake sure that the file is saved in the root directory Once the VNC1L detects the USB drive it will check and verify the format of the firmware upgrade file and automatically upgrade the firmware for you This project employs the latest version of the firmware 3 69 VCC3V3 Figure 4 How to program VNCIL using a USB serial converter There are six types of firmware available for VNC1L This project uses VDAP firmware which is for the most general purpose and supports most USB devices on Port 1 and Port 2 With this firmware both HID devices and mass storage devices BOM S Bulk Only M ass Storage can be connected to Port 2 on a VDIP1 Command Monitor The way to control and communicate with the VNC1L is through a comm
30. vnc_error_message 1 120 vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 120 CopyStringtoLCD LCD success 0 1 fprintf stdout A n rStart polling n r If you reached here then no error has occured LED blinks every second main task scheduler loop while 1 reset time and call task if timel1 0 time1 t1 task1 LED D1 ON delay ms 1000 1 sec LED D1 OFF delay ms 1000 RRR RR KK KKK RK KKK KK KK KKK Task subroutine Task 1 void task1 void Device Send Setup Data Get Report vnc status vnc_wr_cmd_UART SSU A101000100000800 monitor returns 8 bytes if vnc status vnc_error_message 1 12 vnc status vnc_get_report_UART KEYBOARD 97 only a new key press will be printed here only one key press is checked but you can check 5 more presses if pre 2vnc receive buffer FIRST KEY amp amp vnc receive buffer FIRST KEY NO KEY PRESSED fprintf stdout c print keystoke vnc receive buffer FIRST KEY if pre special 2vnc receive buffer SPECIAL KEY amp amp vnc receive buffer SPECIAL KEY 2NO KEY PRESSED switch vnc receive_buffer SPECIAL_KEY case KEY LEFT CTRL fprintf stdout n rLeft CTRL n r break case KEY LEFT SHIFT fprintf stdout n rLeft SHIFT n r break case KEY RIGHT CTRL fprintf stdout n rRight CTRL n r break case KEY
31. void init_system void LED for debugging LED DDR 1 lt lt LED PIN output LED_D1_OFF turn off LED VNCIL SPI interface setup SPI DDR 1 lt lt SCLK_PIN 1 lt lt SDI_ PIN 1 CS PIN 1 RE PIN outputs SPI DDR amp 2 1 SDO PIN input init the UART uart init is in uart c uart_init stdout stdin stderr amp uart str fprintf stdout n r Starting VNC1L USB drive test n r RRR RR RR HR KK A AAR RR RR RR RA A A A A A EK KKK KK KK List of errors RRR RR ARR RR RR RR RR EK KK A A OR RK RK RR KR KE KKK KKK II 1 Command was not accepted by VNCIL ll 2 Command Failed Il 3 Bad Command Il 4 Disk Full ll 5 Filename Invalid Il 6 Read Only II 7 File Open 8 Directory Not Empty Il 9 No Disk ll 20 No VNCIL with VDAP firmware available II 21 No USB drive plugged II 50 Buffer is too small to read a file buffer overflow i 51 File length 0 or gt 64kByte II 99 Timeout RRR RR RR RR HR KK KA A A RR RR RK RA A A A A KK KK KK KK 39 void vnc error message unsigned char error type unsigned char error num LED D1 ON LEDturns on if there s an error fprintf stdout n rError type d Error number d n r error type error num error occured while 1 error keeps the system hanging RRR RR KKK KK KEK A K KE KKK RR OR OR OR RR RE EE EE EE EEK KK KK Main program RR RR KKK KK E K EEE KKK KKK KK K
32. 0 RRR RRR RR KR KK KKK RR RRR KK KK RK EE EEK KK KKK KKK KKK KKK K KKK LCD setup void init Icd void LCDinit initialize the display LCDcursorOFF LCDclr clear the display LCDGotoXY 0 0 CopyStringtoLCD LCD initialize 0 0 system initialization void init_system void LED for debugging LED DDR 1 lt lt LED PIN output LED_D1_OFF turn off LED VNC1L SPI interface setup SPI DDR 1 lt lt SCLK_PIN 1 SDI PIN 1 CS PIN 1 RE PIN outputs SP DDR amp 1 SDO PIN input init the UART uart init is in uart c uart init stdout stdin stderr amp uart str fprintf stdout A nV Starting VNCIL USB mouse test n r crank up the ISRs sei 69 RR RR RR OR AR RR A EK A EE KR A KK KR EK KE List of errors TJ EEEE RK K KRKK KRKK KRKK KRKK K EEKE KK A AK OR E EEE RA A A A KK E EEEE E 1 Command was not accepted by VNCIL II 2 Command Failed II 3 Bad Command 4 Disk Full ll 5 Filename Invalid Il 6 Read Only II 7 File Open Il 8 Directory Not Empty Il 9 No Disk ll 20 No VNCIL with VDAP firmware available II 21 No USB drive plugged II 50 Buffer is too small to read a file buffer overflow II 51 File length 0 or gt 64kByte II 99 Timeout RRR RR RR HRA A KA A A A RR OR RR RR RA A A A EK KKK AK KK void vnc_error_message unsigned char error_type unsigned char error_num L
33. 1 OFF delay ms 1000 Task subroutine Task 1 void task1 void Device Send Setup Data Get Report vnc status vnc_wr_cmd SSU A101000100000800 monitor returns 8 bytes if vnc status vnc error message 1 12 for int t20 t 23 t this includes prompt check as well as a report vnc rd spi 0 test t int vnc receive_buffer 0 66 II fprintf stdout n d test t fprintf stdout n c vnc receive buffer 0 only one key press is checked here but you can check 5 more key presses if pre test 12 amp amp test 12 NO_KEY_PRESSED fprintf stdout c print_keystoke test 12 if pre_ special test 10 amp amp test 10 0 switch test 10 case KEY LEFT CTRL fprintf stdout n rLeft CTRL n r break case KEY LEFT SHIFT fprintf stdout n rLeft SHIFT n r break case KEY RIGHT CTRL fprintf stdout n rRight CTRL n r break case KEY RIGHT SHIFT fprintf stdout in rRight SHIF nr break pre test 12 pre special test 10 3 VNCIL mouse SPI polling HK KK KK AKAKAKKKKKAK YNC1L mouse c Original project by Matthias Kahnt az51 gmx net Modified by Terry Young Kim ATmegal1284 VNC1L VDIP1 Vinculum Port2
34. 2 10 Button left Button right Byte 3 Byte 2 Byte 1 Byte 0 s Wheel Y X The mouse pointer position Button middle Figure 14 USB mouse report structure Results Implementing a USB host interface to M ega1284 using the VNCIL on a VDIP1 module was successful Overall eight project files were created to demonstrate how the host M CU can communicate with a USB device through the command monitor by calling APIs that send out firmware commands to the monitor and also parse and process data that a USB device sends to the host This certainly unloads the host mega1284 For each type of devices a USB flash drive a USB keyboard and a USB mouse a library of API functions was created Also each kind of the libraries was implemented twice one using SPI and the other in USART interface The list of the projects files that are provided with this report is as followings e VNCIL USB drive SPI e VNCIL keyboard SPI polling e VNC1L mouse SPI polling e VNC1L_USB drive UART e VNCIL keyboard UART polling e VNCIL mouse UART polling e VNC1L keyboard UART data e VNC1L mouse UART data 26 As mentioned in the earlier section VNC1L USB drive project is based on Kahnt s original project and only minor changes are made to it However VNC1L USB drive project demonstrates that not only a hard coded string buffer but also a string of characters that is input by a user in real time can be saved in a new file or be appen
35. 4 error command was not accepted by VNC1L vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 4 monitor returns prompt if command executed correctly Display firmware version vnc status vnc wr cmd UART FWV if vnc status vnc error message 1 6 error command was not accepted by VNCIL print firmware version returned by VNC1L and prompt check vnc status vnc firmware UART Query port 2 for HID vnc status vnc wr cmd UART QP2 if vnc status vnc error message 1 7 error command was not accepted by VNC1L print device class and prompt check vnc status vnc query port UART Query Device vnc status vnc wr cmd UART QD 0 if vnc status vnc error message 1 8 error command was not accepted by VNC1L vnc status vnc query device UART Set current device vnc status vnc wr cmd UART SC 0 96 if vnc status vnc error message 1 9 error command was not accepted by VNCIL vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 9 monitor returns prompt if command executed correctly Device Send Setup Data Set Idle vnc status vnc wr cmd UART SSU 210A000000000000 no interrupt transfer unless there is a change in the keycode 210A007D00000000 gt interrupt transfer every 500ms 500ms 4ms 0x7D if vnc status
36. 6 define KEY_END 77 define KEY_PAGE DOWN 78 define KEY_RIGHT 79 define KEY_LEFT 80 define KEY DOWN 81 define KEY_UP 82 define KEY NUM LOCK 83 define KEYPAD_ SLASH 84 define KEYPAD_ASTERIX 85 define KEYPAD MINUS 86 define KEYPAD PLUS 87 define KEYPAD ENTER 88 define KEYPAD 1 89 define KEYPAD 2 90 define KEYPAD 3 91 define KEYPAD 4 92 define KEYPAD 5 93 define KEYPAD 6 94 define KEYPAD 7 95 define KEYPAD 8 96 define KEYPAD 9 97 define KEYPAD 0 98 define KEYPAD PERIOD 99 fimware c KKK R KEK KKK KK KKK KK 101 include firmware h defines macros define VNC BUFFER SIZE 160 Transmit receive buffer size is at least 60 11 HAAA AVAVA AVAVA AAAA 60 struct vnc struc char receive buffer VNC BUFFER SIZE Receive buffer char send buffer VNC BUFFER SIZET Send buffer unsigned char status Status Y struct vnc struc vnc instantiate vnc struc V eeeelekeieielelelelelelelelelelelelelelelelererererererererererereerererelelelelololelelelelelelelelerererererererererererereek VNC1L Sending a command Parameter wr cmd command address Return status 0 2command accepted by VNCIL
37. 7 int8 tlcd buffer 17 LCD display buffer volatile char my text 50 volatile char my str 50 volatile char read str 50 RRR RRR KK RK KR KK KK K K K K K K K KK K K K K K K K K K K K K K K K K K LCD setup void init Icd void LCDinit initialize the display LCDcursorOFF LCDclr clear the display LCDGotoXY 0 0 CopyStringtoLCD LCD initialize 0 0 Textfile 1 char file1 VNCILUSB Drive test n r It can write to and read from a USB flash drive n r Text file 1 VNC1L VDIP1 n r a a is the EOF end of file Textfile 2 char file2 Text file 2 n r Another text file to be created n r a Textfile 3 char file3 Text file 3 can be appended to an existing file n r a Bin file char file4 OxFA 0x89 0x11 0xFF 0xAA 0x02 0x00 0x1F 0x1D 0xBA 0xA6 0x24 0x99 0x2D 0x1E 0x1F 0x0D 0x0C 0xA0 0x55 0x30 0x1F 0x16 0xEF 0x04 0x22 0x00 0x00 0xCF 0x12 0x5F 0xDF 0x69 0x00 0x00 0x1F 0xEF 0x15 0x3F 0xCF Ox5F 0x44 0x1F 0x1F 0xBF 0x16 0x13 0x7F 0x00 0x10 0x1F 0xDF 0x1F 0x8F 0x16 0xDF Ox1F 0x32 0x3F 0x56 0x1F 0x19 0x17 0xFF Ox3F 0x42 0xFE 0x46 0x6F 0x99 0x10 0xAF 38 0x6F 0x62 0x36 0x66 0x10 0xAA 0xBB 0xCC 5 Textfile 5 char file5 M acGyver left the building He ain t coming back n r a Y char file buffer FILE BUFFER SIZE buffer for testing unsigned int file length byte length of a file for reading system initialization
38. CIL However after learning about Atmel mega1284 and studying its datasheet students in ECE 4760 do not have to repeat the same time consuming process with a VNCIL if they choose to use it for their final projects It is recommended that they read about basics of USB protocols that are explained in the previous section and learn how to use key commands for the firmware that a VCN1L is programmed with The details on Vinculum Firmware will be explained in the next section Figure 2 VDIP1 left and VDIP2 right with VNC1L Above are the pictures of two development modules of VNC1L They are both under 25 which serves well the budget constraint for a final project in ECE 4760 class The size of VDIP2 is 64 8mm by 17 78mm with the height of 25mm Their compact size and relatively light weight will work well with any final project designs Only different between the two modules is that VDIP2 comes with two USB A type receptacles while VDIP1 comes with only one that is connected to the USB Port 2 of a VNCIL With VDAP firmware which is used for this project both HID devices and mass storage devices a USB memory stick can be connected to USB Port 2 and be supported Therefore this project uses a VDIP1 Mass storage devices can be connected only to Port 2 with VDAP firmware and it should not be connected to Port 1 on a VDIP2 HID devices connected to Port 1 on VDIP2 proved to work well Although VDIP1 has only one USB type A receptacle it has t
39. ED sdefine LED D1 OFF LED PORT 1 lt dED PIN define SCLK L SP PORT amp 1 SClK PIN SCLK VNCIL sdefine SCLK H SP PORT 1 lt lt SCLK_PIN define SDI L SP PORT amp 1 SDI PIN SDI VNCIL sdefine SDI H SP PORT 1 SDI PIN define SDO_VNC SPI PIN amp 1 lt lt PD5 SDO VNCIL define CS VNC L SPI PORT amp 1 CS PIN CS VNCIL define CS VNC H SPI PORT 1 lt lt CS PIN define RE VNCL SPI PORT amp 1 RE PIN RS VNCIL define RE VNC H SPI PORT L RE PIN define PROM PT CHECK 2 define PROM PT AND ERROR CHECK 1 define PROM PT OK 1 define FILE NEW 0 define FILE APPEND 1 define TIM EOUT SPI 50 Number of SPI read write tests define TIMEOUT READ WRITE 500 Number of read write tests if buffer is full define TIMEOUT_COMMUNICATION 5 Timeout if no communication has happened define FILE BUFFER_SIZE 100 Buffer size is at least 100 FMW are C FERRE KKK KKK KK KK include firmware h defines macros define VNC BUFFER SIZE 60 Transmit receive buffer size is at least 60 struct vnc struc char receive buffer VNC BUFFER SIZE Receive buffer char send buffer VNC BUFFER SIZE Send buffer unsigned char status Status Y 44 struct vnc struc vnc instantiate vnc struc int8_t Icd_buffer 17 LCD display buffer iJ AAR KKK KKK
40. ED D1 ON LED turns on if there s an error fprintf stdout n rError type d Error number d n r error type error num error occured while 1 error keeps the system hanging RRR RR K K K K K AKK E K A A KEK KK K KKK K K EK K KKE KE K OR OR RE EE EEE EEK KK KK Main program EAK KK KKK KKK K KKK KKK K KK KK KE EE KKE EE KKK K KKK K K K KEK KKE KEE E EKK KK KK KEKEKE KEEF int main void init_system start the LCD init Icd LCDclr initialize VNCIL vnc_init set up timer 0 for 1 mSec timebase 70 TIM SKO 1 lt lt OCIEOA turn on timer 0 cmp match ISR OCROA 249 set the compare reg to 250 time ticks set prescalar to divide by 64 TCCROB 3 turn on clear on match TCCROA 1 lt lt WGM 01 put some stuff on LCD CopyStringtoLCD LCD VNCLL 0 0 start at char 0 line 0 CopyStringtoLCD LCD mega1284 0 1 start at char 0 line 1 char count x Check for the presence of VDAP firmware on VNCIL if vnc_wait_for VDAP vnc_error_message 20 1 check confirmation Wait until a USB drive is plugged and detected if vnc wait for Device Detected vnc error message 21 2 check confirmation Wait for the first prompt that monitor returns D gt for HID devices do not run prompt check here vnc status vnc prompt check check confirmation if vnc status vnc error message vnc status 3 error message get the length of the s
41. EREK K KKK K KKK KKK KK K KKK KKE KE KRKE KE K KKK A A RR RR RR RR RR RA A A A A EK KK KKK KE void vnc error message unsigned char error type unsigned char error num 111 LED D1 ON LED turns on if there s an error fprintf stdout n rError type d Error number d n r error type error num error occured while 1 error keeps the system hanging II KKK K KKK K K K KK K K K KK K K K KK KK K K KEK K K K KK K K K K K KK K K KK K K KK K K KKK K KK K K KKK KKK K K K K Main program II KKK KKK KK K KKK K K KKK K K K KK KK K K K K K K K KK K K K K K KK K K KK K K K KKK K KKK K K K K KKK KKK K K K K int main void init_system start the LCD init Icd LCDclr set up timer 0 for 1 mSec timebase TIM SKO 1 lt lt OCIEOA turn on timer 0 cmp match ISR OCROA 249 set the compare reg to 250 time ticks set prescalar to divide by 64 TCCROB 3 turn on clear on match TCCROA 1 lt lt WGM 01 crank up the ISRs sei put some stuff on LCD CopyStringtoLCD LCD VNCLL 0 0 start at char 0 line 0 CopyStringtoLCD LCD mega1284 0 1 start at char 0 line 1 To print what monitor returns fprintf stdout n r s n r vnc receive buffer note All output from the command monitor is LSB first If monitor return multiple lines of data they are followed by carriage return which overwrites a previous line on fprintf Wait for VNC1L to respond with firmware version a
42. ERROR CHECK if status PROMPT OK Response string is now in the buffer the last character at the forefront for buff index VNC BUFFER SIZE buff index buff index file content 2vnc receive buffer buff index 1 flip the buffer content if file content file content avoid string end identifier 0x00 file content4 flle content 20x00 put string end identifier file content VNC BUFFER SIZE 2 Buffer set to start back Response string is now in the receive buffer example VNCFILE2 TXT 52 00 00 00 D gt char strchr const char s int c it locates the first occurrence of c in the string pointed to by s II it returns a pointer to the byte or a null pointer if the byte was not found start strchr file_content find the index of the first occurance of starting from LSB file length str_to_int start convert hex string to a number currently up to 64 kByte if file_length return 51 error file is too long or has length of 0 return 0 Ok valid file length return status error number while 0 OK IERE KKK K KKK KK K KK K K KAKKA K KKK KE KKK KKK K KK KKK KREE E KE KKK KKK KK KK KE K KEKEE KE VNC1L Generating a binary file on a USB drive It can also write a text file Maximum file length 64 kByte Parameters file name Address of file name Il file content Address of data block Il file length nnumber of bytes
43. ET Micro Framework classes NET M icro Framework and UST host communications Table 1 Hardware options available for implementing a USB host in an embedded system To make a decision on which IC chip would be the best for this project first much research on those chips had to be carried out as well as studies on their datasheets their compatibility to M ega1284 and support items that each vendor provides such as libraries APIs and firmware The main purpose of this project is to serve the need of students who desire a simple way to utilize their microcontroller as a USB host so that they can employ a USB slave device in their final project without losing much of the resources or the computing power of the M CU to the processing of communication between a USB host and a slave Considering that a processor with an on chip host module or a host module with interface to an external processor seemed to be the best choice for the project FTDI Future Technology Devices International offers VNC1L Vinculum USB Host Controller IC which can be programed with firmware fully developed by FTDI The manufacturer also produces a single USB connector based development module VDIP1 for the VNC1L and a double USB connector base development module VDIP2 for the VNCIL Maxim Integrated offers a single IC with USB functionality M AX3421E USB Peripheral Host Controller with SPI interface Although MAX3421E provides a microcontroller independent solution no ext
44. K K K K K K K KK K K K K KKK K ERR RRR KK IG Ie KKK AR KK RR KEE EE EEE EE KR RR RR RR RR RRR EK KK KK define LED D1 ON LED PORT amp 1 lt lt LED_PIN LED define LED D1 OFF LED PORT 1 lt dED PIN define PROM PT CHECK 2 define PROM PT AND ERROR CHECK 1 define PROM PT OK 1 define TIMEOUT READ WRITE 5 buffer is full 00 Number of read write tests if define TIM EOUT_COM M UNICATION 5 Timeout if no communication has happened define FILE BUFFER SIZE 100 Buffer size is at least 100 define NO BUTTON PRESSED 0 define NO M OVEM ENT 0 KKK KKK KK KK KK KKK KK K firmware c KKK KKK KKK KK KKK KK KK K nclude firmware h defines macros define VNC BUFFER SIZE 160 Transmit receive buffer size is at least 60 11 WAAAH AAVA AAAA VAA AAAA 60 struct vnc struc char receive buffer VNC BUFFER SIZE Receive buffer char send buffer VNC BUFFER SIZE Send buffer unsigned char status Status Y struct vnc struc vnc instantiate vnc struc 116 X Cceelekekelelelelelelelelelelelelelelelelelelelerererererorerererereereleleleleleleleleleleleleerereeierelelelelelelelelelelele VNC1L Sending a command Parameter wr cmd command address Return status 0 2command accepted by VNCIL Ceceekeleieierelelelelelelelelelelelelelelelelelerererererererererereerererelelelelelelelelelelelelerelelerereerererererererererek unsigned char vnc wr cmd UART char wr cmd unsig
45. K K K KK K K K K K KK K K KKK KK K K K KKK KK K K K KKK KKK K K K K int main void init_system start the LCD init Icd LCDclr set up timer 0 for 1 mSec timebase TIM SKO 1 lt lt OCIEOA turn on timer 0 cmp match ISR OCROA 249 set the compare reg to 250 time ticks set prescalar to divide by 64 TCCROB 3 turn on clear on match TCCROA 1 lt lt WGM 01 crank up the ISRs sei put some stuff on LCD CopyStringtoLCD LCD VNCLL 0 0 start at char 0 line 0 CopyStringtoLCD LCD mega1284 0 1 start at char 0 line 1 To print what monitor returns fprintf stdout n r s n r vnc receive_buffer note All output from the command monitor is LSB first If monitor return multiple lines of data they are followed by carriage return which overwrites a previous line on fprintf Wait for VNC1L to respond with firmware version and message if a device is detected vnc status 2vnc wait for VNC1L UART if vnc status vnc error message vnc status 5 95 run IPA command before running ECS command Monitor commands in ASCII IPA mode vnc status vnc_wr_cmd_UART IPA if vnc status vnc_error_message 1 5 error command was not accepted by VNC1L vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 5 Extented Command Set vnc status vnc wr cmd UART ECS if vnc status vnc error message 1
46. K KKK KKE EEEE EKK EE EE EE EEK KK KK int main void init_system start the LCD init Icd LCDclr initialize VNCIL vnc_init put some stuff on LCD CopyStringtoLCD LCD VNCLL 0 0 start at char 0 line 0 CopyStringtoLCD LCD mega1284 0 1 start at char 0 line 1 my text 47 n my text 48 r my text 49 a a marks EOF end of file Regardless of the size of a buffer the last character of the buffer should be a fprintf stdout n rType something fscanf stdin n s n r my text An allows user to type multiple words Separated by a space Check for the presence of VDAP firmware on VNCIL if vnc wait for VDAP vnc error message 20 1 check confirmation Wait until a USB drive is plugged and detected if vnc wait for Device Detected vnc error message 21 2 check confirmation Wait for the first prompt that monitor returns D gt 40 vnc status vnc prompt check if vnc status vnc error message vnc status 3 Extented Command Set vnc status vnc_wr_cmd ECS if vnc status vnc_error_message 1 4 by VNCIL vnc status vnc prompt check prompt if vnc status vnc error message vnc status 4 check confirmation error message error command was not accepted check if monitor returns monitor returns prompt if command executed correctly Monitor commands in ASCII IPA mode vnc status vnc_w
47. KA A A AK KKK KK AK VNCIL Get firmware version Return 0 Prompt received EEKE KK KK KKK K KKK KK KK KKK K KEEK KEK KE KK KK KK KK K KKK KKE FEE K E KK KKK K KKK KK K KKK KEE unsigned char vnc firmware UART void int z get message from VNC1L and check prompt for z 20 z 34 z 1 wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDRI Il fprintf stdout n r c vnc receive buffer z count strlen vnc receive_buffer 1 for z 20 z 34 z for x 0 x count x if vnc receive buffer z r fprintf stdout An vnc receive buffer z fprintf stdout c vnc receive buffer z else fprintf stdout c vnc receive buffer z 118 return 0 RRR RR RR OR A HOR RR RR RR A EE EK RR A KK KK RK KKK KKK VNC1L Waiting for PROM PT Return 0 Prompt received FJ EEKE KK KK KK RR KKK K KE E E K EEK KKK KK KK KK K KKK KKE EEE K E KK KKK A A KK K KKK KEE unsigned char vnc prompt check UART void int done 0 int rd count 210 TIM EOUT COMMUNICATION TIMEOUT error abort if necessary int count 0 while rd count 1 if done wait until a byte has been received while UCSR1A amp 1 lt lt RXC1 0 vnc receive buffer count UDR1 printing here could cause the program to break fprintf stdout n r c vnc receive buffer count prompt received if vnc recei
48. KKK KKK K KKK K KEK K K EEKE KK K KKK KK K KKK KE EE EKK EKK KKK K KKK KE K KKK KEE unsigned char vnc query device UART void int z count get message from VNC1L and check prompt for z 20 z 135 z 1 wait until a byte has been received 120 while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 Il fprintf stdout n r c vnc receive buffer z count strlen vnc receive buffer 1 for z 20 z count z for x 20 x count x if vnc receive buffer z r fprintf stdout An vnc receive buffer z fprintf stdout c vnc receive buffer z else fprintf stdout c vnc receive buffer z return 0 RRR RR KKE E KKK A AA OR RR RK RR A A A KKK A EK KK KK k kE VNCIL Get class specific report Return 0 Prompt received Cekekeelekeierelelelelelelelelelelelelelelelelelerererererererererereererelelelelelelelolelelelelelelelelererererererererererererek unsigned char vnc get report UART char HID class int z This includes prompt check as well as parsing a report for z 20 z HID class z wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 Il fprintf stdout n r c vnc receive buffer z return 0 121
49. LED DDR 1 lt lt LED PIN output LED_D1_OFF turn off LED 8 bit no parity asynchronous UART 1 stop bit UCSR1C 1 UCSZ11 1 lt lt UCSZ10 init the UART uart init is in uart c uart init uart init1 stdout stdin stderr amp uart str fprintf stdout n r Starting VNC1L USB keyboard UART test n r J E AEK K K KKK K RR HR KA A A KKE K RR OR RR KE RA A A A A HE A EK KK KK K KE List of errors JJ AEA KKK KKK KKK RR RR HR KK A AK OR RR RR RA A A KKK EK K KEEKEKE II 1 Command was not accepted by VNCIL II 2 Command Failed 3 Bad Command Il 4 Disk Full ll 5 Filename Invalid Il 6 Read Only II 7 File Open Il 8 Directory Not Empty Il 9 No Disk ll 20 No VNCIL with VDAP firmware available II 21 No USB drive plugged II 50 Buffer is too small to read a file buffer overflow II 51 File length 0 or gt 64kByte 99 Timeout RRR RR RR HR KK A A A RR RR RR RR OR A A A A A A A KKK KKK HK void vnc_error_message unsigned char error_type unsigned char error_num 94 LED D1 ON LED turns on if there s an error fprintf stdout n rError type d Error number d n r error type error num error occured while 1 error keeps the system hanging II KKK K KKK K K KKK K K K KK K K K KK KK K K KK K K K KK K K K K K KK K K KK K K KK K K KKK K KK K K KKK KKK K K K K Main program II KKK K KKK K K KKK K K K KK K K K KK KK K K KK
50. LLC 2006 Print 3 Axelson Jan USB Embedded Hosts The Developer s Guide M adison Lakeview Research LLC 20011 Print Datasheets 1 Vinculum VNC1L Embedded USB Host Controller IC Datasheet by FTDI 2 VDIP1 Vinculum VNCIL M odule Datasheet by FTDI 3 VDIP2 Vinculum VNCI1L M odule Datasheet by FTDI 4 8 bit Atmel M icrocontroller ATmega1284 datasheet Manual 1 Vinculum Firmware User M anual by FTDI Documents PDF 1 Universal Serial Bus Specification 2 0 by USB IF 2 Device Class Definition for Human Interface Devices HID by USB IF 3 HID Usage Tables by USB IF 4 Data Logging Using the Vinculum VNCIL by FTDI 5 V Eval USB Missile Launcher Application Note by USB IF 6 Embedded USB Design by Example Part 1 amp 2 by John Hyde 3l 7 Interrupt Driven USART in AVR GCC by Dean Camera 8 AVR271 USB Keyboard Demonstration by Atmel 9 USB Keyboard Using M SP430TM Microcontrollers by Texas Instruments 10 Using USB Keyboard with an Embedded Host by M icrochip Technology Inc Websites 1 USB Implementers Forum www usb org 2 VNCIL USB Host Controller project www mikrocontroller net articles USB Stick am M ikrocontroller 3 ECE 4760 class website http people ece cornell edu land courses ece4760 4 Future Technology Devices International www ftdichip com 5 Wikipedia http en wikipedia org wiki Wikipedia 32 Appendix A USB Device Request 1 The format of the Setup packet in which USB de
51. RR RR RR RR HOR A EE KKE EE KK KK K EEK KK KEK KK KEE KK RR KK KKK KK VNCIL Initialize SPI Interface and VNC1L SPI Mode C Cekeeeeieieielelejelelelelelelelelelelelelelelelererererererererereerelerelelelelelelolelelelelelelelelelerererererererererererek void vnc init void CS VNC L SPl Interface inactive SCLK_L idle status of SPI lines SDI H RE VNC L Hardware reset VNC1L delay ms 100 X Pause RE VNC H start VNCIL delay ms 500 X Pause J RRR RR K K K K K A K K A K K K K K KK K K K K K K KK K K K K RA A A K K K K K K KK K K K K K K K VNC1L 13 Bit SPI Sending a character SPI Mode Parameter wr byte character to be output Return status 0 Accepted OK 1 Byte is not accepted by VNCIL Cekeekciereierelelelelelelelelelelelelelelelelerelererererererererereererelelelelelelelelelelelelelelelerererererererererererererek unsigned char vnc wr spi unsigned char wr byte unsigned char bit pos status count count TIM EOUT SPI timeout after unsuccessful number of attempts to write do CS VNC H SPl Interface active SDI H Start bit always 1 SCLK H SCLK_L falling rising edge SDI L Read Write bit 0 Write SCLK_H SCLK_L SDI L ADDR 0 Data SCLK H SCLK L send 8 data bits M SB first for bit pos 20x80 bit pos bit pos 22 1 if wr byte amp bit pos SDI H else SDI L 45 SCLK H SCLK L read status status SDO_VNC
52. T GUI 0x80 define KEY A 4 define KEY B 5 define KEY C 6 define KEY D 7 define KEY E 8 define KEY F 9 define KEY G 10 define KEY H 11 define KEY 12 define KEY 13 99 define KEY K 14 define KEY L 15 define KEY M define KEY N 17 define KEY O 18 define KEY P 19 define KEY Q 20 define KEY R 21 define KEY S 22 define KEY T 23 define KEY U 24 define KEY V 25 define KEY W define KEY X 27 define KEY Y 28 define KEY Z 29 define KEY 1 30 define KEY 2 3l define KEY 3 32 define KEY 4 33 define KEY 5 34 define KEY 6 35 define KEY_7 36 define KEY_8 37 define KEY_9 38 define KEY_0 39 define KEY_ENTER 40 define KEY ESC define KEY BACKSPACE define KEY TAB define KEY SPACE 44 define KEY MINUS 45 define KEY EQUAL 46 define KEY LEFT BRACE define KEY RIGHT BRACE define KEY BACKSLASH define KEY NUM BER define KEY SEM ICOLON define KEY QUOTE 52 define KEY TILDE 53 define KEY COMMA 54 define KEY PERIOD 55 define KEY SLASH 56 define KEY CAPS LOCK 16 26 57 100 define KEY F1 58 define KEY F2 59 define KEY F3 60 define KEY F4 61 define KEY F5 62 define KEY F6 63 define KEY F7 64 define KEY F8 65 define KEY F9 66 define KEY F10 67 define KEY F11 68 define KEY F12 69 define KEY PRINTSCREEN 70 define KEY SCROLL LOCK 71 define KEY PAUSE 72 define KEY INSERT 73 define KEY HOME 74 define KEY PAGE UP 75 define KEY_DELETE 7
53. T vnc send buffer status vnc prompt check UART Data is usually appended to the end of an existing file or a new empty file is created if it doesn t exist SEK command move to an arbitrary point in a file if option new file status vnc wr cmd UART SEK 0 status vnc prompt check UART write to a file sprintf amp vnc send buffer 0 WRF u file length status vnc wr cmd UART vnc send buffer status vnc prompt check UART do not check for prompt here file ptr 2file content for vnc i 20 vnc i file length file CR vnc_i if file ptr wait until the last byte has been transmitted while UCSR1A amp 1 lt lt UDRE1 0 UDRI file_ptr status vnc_prompt_check_UART file ptr4 close a file and prompt check sprintf amp vnc send buffer 0 CLF s file name status vnc wr cmd UART vnc send buffer status vnc prompt check UART return 0 II KKK KK K K K KK KK K K K KK KK K K K KKK K K K K K K KKK K K K KKK KK K K K KKK KK K KKK KK OK OK OK OK OK OK KOK OK OK KKK KK VNC1L Reading a file of a specific length from an USB drive Length of the file should be known so determine it beforehand with vnc rd dir Parameters file name address of file name 87 Il file content address of destination buffer where the read data will be stored II file_length number of bytes Return 0 OK II PEKEE E E KE KK E E E E KE E K K K K KK KK
54. UART write to a file sprintf amp vnc send buffer 0 WRF d file length status vnc wr cmd UART vnc send buffer status vnc prompt check UART do not check for prompt here for vnc i 20 vnc i file length vnc_i Hh 91 wait until the last byte has been transmitted while UCSR1A amp 1 lt lt UDRE1 0 UDRI file content file content4 status vnc prompt check UART close a file and prompt check sprintf amp vnc send buffer 0 CLF s file name status vnc wr cmd UART vnc send buffer status vnc prompt check UART return 0 5 VNCIL keyboard UART polling HK KK AK KK KKKKKKKKEK VNCTLE keyboard UART C Original project by Matthias Kahnt az51 gmx net Modified by Terry Young Kim ATmegal1284 VNC1L VDIP1 Vinculum Port2 VNCIL USB HOST CONTROLLER M ega1284 M aster VNC1L Slave VDAP firmware version 3 69 USART interface VDIP1 Jumper Set J3 Pullup J4 Pullup for UART VNCIL connect CTS AD3 to ground pull down low or connect CTS AD3 and RTS AD2 WARNING if the prompt check is carried out properly the program will hang include avr io h include lt string h gt include lt stdio h gt include lt stdlib h gt include lt avr interrupt h gt include util delay h for LCD include uart c UART channel 0 gt PuTTy
55. USB HOST CONTROLLER FOR A MICROCONTROLLER FOR USE IN ECE 4760 A Design Project Report Presented to the School of Electrical and Computer Engineering of Cornell University in Partial Fulfillment of the Requirements for the Degree of Master of Engineering Electrical and Computer Engineering Submitted by Young Hwa Kim MEngField Advisor Dr Bruce Land Degree Date January 2013 Abstract Master of Engineering Program School of Electrical and Computer Engineering Cornell University Design Project Report Project Title USB Host Controller for a M icrocontroller for Use in ECE 4760 Author Young Hwa Kim Abstract Using a microcontroller as a USB host device instead of as a USB peripheral device can be very helpful for students in ECE 4760 Digital Systems Design Using M icrocontrollers to attach a USB mouse a USB keyboard or a USB memory stick Although a full software version of a USB host has been previously implemented on AVR M ega32 microcontrollers as a final project for ECE 4760 by students the fact that it heavily loads the microcontroller forces us to look for an alternative solution in other words a hardware implementation For example dedicated host chips such as VNC1L and M AX3421 provide high speed interface to unload the microcontroller implemented a useable USB host interface to M ega1284 using a chip VNCIL on VDIP1 module that unloads the microcontroller The final product includes the libraries that consist
56. a specific length from an USB drive Length of the file should be known so determine it beforehand with vnc rd dir Parameters file name address of file name hl file content address of destination buffer where the read data will be stored Il file length number of bytes Return status error number 0 OK EERE RER KRKK KE KEKEKE KK KKR EREKE EE EER KEEKEEKE KEER EE EE EEK KEREK EEKE ERE EE EEE unsigned char vnc_rd_file char file_name char file_content unsigned int file_length unsigned char rd_steps 0 unsigned char status 0 if file length gt FILE_BUFFER_SIZE 1 return 50 error buffer is too small do if rd_steps 4 return 0 Done OK last prompt character exists switch rd steps read process case 0 Open file for reading sprintf amp vnc send buffer 0 OPR 96s file name if vnc wr cmd vnc send buffer return 1 Error command was not accepted break case 1 Seek offset byte position of 0 in the open file you can also choose other offset if vnc wr cmd SEK 0 return 1 Error command was not accepted break 55 case 2 Read the number of bytes from an open file sprintf amp vnc send buffer 0 RDF 96d file length if vnc wr cmd vnc send buffer return 1 Error command was not accepted while file length if vnc rd byte return 1 error byte is not received new character exists file content vnc receive_buffer 0
57. ails how to configure a VNC1Lto communicate with a microcontroller using the UART interface Please note once again that in this project the flow control is not used Thus ADBUS2 and ADBUS3 should be connected together instead of being connected to RTS and CTS of the microcontroller ai VG Figure 12 VNC1L schematic MCU UART interface 14 Excerpted from VNCIL datasheet on page 25 20 USB Mass Storage Device VNCIL USB Host Controller project by Matthias Kahnt was the basis and a good start for this project Kahnt s project uses emulated SPI for the communication between a mega644 and a VNC1Lon a VDIP1 module It comes with its own LCD and UART libraries which are different from the ones that are used in ECE 4760 class Instead of using SCK M ISO M OSI and SS pins on Port B that mega644 sets apart for SPI it uses five pins on Port D for SPI and Port A for an LCD display This project comes with an extensive library that consists of all APIs that are necessary for a microcontroller host to interface with a USB flash drive With these APIs firmware commands can be sent to the monitor to write a text file or a binary file to a USB drive read a text file from a USB drive and append a string of text to an existing file The VNC1L USB drive project is not much different from Kahnt s original project It is simply re written in English with minor changes made to the original project The VNCIL USB drive project for ECE 4760 class
58. ain program with options for 8 data bits no parity asynchronous UART and 1 stop bit Also the two three way jumper pin headers on the VDIP1 module should be correctly configured for UART interface The red lines next to J3 and J4 in the figure below show how the jumpers should be mounted for UART along with other port pin configurations AD6 1 3 s AD5 DATAREQ AD7 E AD4 DATAACK ACO a AD3 CTS AC1 e zc RTS AC2 3 AD1 RXD PD3 GND e GND A i AC3 3 ADO TXD PD2 AC4 e U1M AC5 L U1P RS LD2 PG LD1 3V3 24 E 5V0 from MCU Figure 11 VDIP1 on board jumper pin configuration and port connections to M CU for UART It should be noted that pins AD2 RTS request to send and AD3 CTS clear to send are connected together Although the VNC1L supports the flow control functionality of UART in this project the flow control is not utilized for both of UART channels However to enable UART communication either RTS and CTS should be connected or CTS should be pulled down The benefit of using the UART mode with VDIP1 is that it requires only two ports RX and TX from a microcontroller plus possibly one more output port from the M CU that can pull down AD5 B Excerpted from VDIP1 datasheet on page 4 19 DATAREQ Z to make the VNCIL switch from Command M ode to Data M ode which will be explained more later If students choose to use only a VNCIL chip instead of a VDIP1 module for their project the next figure det
59. and a report from a USB host can turn on an LED for a NUM Lock on a keyboard The Windows HID API provides a set of functions that applications can use to get and send a report Conveniently the firmware for VNC1L comes with a command that can do the same which will be elaborated on later in this report More detailed information on the entire USB protocols can be obtained from documents such as USB Serial Bus Specification on USB Implementers Forum USB IF website Vinculum VNC1L Embedded USB Host Controller IC Hardware VDIP1 module VNCIL from FTDI is a single chip embedded dual USB host controller that features two independent USB 2 0 Low Full speed USB host ports This chip handles entire USB protocols such as enumeration and various transfers of descriptors at IN and OUT endpoints It comes with 64k bytes of embedded Flash E FLASH memory to store firmware which could be programed or updated via UART interface VNCIL also provides options to interface to external Command M onitor via UART SPI or FIFO slave interface It does not require external software control because the free firmware takes care of it all which is the best advantage of using a VNCIL chip for the project PLL FILTER INTERNAL IO BUS INTERNAL IO BUS EXTERNAL IO BUS Figure 1 Simplified VNC1L Block Diagram Excerpted from VNCIL datasheet on page 4 Figure 2 1 9 The block diagram is provided here for anyone who wants to know what is inside of a VN
60. and monitor The firmware activates a command monitor port for one of the USB ports and this allows an embedded device such as an M CU to communicate with a USB peripheral device via the VNCIL s UART SPI or FIFO interface An M CU can send instructions commands to the command monitor and receive data from it When the VNCIL is ready to take a command and after a successful execution of any command the command monitor returns a prompt D gt 5 Excerpted from VNCIL datasheet on page 26 Figure 7 2 12 There are two modes in which the command monitor works Command M ode and Data Mode The VNCIL firmware starts in the command mode to switch to the data mode the DATAREQ line on VNC1L must be asserted low Once in the data mode the DATAACK line goes low and the VNCIL simply passes data between a USB device and the monitor port In the command mode the VNCIL interprets and executes commands taking appropriate actions The operations of these two modes are depicted in Figure 5 and Figure 6 respectively Monitor Microcontroller E Lr Hn jc md ao m j VNCiL 1A mn EO ra E USB Device Figure 5 Command M ode connection gt E Port 2 BOMS Flash Disk DUDE HH HEH HAL RAH AO AAA OHA liii iO Port 1 BARRE AT ihi lili dl FTDI USB Slave Peripheral Figure 6 Data M ode connection The command monitor supports two command entry
61. and they proved to work fine equally For both projects polling a report from a keyboard every 50ms using a timer and timer compare ISR interrupt service routine worked smoothly The basic housekeeping procedure which is the same as the one for a USB drive is done at the beginning of the program such as getting a version of firmware and a confirmation from the monitor that a device was detected on Port 2 For a USB keyboard there is a different set of commands to be used for a host to exchange data with the device connected to the VNC1L Before the exchange of data between a host and a slave device could happen some more important housekeeping procedure should be done for both SPI and UART projects To make sure if the device on Port 2 is recognized as an HID device QP2 command is sent to the monitor For a USB keyboard the monitor returns 08 00 while 20 00 is returned for a USB drive To get information on a device interface QD command is used QD takes a parameter that presents a device number which can be between 0 and 15 inclusively Zero works fine for a device number in both of the projects since VDIP1 comes with only one USB receptacle for one device to be connected to the VNCIL at a time Among the information that the monitor returns after the QD command are a vendor ID for the device a product ID Pipe IN End Point number Pipe OUT End Point number and a device class which are part of a block of 32 bytes QP and QD commands
62. are not essential and can be left out However before sending a command that can fetch data from a device SC command must be executed see Table 2 This is very important for both projects and for any mode that the VNCIL might be in SC with the device number which is zero for this project allows all output from the SSU command to be routed to this specific device Unless SC command is executed first SSU command which is the most import command to exchange data with HID devices does not work at all Reports from an HID device can be polled and sent through the Control pipe instead of Interrupt In pipe All USB devices must respond to requests from a host on their default Control Pipe Class specific requests allow a host to get a report from a device to find out the state of it and to send a report to a device to change the state of output from it Using the SSU command we can send get report requests set report requests and set idle requests Only get report requests are mandatory and all devices must support them The detailed information on the formats of each type of requests is found in Appendix A After a get report request is sent as a parameter of the SSU command the monitor returns an IN report from a keyboard which has information shown in Figure 13 The direction 23 of a report is always from a host s point of view Only one report is allowed in a single USB transfer and one IN report can tell us up to six key presses plus if
63. c vnc receive buffer x else fprintf stdout c vnc receive_buffer x return 0 X Ceeeelekekelelelelelelelelelelelelelelelelelelelelerererererorererereererelelelelelelelelelelelelelelelelererererererererererererek VNCIL Get firmware version Return 0 Prompt received RR KKK K KKK KK K K KKK KKK K KKK KKK KK K K K K KEK KKE RR RR RA A KKK A EK KK KK EKE unsigned char vnc firmware UART void int z get message from VNC1L and check prompt for z 20 z 34 z wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 Il fprintf stdout n r c vnc receive buffer z 103 count strlen vnc receive buffer 1 for z 20 z 34 z for x 20 x count x if vnc receive buffer z r fprintf stdout An vnc receive buffer z fprintf stdout c vnc receive buffer z else fprintf stdout c vnc receive buffer z return 0 AREK K KKK K KK KK KKK KKK KK K KKK K K KKK KE KKK KKK KKK KK KK REKE K EKK KKK KKK KKK K KEKEE KE VNC1L Waiting for PROM PT Return 0 Prompt received EKEK KKR KKK KKK KK KRKK KEKERE E KEK E E KERRE KEKEE E EEK ROR RR RR RR A A A A EKKE ERE ERREF unsigned char vnc prompt check UART void int done 0 int rd count 210 TIM EOUT COMMUNICATION TIMEOUT error abort if necessary int count 0 while rd count if done wait until a byt
64. check if monitor returns prompt if vnc status vnc error message vnc status 9 monitor returns prompt if command executed correctly 13 fprintf stdout n r s n r vnc receive buffer Device Send Setup Data Set Idle vnc status vnc wr cmd SSU 210A000000000000 no interrupt unless there s a change of event 210A007D00000000 500ms 4ms 0x7D if vnc status vnc error message 1 120 vnc status vnc prompt check check if monitor returns prompt if vnc status vnc error message vnc status 120 CopyStringtoLCD LCD success 0 1 fprintf stdout n rStart polling n r If you reached here then no error has occured LED blinks every second main task scheduler loop while 1 reset time and call task if timel1 0 time1 t1 task1 LED D1 ON delay ms 1000 1 sec LED D1 OFF delay ms 1000 RRR RRR KK KKK RAK AK KK KK KKK Task subroutine Task 1 void task1 void Device Send Setup Data Get Report vnc status vnc_wr_cmd SSU A101000100000400 monitor return 4 bytes if vnc status vnc_error_message 1 12 for int t 0 t 19 tH this includes prompt check as well as report vnc_rd_spi 0 test t int vnc receive_buffer 0 II fprintf stdout n d test t 74 Il fprintf stdout n c vnc receive buffer 0 if pre test 10 amp amp test 10 20 buttons iftest 10 1 fprintf stdout n
65. d provide APIs that read a file from a drive write a file to a drive and append new texts to an existing file on a USB drive The library for a USB keyboard would have APIs that can recognize a keystroke on a keyboard The last library for a USB mouse would include APIs that detect a button press left and right clicks and a wheel movement on a mouse in terms of X and Y coordinates With the complete sets of API libraries students should be able to easily add a USB slave device to their projects To help students better understand how to utilize the new libraries in their project sample programs that employ API function calls from each library would be written to show how to interface a USB slave device to a host controller M ega1284 Developing an API library for a USB printer would not be considered because many printers these days use a printer control language that is unique to themselves Implementing supports for every possible printer control language and many different features of every printer would be outside of the scope of this project USB Protocol Basics Although VNCIL does take care of all low level housekeeping that is related to USB protocols for a microcontroller understanding the basic terminology of USB protocol will help students who plan to use a VDIP1 module and APIs that allow communication between an M CU and VNCIL for their final projects Thus here a few of important USB interface are explained USB Transfers A USB
66. ded to an existing file on a USB drive This shows that now a USB drive can be used as a good storage for a data logging program and eliminate the limit of memory space for a project that saves much data One thing to be noted is that USB flash drives usually ship preformatted in FAT32 FAT12 or FAT16 file systems Although the firmware user manual guarantees that it supports all those three file Systems with a sector size of 512 bytes if a certain USB drive cannot be accessed by the VNCIL it is recommended that the drive should be re formatted to be of FAT32 file system with a sector size of 512 bytes before it is connected to the VDIP1 For a USB keyboard and a USB mouse in the command mode polling an IN report every 50 ms with the SSU command after setting the idle time to indefinite worked very well either with SPI or USART A user can type at a considerably fast speed or click the buttons on a mouse continuously while there was no miss of those new events on the host side However in the data mode where data from a slave device is directly sent to a host without going through the monitor even polling an IN report with the SSU command did not work with SPI For example many keystrokes were missed because it seemed that the IN reports did not come in at a regular rate which made it impossible to parse them correctly In the SPI mode only a master provides the clock and thus only a master can initiate the communication Therefore even with the i
67. device Both SPI and USART are tested with a USB flash drive a USB keyboard and a USB mouse and they proved to work fine equally Different wire connections between the mega1284 board and the VDIP1 module for SPI and UART are depicted in the next sections respectively SPI Serial Peripheral Interface SPI allows high speed synchronous data transfer between mega1284 and a peripheral device in our case VNCIL The hardware setup for SPI between a host and a slave is Excerpted from Vinculum Firmware M anual on pages 22 26 27 and 41 15 demonstrated in the next figure Since SPI uses a synchronous serial communication bus a transmitter and a receiver must use the same clock to synchronize the detection of the bits at the receiver In SPI both the master and the slave send and receive data simultaneously through the shift registers as shown on the right eight bits flow from the master to the slave and different eight bits flow from the slave to the master The master always supplies the clock SCLK for synchronization and initiates the communication To get data from the slave the master has to send out dummy data that is shifted out of M OSI master out slave in and into the shift register in the slave which causes the data in the shift register in the slave to be shifted out of M ISO master in slave out and into the shift register in the master More than one slave device can be connected to one master and SS chip select can
68. dle time set to 50 ms in the data mode which means that a device is scheduled to send an IN report every 50 ms whether there is a new event or not just like polling it does not work for a keyboard or a mouse On the other hand polling an IN report in the data mode with USART worked as good as in the command mode for both a keyboard and a mouse USART can be used with RX and TX interrupts The idea that an interrupt on RX complete could leave more time to the M CU to perform other tasks than polling a report every 50 ms was tested in the data mode First whether the idle time could be set correctly with the SSU command was checked in hardware because we would want a slave device to send an IN report to the host only when there was a change in the report USB type A pinout is shown in Figure 15 To scope D and D two soldered points on the bottom of the VDIP1 module towards a receptacle were connected to an oscilloscope With the idle time set to indefinite whenever a key is pressed a keyboard is expected to send an IN report eight bytes of which should be saved in a buffer in the RX Complete ISR Interrupts were fired as expected however there were other problems When a user types at a considerably fast speed the first report contains the first keystroke in the Key array 0 and at the second keystroke the second report saves both keystrokes in the Key array 0 and the Key array 1 The problem is that keystrokes are not saved in the same order
69. e VDIP1 Jumper Set J3 Pullup J4 Pullup for UART VNC1L connect CTS AD3 to ground pull down low or connect CTS AD3 and RTS AD2 WARNING if the prompt check is carried out properly the program will hang include avr io h include lt string h gt include lt stdio h gt include lt stdlib h gt include lt avr interrupt h gt include util delay h for LCD include uart c UART channel 0 gt PuTTy nclude uart1 c UART channel 1 lt gt VNCI1L include Icd lib c LCD include firmware c VNCIL APIs define F CPU 16000000UL define MOUSE 18 define BUTTONS 10 define X COORDINATE 11 define Y COORDINATE 12 define WHEEL_COORDINATE 13 define BIT 1 ON 1 define BIT 2 ON 2 109 define BIT 4 ON 4 timeout value for a task define t1 50 50ms works fine volatile unsigned int time1 timeout counter LED PBO LCD PORTC VNC TX PD3 RX PD4 UART file descriptor putchar and getchar are in uart c FILE uart_str FDEV_SETUP_STREAM uart putchar uart getchar FDEV SETUP RW const int8 t LCD initialize PROGM EM LCD Initialized 0 const int8 t LCD VNCIL PROGM EM VNCI1L Test 0 const int8 t LCD mega1284 PROGM EM AVR Atmega1284V0 const int8 t LCD success PROGM EM VNCI1L success V0 int8 tlcd buffer 17 LCD display buffer volatile int pre 0 volatile int pre x 0 volatile int pre y 0 volatile int pre whe
70. e 9 When the VDIP1 is powered on two on board LEDs LED1 and LED2 flash alternately for 2 seconds and it repeats until the monitor connects When commands from the monitor port are sent to a USB device LED2 flashes A USB drive should not be removed from the USB type A receptacle of the VDIP1 if LED2 is blinking It is safe to remove it when LED2 is on 36 Appendix C Code 1 VNCIL USB drive SPI Original project by Matthias Kahnt az51 gmx net Modified by Terry Young Kim ATmegal1284 VNC1L VDIP1 Vinculum Port2 VNCIL USB HOST CONTROLLER M ega1284 M aster VNC1L Slave VDAP firmware version 3 68 or 3 69 SPl interface VDIP1 Jumper Set J3 Pulldown J4 Pullup for SPI nclude lt avr io h gt include lt string h gt nclude lt stdio h gt Anclude lt stdlib h gt include util delay h for LCD include uart c UART include Icd lib c LCD include firmware c VNC1L APIs define F CPU 16000000UL LED PBO LCD PORTC NNC SCLK PA3 SDI PA4 l SDO PA5 l CS PA6 l RS PA7 UART file descriptor putchar and getchar are in uart c FILE uart_str FDEV_SETUP_STREAM uart_putchar uart getchar FDEV SETUP RW const int8 t LCD initialize PROGM EM LCD Initialized 0 const int8 t LCD VNCIL PROGM EM z VNCIL Test 0 const int8 t LCD mega1284 PROGM EM AVR Atmega1284V0 const int8 t LCD success PROGM EM VNCI1L success VO 3
71. e vnc status vnc wr cmd UART SC 0 113 if vnc status vnc error message 1 9 error command was not accepted by VNCIL vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 9 monitor returns prompt if command executed correctly Device Send Setup Data Set Idle vnc status vnc wr cmd UART SSU 210A000000000000 no interrupt transfer unless there is a change in the keycode 210A007D00000000 2 interrupt transfer every 500ms 500ms 4ms 0x7D if vnc status vnc_error_message 1 120 vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 120 CopyStringtoLCD LCD success 0 1 fprintf stdout A n rStart polling n r If you reached here then no error has occured LED blinks every second main task scheduler loop while 1 reset time and call task if time1 90 time1x1 task1 LED D1 ON delay ms 1000 1 sec LED D1 OFF delay ms 1000 RRR RR KK KKK RK KKK KK KK KKK Task subroutine Task 1 void task1 void Device Send Setup Data Get Report vnc status vnc_wr_cmd_UART SSU A101000100000400 monitor returns 4 bytes if vnc status vnc_error_message 1 12 vnc status vnc_get_report_UART M OUSE 114 left click right click wheel click if pre vnc receive_buffer BUTTONS amp amp vnc recei
72. e has been received while UCSR1A amp 1 lt lt RXC1 0 vnc receive buffer count UDR1 printing here could cause the program to break fprintf stdout n r c vnc receive buffer count prompt received if vnc receive buffer count 2 0x0D DA if vnc receive_buffer count 1 amp amp vnc receive buffer count 2 0x5C amp amp vnc receive buffer count 3 amp amp vnc receive buffer count 4 D 104 return 0 count E rd_count return 1 no prompt timeout JEA KKE KRKK KKK RR KKK K KKE KK K KK KE KKK KKK KK KK KK KKE KE EEK KKK KKK KKK KKK KKE EKE VNC1L Get device class from VNCIL for example 08 amp 00 for HID Return 0 Prompt received RRR RR RR RR RR RR RR RR RR RK KK AK RR OR RR RR RRR EK KK KK KKK unsigned char vnc query port UART void int z get message from VNC1L and check prompt for z 20 z 13 z wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 fprintf stdout n r c vnc receive buffer z count strlen vnc receive_buffer 1 get message from VNC1L and check prompt for z 20 z 13 z for x 20 x count x if vnc receive buffer z r fprintf stdout An vnc receive buffer z fprintf stdout c vnc receive buffer z else fprintf stdout c vnc receive buffer z return 0 105 AAK KK KKK
73. eceive_buffer x if x 0 break To print what monitor returns fprintf stdout n r s n r vnc receive buffer note All output from the command monitor is LSB first If monitor return multiple lines of data they are followed by carriage return which overwrites a previous line on fprintf 72 Query port 2 for HID vnc status vnc wr cmd QP2 if vnc status vnc error message 1 7 error command was not accepted by VNC1L vnc status vnc prompt check check if monitor returns prompt if vnc status vnc error message vnc status 7 monitor returns prompt if command executed correctly fprintf stdout n r s n r vnc receive buffer Query Device vnc status vnc_wr_cmd QD 0 if vnc status vnc_error_message 1 8 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 8 monitor returns prompt if command executed correctly count strlen vnc receive_buffer 1 for x count x gt 0 x if vnc receive buffer x r fprintf stdout An vnc receive buffer x fprintf stdout c vnc receive buffer x else fprintf stdout 9oc vnc receive buffer x if x 0 break Set current device vnc status vnc wr cmd SC 0 if vnc status vnc error message 1 9 error command was not accepted by VNC1L vnc status vnc prompt check
74. ed int count count TIM EOUT READ WRITE number of attempts to send before timeout do read status byte from VNCIL if vnc rd spi 1 return 1 error byte is not accepted Status byte is now in the buffer status vnc receive_buffer 0 amp 0x01 test for VNC1L RECEIVE BUFFER full RXF Bit0 1 count if status delay us 150 Pause if RECEIVE BUFFER full RXF while status amp amp count if status count return 1 error byte is not accepted VNCILis now ready to receive if vnc wr spi wr byte return 1 error byte is not accepted return 0 byte has been sent JAEK E K EKK KK KK KE KKK KKK KKK E KK K KK KEK KK KK KKK KK KK KKE KE EEK KKK KKK KEK KKK EKE KEE VNC1L Receiving a character Return status 0 2 New byte in the buffer OK 1 a new byte is not available from VNCIL Ceeeleereiereielereierejelejelelelelelololelelolololoiereretereretererereteretetetereterereretereierejejererererereierelelelelelek unsigned char vnc rd byte void unsigned char status 48 unsigned int count count TIM EOUT READ WRITE number of attempts to receive before timeout do read status byte from VNCIL status vnc rd spi 0 f status 1 there is not a new byte Testing for TXE in the status byte has no advantage count if status delay us 150 Pause if there is no new byte while status amp amp count if status count return 1 error by
75. el 0 the task subroutine void task1 void RRR RRR RK KR AK KK RR RR RR RR RR KK AK KK KK EEE E timer 0 compare ISR ISR TIM ERO COMPA vect Decrement the time if it is not already zero if time120 timel RRR RR KKK KK KKK A KK RR RR RR RR RR KK KK KK KKK KK LCD setup void init Icd void 110 LCDinit initialize the display LCDcursorOFF LCDclr clear the display LCDGotoXY 0 0 CopyStringtoLCD LCD initialize 0 0 system initialization void init_system void LED for debugging LED DDR 1 lt lt LED PIN output LED D1 OFF turn off LED 8 bit no parity asynchronous UART 1 stop bit UCSR1C 1 UCSZ11 1 lt lt UCSZ10 init the UART uart init is in uart c uart init uart init1 stdout stdin stderr amp uart str fprintf stdout n r Starting VNCIL USB mouse UART test n r RRR RR RR OR A EREE HOR RR A EE EE EK KK KA KKK KKK RK KKK KKK List of errors RRR RR RR RRA KK AA ARR OR RR OR RK A A A A A EK KKK KK KK II 1 Command was not accepted by VNCIL II 2 Command Failed 3 Bad Command II 4 Disk Full II 5 Filename Invalid Il 6 Read Only II 7 File Open Il 8 Directory Not Empty Il 9 No Disk II 20 No VNCIL with VDAP firmware available II 21 No USB drive plugged II 50 Buffer is too small to read a file buffer overflow II 51 File length 0 or gt 64kByte II 99 Timeout J
76. elelerererererererererereererelelelelelelelelelelelelelelelerererererererererererererek VNCIL Get firmware version Return 0 Prompt received EERE KK KK KKK K KKK KKK KK KKK K KEK K K EE KK KK K KKK KK K KKK K KEF EKK EKK KKK K KKK KK K KKK KKE unsigned char vnc firmware UART void int z get message from VNC1L and check prompt for z 20 z 34 z 1 wait until a byte has been received 84 while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 Il fprintf stdout n r c vnc receive buffer z count strlen vnc receive buffer 1 for z 20 z 34 z for x 20 x count x if vnc receive buffer z r fprintf stdout An vnc receive buffer z fprintf stdout c vnc receive buffer z else fprintf stdout c vnc receive buffer z return 0 RRR KK KRK KK KKK KK KKK K KA KK KE KK KKK KKK KK KK KKE KE RR RA A A A A AK KK KK A AK VNC1L Waiting for PROM PT Return 0 Prompt received Cekekelekeielerelelelelelelelelelelelelelelelelelerererereroerererereereleleleleleketererererereieleleleleleleleleleleleleleleleler unsigned char vnc prompt check UART void int done 0 int rd count 210 TIM EOUT COMM UNICATION TIM EOUT error abort if necessary int count 0 while rd count 1 if done 1 wait until a byte has been received while UCSR1A amp 1 lt lt RXC1 0 vnc receive buffer count UDR1
77. ensive firmware download for the chip is available from the vendor Writing a device specific firmware for a USB host controller is outside of the scope of this design project Thus VNCIL was the best choice for the project Once a decision was made on which IC was to be the hardware option for the project studies on the libraries of the specific firmware for VNCIL and its command sets for various USB device classes were carried out The expectation was that those firmware commands would take care of instantiating the low level interface between the USB host M ega1284 and its USB Slave device such as an enumeration of the device requesting and receiving various types of descriptors and addressing endpoints of the device Proposal for Development Next step would be to write the API libraries for two different USB classes HID and mass storage which includes a USB keyboard a USB mouse and a USB memory stick Those classes use different transfer types to communicate with a host HID class uses interrupt transfer while the mass storage class uses bulk transfer Also HID class uniquely uses report to transfer data Thus three sets of API libraries for each device should be written and this would be the main task for the finished project Once the project was successfully completed the deliverables were expected to be a ready to use USB interfacing solution that supported two common USB device classes The library for a USB memory stick woul
78. er PROM PT_AND ERROR CHECK while status PROMPT OK Testing for next prompt character gt return status error number while 0 OK 2 VNC1L keyboard SPI polling KKK KK OK OK K K KKK OK KKK KK VNCIL keyboard c KKK 2K 2K 2K KK eoe OK OK OK OK OK KK KK Original project by Matthias Kahnt az51 gmx net 59 Modified by Terry Young Kim ATmegal284 VNC1L VDIP1 Vinculum Port2 VNCIL USB HOST CONTROLLER M ega1284 M aster VNC1L Slave VDAP firmware version 3 68 or 3 69 SPl interface VDIP1 Jumper Set J3 Pulldown J4 Pullup for SPI include avr io h include lt string h gt include lt stdio h gt include lt stdlib h gt include lt avr interrupt h gt include util delay h for LCD include uart c UART include Icd lib c LCD include firmware c VNC1L APIs define F CPU 16000000UL timeout value for a task define t1 50 50ms works fine LED PBO LCD PORTC NNC SCLK PA3 l SDI PA4 l SDO PA5 l CS PA6 l RS PA7 UART file descriptor putchar and getchar are in uart c FILE uart str FDEV_SETUP_STREAM uart_putchar uart getchar FDEV SETUP RW const int8 t LCD initialize PROGM EM LCD Initialized 0 const int8 t LCD VNCIL PROGM EM z VNCIL Test 0 const int8 t LCD mega1284 PROGM EM AVR Atmega1284V0 const int8 t LCD success PROGM EM VNCI1L success VO int8 tlcd buffer 17 LCD display buf
79. erererererererererererek II 1 Command was not accepted by VNCIL II 2 Command Failed 3 Bad Command Il 4 Disk Full II 5 Filename Invalid Il 6 Read Only 7 File Open II 8 Directory Not Empty 9 No Disk ll 20 No VNCIL with VDAP firmware available II 21 No USB drive plugged II 50 Buffer is too small to read a file buffer overflow II 51 File length 0 or gt 64kByte 99 Timeout RRR RR RRR HR KK A KK RR OR EE RR RA A A A K AH RK KK KEKEKE void vnc_error_message unsigned char error_type unsigned char error_num LED D1 ON LEDturnson if there s an error fprintf stdout n rError type d Error number d n r error type error num error occured while 1 error keeps the system hanging J AAR KKK KKK KKK KKK KK KK K KKK K KEK K KEEK KKK KKK KK E K KEK KKE KEE EE KK KK EE EE EEK KK KK Main program RRR AR HR K KKK RR RR RK OR RR RR RRR RRR KK int main void init_system start the LCD init Icd LCDclr initialize VNCIL vnc_init 62 set up timer 0 for 1 mSec timebase TIM SKO 1 lt lt OCIEOA turn on timer 0 cmp match ISR OCROA 249 set the compare reg to 250 time ticks set prescalar to divide by 64 TCCROB 3 turn on clear on match TCCROA 1 lt lt WGM 01 put some stuff on LCD CopyStringtoLCD LCD VNCLL 0 0 start at char 0 line 0 CopyStringtoLCD LCD mega1284 0 1 start at char 0 line 1 char count x
80. f vnc status vnc error message vnc status 10 Write a binary bin file to disk vnc status vnc wr binfile VNCFILE3 BIN file4 80 file length 280 if vnc status vnc error message vnc status 11 Before reading a file you must get the length of it vnc status vnc rd dir VNCFILE2 TXT file buffer amp file length if vnc status vnc error message vnc status 12 Now the file length is saved in file length if Ivnc status Read a text file of known length into file_buffer vnc status vnc_rd_file VNCFILE2 TXT file buffer file length if vnc status vnc error message vnc status 13 Write text file 5 to disk vnc status vnc_wr_txtfile VNCFILE5 TXT file5 0 FILE NEW if vnc status vnc_fehlermeldung vnc status 14 Write text file 5 to disk using user input string vnc status vnc_wr_txtfile VNCFILE5 TXT my text FILE NEW if vnc status vnc error message vnc status 14 Get the length of file vnc status vnc rd dir VNCFILE5 TXT read str amp file length if vnc status vnc error message vnc status 15 if vnc status Read a text file of known length into my str vnc status vnc rd file VNCFILE5 TXT my str file length if vnc status vnc error message vnc status 16 fprintf stdout Echo back n r s n r my_str 42 Append a text string to an existing file vnc status vnc wr txtfile VNCFILE5 TXT file5 0 FILE APPEND if vnc stat
81. f their choice for their final projects which is expected to help them expand the scope of their projects and give them more freedom to realize their creative design concepts Table of Contents Abstract rap piri pni cio Gr nr Fla ao pl X P Ki ae P ORO c RE E ARD KG EAR 1 Executive SummMary e innana anara aa naasia iaat ia maaa aaa aana Aaaa AA Aaea Aana Ta nrinn a aAA iana Nan An aana Nin 2 Table of Contents iioncusociniinrcin ni nada ei ci i c kp On CER EC ERE E E V KR AR 3 IntroductiON smi 4 Issues to be addressed isieinnisinnrinin tain rac a t Da E RE ER RR a 4 Preliminary Research ea Yin as diu e ar EUR QOL D Dr CC a rt oa RC E RN KARRIERE 5 Proposal for Development si ii 7 USB Protocol Basics i cis caccessancencvinecssesssvrersvasueauessuccsntussuedvonssusesctisuauinscunandeisandsausnetustisecadversianeaes 7 PLEGIUS 7 ENuUmeration se t ii e a a a a a a i 8 HD ReBOort e C Attn 8 Vinculum VNC1L Embedded USB Host Controller Cs 9 Hardware VDIPT modules edet Pa ER ERU nn 9 Software VDAP Firmware version 3 69 usn da sivc pedea tal e abe desta dn 11 Firmware Upgrade asrina atata ee a ee Pei aud 11 Command MODIEOE sa ee e nRAA ea SEMI 12 Essential Monitor COMMANGS Ne 14 Serial Communications iioii acer iioi oit Roi Re eiii ai Ro Dr nananana 15 SPD esi a ee Vedi mb pa dU Vi prb SPINE Fr EHE ee 15 USART Se a tut gta eats M a e M xp M M Mes et ote um 18 USB Mass Storage Device 4i niger ince n PR UG ir
82. fer 60 volatile unsigned int time1 timeout counter volatile int test 16 volatile int pre 20 previous key stroke volatile int pre special 20 previous SHIFT CONTROL key stroke the task subroutine void task1 void RRR RR KKK RRR K K K K K KK K K K K K K K KK K KK K K K K K K K K K K timer 0 compare ISR ISR TIM ERO COMPA vect Decrement the time if it is not already zero if time120 timel RRR RRR KK RK A KK RR RR RR RR RR KK KKK A AK KK LCD setup void init Icd void LCDinit initialize the display LCDcursorOFF LCDclr clear the display LCDGotoXY 0 0 CopyStringtoLCD LCD initialize 0 0 system initialization void init_system void LED for debugging LED DDR 1 lt lt LED PIN output LED_D1_OFF turn off LED VNC1L SPI interface setup SPI DDR 1 SCLK PIN 1 SDI PIN 1 CS PIN 1 RE PIN outputs SP DDR amp 1 SDO PIN input init the UART uart_init is in uart c uart_init stdout stdin stderr amp uart_str forintf stdout n r Starting VNCIL USB keyboard test n r crank up the ISRs 61 sei eeceleleieielelelelelelelelelelelelelelelelelerererererererererereerererelelelelelelelelelelelelelelelererererererererererererek List of errors Cekeeelekelejelelelelelelelelelelelelelelelelelelererererererererereererereleleleleleleleleleleleleleleler
83. ffer 0 n reply 7 Directory Not Empty if vnc receive buffer 3 m amp amp vnc receive buffer 2 p amp amp vnc receive buffer 1 t amp amp vnc receive buffer 0 y reply 28 No Disk if vnc receive buffer 3 D amp amp vnc receive buffer 2 i amp amp vnc receive buffer 1 s amp amp vnc receive buffer 0 k reply 9 Here you can check for other error messages No break here After error check prompt check should be done as well case 2 Only Prompt Check if vnc receive buffer 2 O0x5C amp amp vnc receive buffer 1 gt amp amp vnc receive buffer 0 0x0D Test for V Carriage Return is received reply 21 vnc receive_buffer 0 20 Buffer discard delete the last character from the last string if reply gt 2 if vnc wr byte 0x0D return 0 send Carriage Return to confirm error then comes a prompt exit on error if reply break rd answer count TIMEOUT COM M UNICATION Timeout reset Jelse rd answer count if reply reply 99 Timeout return reply 52 J AERE E K KKK K KKK K RK KK K K K K KK EKK K EKK KEK KKK K KK K KEKE K KEK E KEK KK K KKK KKK KKK KKK Kk E NNC1L Waiting for PROM PT If there is an error return the error number Return 0 Prompt received I xx error number from vnc rd answer function Cekeeereeierelelelelelelelelelelelelelelelelele
84. h the device This process of initialization and exchanging information between a host and a slave device is called enumeration During the enumeration a host can assign an address to a device and read all kinds of descriptors from a device Once the enumeration is completed a slave device can be ready to transfer data to a host USB descriptors are data structures that contain information about a device such as interface and endpoints of it They enable a host to learn about a slave device and all USB devices are required to respond to requests for the standard USB descriptors from a host The good news is that VNCIL does execute the process of enumeration in the background for us as soon as it detects a device on its USB port Human Interface Device HID Report It was mentioned above that HID devices such as a USB keyboard or a USB mouse use interrupt transfer to send data to a host through an IN interrupt endpoint the direction of any data transfer is always from a host point of view This data that a device sends to a host is contained in a report which HID devices use to exchange data A report descriptor contains information about the data that is sent and received between a host and a device however the descriptor does not include a report HID class specific requests can be used instead to get a report from a device and send a report to a device For example a report from a USB keyboard 8 can tell a host which key has been pressed
85. har wr cmd unsigned char offset vnc offset length of command for offset 2strlen wr cmd offset offset while UCSR1A amp 1 lt lt UDRE1 0 UDR1 wr cmd wr cmd 5 send carrage return a command to monitor ends with OxOD while UCSR1A amp 1 J DRE1 0 UDR1 0x0D return 0 RR RR RR KKE KK KKK A A KKK KKK K KKE RR RR RA A A A A A EK KKK KK HK VNC1L Receive a string Wait until the monitor returns info from firmware ex Firmware Version Device Detected Return status 0 string was received from VNCIL J IEKE K KK KKK KKK KK KKK K KK K K K KK KKK BE BH IE KKE K EA IE KE KKK KK KK KKK BK KK KE 83 unsigned char vnc wait for VNC1L UART t char count x Wait for VNC1L to respond with firmware version and message if a device is detected for int z20 z 45 z 1 wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 printing in this loop could cause the program to break Il fprintf stdout n r c vnc receive buffer z get the length of the string and it s last character index count strlen vnc receive_buffer 1 for x 0 x count x if vnc receive buffer x r fprintf stdout An vnc receive buffer x fprintf stdout c vnc receive buffer x else fprintf stdout c vnc receive_buffer x return 0 Ceeeeeieierelelelelerelelelelelelelelelel
86. her tasks than communicating with a USB slave device it should be freed from such a huge load since the entire implementation was done in software This fact calls for a hardware implementation of a USB host controller instead of a software implementation In summary the limitations of the previous project mentioned above point to a hardware implementation of a USB host controller using a dedicated IC chip which is VNCIL for this project Preliminary Research To address the main problem of the previous project on implementing a USB host controller we needed a dedicated host chip that could ease the load of M ega1284 According to USB Embedded Hosts by Jan Axelson there are many hardware options available for implementing a USB host in an embedded system as shown in the table below System Type Host Communications Support Embedded PC with host controller Linux or Windows API other protocols supported by the OS and programming environment General purpose microcontroller with on chip host controller Libraries from chip provider Axelson Jan 2011 USB Embedded Hosts M adison WI Lakeview Research LLC 5 External host interface chip plus general Libraries from chip provider purpose microcontroller Processor with on chip host module Vendor specific API Host module with interface to external Vendor specific command set processor Processor with USB host and support for N
87. ile of known length into my str vnc status vnc rd file UART VNCFILES TXT my str file length if vnc status vnc error message vnc status 16 fprintf stdout Echo back n r s n r my str Append a text string to an existing file vnc status vnc_wr_txtfile UART VNCFILE5 TXT file5 0 FILE APPEND if vnc status vnc_error_message vnc status 17 Append a text string to an existing file vnc status 2vnc wr txtfile VNCFILE5 TXT my str FILE APPEND append twice for some reason my str seems to cause the problem if vnc status vnc fehlermeldung vnc status 17 Append a text string to an existing file vnc status vnc_wr_txtfile UART VNCFILE5 TXT my text FILE APPEND if vnc status vnc error message vnc status 17 CopyStringtoLCD LCD success 0 1 81 fprintf stdout An rDone nr If you reached here then no error has occured LED blinks every second main task scheduler loop while 1 LED D1 ON delay ms 1000 1 sec LED D1 OFF delay ms 1000 fimware h kkk kk kk kk kk kk define LED PIN 0 define LED PORT PORTB define LED DDR DDRB define RTS DDR DDRA define RTS PORT PORTA define RTS PIN 0 define CTS DDR DDRA define CTS PORT PORTA define CTS PIN 1 RRR RRR RR KK KKK KKK RR KK K EE K K EE KK KR RR K K K KK K K K K K K K K KK K K K K KKK k
88. in which they were pressed This causes the parsing of a report to 27 be very difficult and it was observed that one keystroke was often mistaken as repeated keystrokes Therefore only the polling method is recommended for the projects for a keyboard and a mouse Pin Name Cable color Description standard A 1 VBUS Red 5V D D 2 D White gold Data Yr 3 D Green Data Prr 4 GND Black blue Ground Figure 15 USB 1 x 2 0 standard pinout One last thing about the projects for a keyboard is that print_keystroke can be modified to return capital letters only when an alphabet key is pressed at the same as a Shift key by checking both the byte for modifying keys Byte 0 and the byte for a keycode Byte 1 in an IN report In a similar way print keystroke can be expanded for other keys such as function keys Many USB devices were tested with both SPI and USART interfaces on their compatibility with the VNCIL Although the documents from USB IF clearly state which USB protocols or standards apply to all USB devices regardless of manufactures or vendors the test results of this project prove it to be not true For example according to the Table 4 the bitmap of an OUT report 0x07 used for a set report request to a keyboard should enable the M CU host to turn on all three LED lights on a keyboard However 0x07 turns only two LEDs on a keyboard made by HP while 0x70 turns on all LEDs on a keyboard made by Logitech Also ou
89. irst occurance of starting from LSB file length 2str to int UART start convert hex string to a number currently up to 64k bytes return 0 0 2 OK VNC1L Generating a binary file on a USB drive It can also write a text file Maximum file length 64 kByte Parameters file name Address of file name Il file content Address of data block Il file length nnumber of bytes Return 0 OK Cekeekeereierelelelelelelelelelelelelelelelelelerererererererererereerererelelelelelelelelelelelelelelerererererererererererererek unsigned char vnc wr binfile UART char file name char file content unsigned int file length unsigned int vnc i 0 unsigned char wr_steps 0 unsigned char status 0 if file length OXxFFFF return 51 error file is too long open a file sprintf amp vnc send buffer 0 OPW 96s file name status vnc wr cmd UART vnc send buffer status vnc prompt check UART Data is usually appended to the end of an existing file or a new empty file is created if it doesn t exist SEK command move to an arbitrary point in a file status vnc wr cmd UART SEK 0 status vnc prompt check
90. is detected vnc status vnc wait for VNC1L UART if vnc status vnc error message vnc status 5 run IPA command before running ECS command Monitor commands in ASCII IPA mode vnc status vnc_wr_cmd_UART IPA if vnc status vnc_error_message 1 5 error command was not accepted by VNC1L vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 5 Extented Command Set vnc status vnc_wr_cmd_UART ECS 79 if vnc status vnc error message 1 4 error command was not accepted by VNCIL vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 4 monitor returns prompt if command executed correctly Display firmware version vnc status vnc wr cmd UART FWV if vnc status vnc error message 1 6 error command was not accepted by VNCIL print firmware version returned by VNC1L and prompt check vnc status vnc firmware UART fprintf stdout n rType something fscanf stdin n s n r my text An allows user to type multiple words separated by a space fscanf stdin n s n r my text An allows user to type multiple words Separated by a space Write text file 1 to USB disk vnc status vnc wr txtfile UART VNCFILE1 TXT file1 0 FILE NEW if vnc status vnc error message vnc status 8 Write text file 2 to USB disk vnc sta
91. le5 M acGyver left the building He ain t coming back n r a x char file buffer FILE BUFFER SIZE buffer for testing unsigned int file length byte length of a file for reading volatile char my text 50 volatile char my str 50 volatile char read str 50 RRR RRR RRR RAK K K K K K KK K K K K K K K KK K K K K K K K K K K K K K K K K K LCD setup void init Icd void LCDinit initialize the display LCDcursorOFF LCDclr clear the display LCDGotoXY 0 0 CopyStringtoLCD LCD initialize 0 0 77 system initialization void init_system void LED for debugging LED DDR 1 lt lt LED PIN output LED_D1_OFF turn off LED 8 bit no parity asynchronous UART 1 stop bit UCSR1C 1 UCSZ11 1 lt lt UCSZ10 init the UART uart init is in uart c uart_init uart_init1 stdout stdin stderr amp uart str fprintf stdout n r Starting VNC1L USB drive UART test n r RR RR RR RR RA RK AK A AA RR OR RR RR KA A A A A A A AK KKK KK AK List of errors RRR RR RR RR OR AR ER HOR RK A EE EE AK E E KK KKK KK KKK II 1 Command was not accepted by VNCIL II 2 Command Failed 3 Bad Command Il 4 Disk Full ll 5 Filename Invalid Il 6 Read Only II 7 File Open Il 8 Directory Not Empty Il 9 No Disk ll 20 No VNCIL with VDAP firmware available II 21 No USB drive plugged II 50 Buffer is too small to read a file b
92. many students could have benefited and made their programs more flexible or sophisticated if they could use an HID class device such as a USB keyboard or a USB mouse as a user input device Also adding a USB mass storage in a project could solve the problem of M ega1284 s limited memory resources that hinders developing a memory intensive project From my experience as a previous student of the class having an option to have a microcontroller as a host to control USB slave devices with a fast and easy interface can allow students to broaden the scope of the design of their final projects or come up with more creative systems believed choosing a right USB host controller IC chip that could be easily interfaced with M ega1284 and came with firmware fully supported by a manufacturer would be a key to the success of this design project This consideration led us to choose a VDIP1 module with a VNCIL chip from FTDI Future Technology Devices International Ltd as a winner Issues to be addressed The previous project Software Implemented Atmel M ega32 Universal Serial Bus Host Controller by Ben Hutton Devrin Talen and Chris Leary was a successful final project for the ECE 4760 class However with its shortcomings it cannot fully address the needs of students who would like to use a USB device in their final projects without having to learn the much complicated USB protocols Below is the list of problematic issues that the previous software im
93. mware comes with M onitor Command Set that covers various commands for different categories For this project mainly M onitor Configuration Commands Disk Commands and USB Device Commands were used Here is a list of commands that are used Extended Command Set Function Monitor Configuration Commands ECS Extended Command Set Switches to the extended command set IPA M onitor M ode ASCII Monitor commands use ASCII values FWV Firmware Version Display firmware version Disk Commands DIR file Directory List specified file and size OPW file Open File for Write Open a file for writing or create a new file SEK dword Seek Seek to the byte position specified by the 1 parameter in the currently open file WRF dword Write to File data Write the number of bytes specified in the 1 parameter to the currently open file CLF file Close File Close the currently open file OPR file Open File for Read Open a file for reading RDF dword Read From File Read the number of bytes specified in the 1 parameter from the currently open file USB Device Commands QP2 Query Port Query port 2 QD byte Query Device Query device specified in the 1 parameter 14 SC byte Set Current Set device specified in the 1 parameter as the current device SSU qword Device Send Setup Send setup data to device control endpoint with
94. nd message if a device is detected vnc status 2vnc wait for VNC1L UART if vnc status vnc error message vnc status 5 112 run IPA command before running ECS command Monitor commands in ASCII IPA mode vnc status vnc wr cmd UART IPA if vnc status vnc error message 1 5 error command was not accepted by VNC1L vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 5 Extented Command Set vnc status vnc_wr_cmd_UART ECS if vnc status vnc_error_message 1 4 error command was not accepted by VNC1L vnc status vnc prompt check UART check if monitor returns prompt if vnc status vnc error message vnc status 4 monitor returns prompt if command executed correctly Display firmware version vnc status vnc wr cmd UART FWV if vnc status vnc error message 1 6 error command was not accepted by VNCIL print firmware version returned by VNC1L and prompt check vnc status vnc firmware UART Query port 2 for HID vnc status vnc wr cmd UART QP2 if vnc status vnc error message 1 7 error command was not accepted by VNC1L print device class and prompt check vnc status vnc query port UART Query Device vnc status vnc wr cmd UART QD 0 if vnc status vnc error message 1 8 error command was not accepted by VNC1L vnc status vnc query device UART Set current devic
95. ned char offset vnc offset length of command for offset 2strlen wr cmd offset offset while UCSR1A amp 1 lt lt UDRE1 0 UDRI wr cmd wr cmd 4 5 send carrage return a command to monitor ends with 0x0D while UCSR1A amp 1 UDRE1 0 UDR1 0x0D return 0 J EAK KK KKK KKK KK KK KKK K KKK KK KK K KEE KKK KKK KKK K RR EEE EEK K K KEKEKE KKE K KEKEKE VNC1L Receive a string Wait until the monitor returns info from firmware ex Firmware Version Device Detected Return status 0 string was received from VNCIL EERE K KKK KK KK K KKK KK KK K KKK KKK K KEK KKK KKK KKK KKK KK KEE E EKEK KKK KK KKK KK K KKE KEE unsigned char vnc_wait_for_VNC1L_UART char count x Wait for VNC1L to respond with firmware version and message if a device is detected for int z 0 z 44 z wait until a byte has been received while UCSR1A amp 1 lt lt RXC1 0 vnc receive buffer z UDR1 printing in this loop could cause the program to break Il fprintf stdout n r c vnc receive buffer z get the length of the string and it s last character index 117 count strlen vnc receive buffer 1 for x 20 x count x i if vnc receive buffer x r fprintf stdout An vnc receive buffer x fprintf stdout c vnc receive buffer x else fprintf stdout c vnc receive_buffer x return 0 RRR RR RR RR RK KA A AA RR OR RR RR
96. nt ports other than Port A can be used for SCLK SDI SDO CS and Re by modifying firmware h The LCD library designates Port C for an LCD display however this can be changed to other ports by modifying lcd lib h 4 It is highly recommended that the USART channel 0 of the M CU to PuTTy is used to print the status including a prompt DA of the Command M onitor and vnc receive buffer that contains data received from the USB device through the M onitor 5 For the UART interface for the USART channel 1 of the M CU to be utilized uart1 c and uart1 h should be added to the project folder along with uart c and uart h for the USART channel 0 6 For the UART interface either the CTS pin from the VDIP1 has to be physically pulled down to GND or CTSz and RTS pins from the VDIP1 have to be tied together because the flow control is not used in this project 7 To switch from the Command M ode to the Data M ode VNC1L DATAREQ Zfrom the VDIP1 should be pulled down to GND One output pin from the M CU can pull DATAREQ down just before the MCU starts polling a report from a slave device connected to the VDIP1 Additionally DATAACK from the VDIP1 can be observed to see if the VNCIL has switched to the Data M ode when DATAACK is asserted low by the VNCIL this is optional Data M ode is used only for a USB keyboard and a USB mouse 8 Polling every 50ms for both a keyboard and a mouse works fine without missing a change in a report from the devic
97. of APIs that a host uses to communicate with HID human interface device and mass storage class peripheral devices The hardware implementation can be used by students in ECE 4760 to run a mouse a keyboard and a memory stick This will allow students to easily attach peripherals such as a mouse to their final project without having to use a host computer Executive Summary This USB Host Controller for a M icrocontroller project was proposed and is created specifically for the use in ECE 4760 class The project is designed to create a useable USB host interface to M ega1284 using a dedicated chip VNCIL on its development module VDIP1 Compared to a similar previous project the solution of which takes an approach in software this project is done in hardware to unload the microcontroller The first and direct beneficiaries of the final product of this project would be the students in ECE 4760 who are expected to design a creative and somewhat complicated final project The final product includes the libraries that consist of APIs that an M CU host simply calls to communicate with HID human interface device and mass storage class peripheral devices What enables the mega1284 to be a USB host is the VNCIL chip that is pre programed with its firmware The serial communication part of this project between two chips was implemented both in SPI and USART to give students options to choose All the tasks that are related to USB protocols are performed by
98. ommand executed correctly Display firmware version vnc status vnc_wr_cmd FWV if vnc status vnc_error_message 1 6 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 6 count strlen vnc receive_buffer 1 for x count x gt 0 x if vnc receive_buffer x r fprintf stdout n vnc receive_buffer x fprintf stdout c vnc receive_buffer x else fprintf stdout c vnc receive_buffer x if x 0 break To print what monitor returns fprintf stdout n r s n r vnc receive_buffer note All output from the command monitor is LSB first If monitor return multiple lines of data they are followed by carriage return which overwrites a previous line on fprintf 64 Query port 2 for HID vnc status vnc_wr_cmd QP2 if vnc status vnc_error_message 1 7 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 7 monitor returns prompt if command executed correctly fprintf stdout n r s n r vnc receive buffer Query Device vnc status vnc_wr_cmd QD 0 if vnc status vnc_error_message 1 8 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc
99. or FWV command is optional because when the VNCIL is powered up it always sends out information on the version of firmware that is installed on it as mentioned above Any string of text to be written to a file should end with a because it is an identifier for the end of text a is chosen so that a user is allowed to input a string of characters including spaces through PuTTy to be written to a file in a USB drive Before calling vnc rd file or vnc rd file UART to read a file vnc rd dir or vnc rd dir UART must be called first to find out the length of the file to be read with the DIR command because the monitor command RDF is used with a parameter for the number of bytes to be read When vnc wr txtfile or VNC wr txtfile UART is called it sends OPW SEK WRF and CLF commands in order to the monitor Likewise when vnc rd file or vnc rd file UART is called it sends OPR SEK RDF and CLF commands in order to the monitor After executing any monitor command before the next one can be sent to the monitor checking for a prompt D gt from the monitor needs to be done first A prompt must be read otherwise the program will stop running because the monitor will not be ready for another command 22 USB HID Device Keyboard A USB keyboard can be a popular choice as an input device for many projects M aking mega1284 a USB host over a USB keyboard as a slave was implemented using both SPI and USART interface to the VNC1L
100. or to see a prompt D has been received from the USB Stick am M ikrocontroller project from www mikrocontroller net 21 monitor which indicates that a command executed successfully In VNC1L USB UART vnc prompt check UART itself checks for a prompt In VNC1L USB drive the SPI status bit can be checked to see if the received data on the M CU side is an old one or a new one to decide whether there is any more data to be received or not In VNC1L USB UART for the program not to hang at while UCSR1A amp 1 RXC1 0 tested constants are hard coded in the most of for loops that include while UCSR1A amp 1 lt lt RXC1 0 These constants present the number of bytes that the monitor returns such as USB protocol related information on a device or a version of firmware installed on the VNC1L There is a list of things that apply to both projects as well First before the M CU can access a USB drive some housekeeping procedure should be done Once the VNCIL is powered up it will send messages to the monitor port regarding a version of the firmware installed on the chip and a confirmation that a USB device has been detected These messages should be received and verified before any firmware commands can be sent to the monitor For the better user interface and the easier parsing of data received from the monitor the VN1Lis set in the Command M ode and the ASCII mode by sending the commands IPA and ECS to the monit
101. ould be mounted for UART along with other port pin configurations ADS 13 fg amp AD5 AD7 EJ AD4 ACO D E AD3e CS PAG AC1 9 E AD2 SDO PAS AC2 EJ AD SDI PA4 GND 6 E GND m AC3 e ADO SCLK PA3 ACA Lj a U1M AC5 7 U1P RE PA7 RS EJ E LD2 PG amp e LD1 3V3 24 R7 amp SVO e from MCU Figure 10 VDIP1 on board jumper pin configuration and port connections to M CU for SPI USART Universal Synchronous Asynchronous Receiver Transmitter USART that sends multiple bits of data over a single wire is commonly used for communication between a microcontroller and various other devices UART which is of asynchronous serial communication does not require a common clock signal at both a transmitter and a receiver for synchronization of data detection Instead it uses a start bit and a stop bit that are added to the data byte M ega1284 conveniently comes with two channels of USART This allows us to use the first channel channel 0 on Port DO RX0 and Port D1 TX0 for communication between a running program and a PCthat runs PuTTy for debugging purposes and printing the status of Excerpted from VDIP1 datasheet on page 4 18 the program execution The second channel channel 1 on Port D2 RX1 and Port D3 TX1 can be used for communication between mega1284 and VNCIL To utilize the second channel of USART the registers that correspond to USART channel 1 should be set up correctly in the m
102. plementation carries e The previous project was implemented for M ega32 which is a much older chip with the less resources available compared to M ega1284 which is currently used in ECE 4760 Although believe the libraries can be exported to be used by M ega1284 the project 4 implements only a low speed 1 5 M bps USB 2 0 compliant host controller and it needs to be updated As the authors of the project state the libraries were tested only with a USB mouse and if a student wants to use other USB slave devices such as a USB keyboard or a USB flash drive he or she needsto write some sort of storage driver such as FAT32 themselves which could be a daunting task for students who are not familiar with complex USB protocols Students who want to use a USB device for their project should not need to have a comprehensive knowledge of complicated USB protocols Preferably an extensive library of API application programming interface functions for each popular USB class HID and mass storage should be provided for students so that their program could access USB slave devices by simply calling those API functions without having to know the details of what is done in a driver file e The example M ouse Driver code from the previous project shows that how communication between a USB host and a USB slave is done at a very low level which is translated as a huge load on a microcontroller For a microcontroller to be able to perform many ot
103. printing here could cause the program to break fprintf stdout n r c vnc receive buffer count prompt received if vnc receive buffer count 2 0x0D DA 85 if vnc receive_buffer count 1 gt amp amp vnc receive buffer count 2 0x5C amp amp vnc receive buffer count 3 amp amp vnc receive buffer count 4 D return 0 count rd_count return 1 no prompt timeout II HR KK KK KK KK KK KKK RK KK E E E KKK KKK KK E E E KKK E E E E E E K K KE K K K OK K K KK kK K kK KKK VNC1L Creating a text file on a USB drive Maximum file length 64 kByte Parameters file name address of file name Il file content address of text block to be written II option File 0 new or 1 append content Return 0 OK II HR KK KKK KK KK KK KKK KK E E E KK KK E E E een E E E KKK KKK E E KK KE K K K K K K KK kK K kK KKK unsigned char vnc wr txtfile UART char file name char file content char option unsigned int vnc i 0 unsigned int file_length 0 unsigned int file CR 0 carriage return char file_ptr unsigned char wr_steps 0 unsigned char status 0 calculate number of bytes file_ptr file_content file_length 0 file CR 0 while file ptr a a is an identifier for the end of text if file ptr file length 4 else file CR44 file ptr open a file sprintf amp vnc send buffer 0 OPW 96s file name 86 status vnc wr cmd UAR
104. r_cmd IPA if vnc status vnc_error_message 1 5 by VNCIL vnc status vnc prompt check prompt if vnc status vnc error message vnc status 5 Display firmware version vnc status vnc_wr_cmd FWV if vnc status vnc error message 1 6 by VNCIL vnc status vnc prompt check prompt if vnc status vnc error message vnc status 6 List files in current directory vnc status vnc wr cmd DIR if vnc status vnc error message 1 7 by VNCIL vnc status vnc prompt check prompt if vnc status vnc error message vnc status 7 To print what monitor returns fprintf stdout n r s n r vnc rec buffer note All output from the command monitor is LSB first error command was not accepted check if monitor returns error command was not accepted check if monitor returns error command was not accepted check if monitor returns If monitor return multiple lines of data they are followed by carriage return which overwrites a previous line on fprintf Write text file 1 to USB disk vnc status vnc wr txtfile VNCFILET TXT file1 0 FILE NEW 41 if vnc status vnc error message vnc status 8 Write text file 2 to USB disk vnc status vnc_wr_txtfile VNCFILE2 TXT file2 0 FILE NEW if vnc status vnc error message vnc status 9 Append text string to existing text file 1 vnc status vnc_wr_txtfile VNCFILE1 TXT file3 0 FILE APPEND i
105. rererererererererereerererelelelelelelelelelelelelelelerelerererererererererererek unsigned char vnc prompt check void unsigned char status 1 status 2 status 1 vnc rd answer PROMPT AND ERROR CHECK if status 1 1 return 0 Prompt was received no previous error command was executed Error occurred now just waiting for prompt but confirming error status 2 vnc rd answer PROM PT CHECK if status 2 1 return status 1 return status 2 no Prompt Timeout JEEE K KKK K KKK KKK KKK KKK KKE KK KKK K KE KKK KK KKE K KKK KRE KE KE KKK KK KK KKK KE KEEKEKE KE VNC1L Creating a text file on a USB drive Maximum file length 64 kByte Parameters file name address of file name Il file content address of text block to be written hl option File 0 new or 1 append content Return status error number 0 OK JEER KEREKE KK KEREK KKR KEKEE E E EEEE E EREEREER KEEK KERKEE EE KERE KEREKE KEKEKE KEEK unsigned char vnc wr txtfile char file_name char file content char option unsigned int vnc i 0 unsigned int file_length 0 unsigned int file CR 20 carriage return char file_ptr unsigned char wr_steps 0 unsigned char status 0 calculate number of bytes file_ptr file_content 53 file length 0 file CR 0 while file ptr a Na is an identifier for the end of text if file ptr file length 4 else file CR44 file_ptr do if wr_steps 4
106. return 0 unsigned char print_keystoke char key_pressed switch key_pressed case KEY 0 return 0 case KEY 1 return T case KEY 2 return 2 case KEY 3 return 3 case KEY 4 return 4 case KEY 5 return 5 case KEY 6 return 6 case KEY 7 return 7 case KEY 8 return 8 case KEY 9 return 9 case KEY A return A case KEY B return B case KEY C return C case KEY D return D case KEY E return E case KEY F return F 107 case KEY G return G case KEY H return H case KEY I return I case KEY J return J case KEY K return K case KEY L return L case KEY M return M case KEY N return N case KEY O return O case KEY P return P case KEY Q return Q case KEY R return R case KEY S return S case KEY T return T case KEY U return U case KEY V return V case KEY W return W case KEY X return X case KEY Y return Y case KEY Z return Z case KEY ENTER return amp case KEY SPACE return 108 case NO KEY PRESSED return default return 6 VNC1L mouse UART polling Jokooolcroleoeob eeecece YNC1L mouse UART c eeeeeexcexeeereteretereie Original project by Matthias Kahnt az51 gmx net Modified by Terry Young Kim ATmegal1284 VNC1L VDIP1 Vinculum Port2 VNCIL USB HOST CONTROLLER M ega1284 M aster VNCIL Slave VDAP firmware version 3 69 USART interfac
107. rst for bit pos 20x80 bit pos bit pos 22 1 if SDO_VNC data bit pos store data bits SCLK H SCLK_L read status status SDO VNC Status bit 0 New Data 1 Old Data SCLK_H SCLK_L End sequence CS VNC L SPl Interface inactive SCLK_H SCLK_L if status received character is a new character make room in the vnc receive_buffer for new data received for bit_pos VNC_BUFFER_SIZE 1 bit_pos bit_pos vnc receive_buffer bit_pos vnc receive_buffer bit_pos 1 vnc receive buffer 0 2data new charater is store in the first spot of the buffer backwards ifdef USART MONITORING if rd_byte fprintf stdout c vnc receive byte 0 endif ifdef LCD M ONITORING if Ird byte sprintf lcd buffer s vnc receive byte 0 LCDGotoXY 0 0 LCDstring lcd buffer strlen lcd buffer endif si 47 count if status delay us 150 pause if there is not a new byte while status amp amp count return status J EE KKK KKK KKK A RR RR RR K KKK KKK EK K A KOR RR OK RRR RK KK KK KKK VNCIL Sending a character Parameter wr byte character to be output Return status 0 2Accepted OK 1 2 Not accepted by VNCIL X Ceeeelekelelelelelelelelelelelelelelelelerelelerererererorerererereereleleleleleleketerererereielelelelelelelelelelelelelelelele unsigned char vnc wr byte unsigned char wr byte unsigned char status unsign
108. rt if necessary status 0 match index 0 buff index 0 length strlen wr string if length gt 12 length 212 length limit while rd answer count amp amp length match_index status vnc rd byte if status Anew character is now available buff index 0 match index 0 for i 20 i length i if vnc receive buffer length i wr string i match index4 match buff index44 rd answer count TIM EOUT COMMUNICATION reset timeout count else rd answer count if status match_index length return 1 error string is not received return 0 String was received OK II PEE EE KKK E E E E E E KKK E E KK K KE K K KK K K K K EK K K K K K K KK K K KK KKK KK KK KK K KKK KK KK KK VNC1L Wait for response string and parse it The last 4 digits of the answer are significant possibly expand it Parameter buffer check II 1 Testing for prompt and error messages 50 II 2 Testing only for prompt Return reply II 1 Prompt received 2 Command Failed received Il 3 Bad Command Il 4 Disk Full ll 5 Filename Invalid Il 6 Read Only ll 7 File Open Il 8 Directory Not Empty Il 9 No Disk 99 Timeout II DKK KK KK KK KK KK KK KK KK KK cepe KK KK KK KK KK KK eee KK OK OK KK OK OK OK OK KOK OK KK KK OK OK OK KKK KKK KKK unsigned char vnc_rd_answer unsigned char buffer_check unsigned char reply unsigned char status unsigned int rd answer count
109. same way The basic housekeeping procedure which is the same as the one for a USB drive and a USB keyboard is done at the beginning of the program Also as for a keyboard QP2 and QD commands are sent to the monitor to confirm that a mouse is recognized as an HID device The M CU sends the SD command to the monitor that all class specific requests that the host makes will be routed to a USB mouse attached to the VDIP1 on Port 2 The SSU command is used the same way to get a report from a mouse and set the idle time to indefinite as for a keyboard Only difference is that a report from a USB mouse is of 4 bytes when a report from a USB keyboard is of 8 bytes Also the host cannot make a set report request to a mouse since 1 Excerpted from USB Keyboard Using MSP430 Microcontrollers by Texas Instruments 3 Excerpted from Using USB Keyboard with an Embedded Host by Microchip Technology Inc 25 there is no component on a mouse that an external source should manipulate unlike LED lights on a keyboard The structure of an IN report from a mouse is shown in the next figure The bit for Button middle is set to 1 when a wheel on a mouse is clicked instead of being scrolled Byte 1 and Byte 2 are Xand Y coordinates of the position of a mouse The value in Byte 3 either increases or decreases as the wheel on a mouse is scrolled up and down Both a button click and a change in the position of a mouse can be reported to the host in the same IN report
110. t A amp amp value lt F value value 0x07 normalize hex based if value lt 0 value gt error 21 error temp position 1 value 0x30 mid byte string to a number subtract 0x30 from a character 0 9 mid byte 4 next lower 4 bits out of a byte value value if temp 1 0 temp 0 0 error 1 error gt 16 bit if error 1 value 16 20x00 No response necessary via buffer temp 2 20 temp 3 20 return temp 2 256 temp 3 FEJ AAR KK KKK KKK K KKK K KKK K KKK K K EK K K EEEE KKK KK K K E K KEK KKE KEE E EKK KKK K KKK KE KK KE EKE VNC1L DIR determines file length Maximum 64 kByte Parameters file name Address of file name II file_content Address of the intermediate stores temporary use l file length Address of the length of the file to be played back Return status error number 0 OK ERREK EK K KKK K KKK K KKK K KEKE E EEEE E FE EE KKK K EEEE K KEK K EEE KEKEKE E EEEE EEEE EEKE KEK KK unsigned char vnc rd dir char file name char file content unsigned int file length unsigned char status 0 unsigned int buff_index 0 char start Address of hex strings beginning sprintf amp vnc send buffer 0 DIR s file name if vnc wr cmd vnc send buffer return 1 Error command was not accepted Response string to DIR is read status vnc rd answer PROM PT AND
111. t of three USB keyboards that are tested only one keyboard made by Logitech responded to get report requests Thus included here is the list of devices that shows which ones work with VNCIL and which ones do not USB flash drive SanDisk 16 GB FAT 32 file system Works Cruzer mini 1GB FAT 32 file system Works Cornell ECE unknown vendor 2 GB FAT file system Works Unknown manufacturer 256 MB FAT 32 filesystem Works USB keyboard Logitech Model Y UR83 Works HP Model SK 2885 Does not work DELL Model SK 8115 Does not work USB mouse Copied from Wikipedia on Universal Serial Bus 28 DELL Model M 056U0A Work Logitech Model M U0007 Work except for scrolling the wheel GE Model unknown Does not work Unknown manufacturer Model unknown Does not work Table 5 Compatibility of the tested USB devices with VNCIL The next is a picture of the entire system for this project It includes a mega1284 board with a serial port an LCD display and a VDIP1 module The second picture is the screen shot of PuTTY with the outputs from the VNC1L when a keyboard is connected to it Picture 2 A screenshot of PuTTy with a USB keyboard connected to the VDIP1 29 Conclusions This project delivers three main sets of libraries of APIs for each type of USB peripheral devices a USB flash drive a USB keyboard and a USB mouse as specified in the
112. te is not received return 0 byte is received RRR RR RR RRR KK A A A RR RR RR RR RA A A A A A A AK KKK KK AK VNC1L Sending a command Parameter wr_cmd command address Return status 0 OK 1 command not accepted by VNCIL RRR RR RRR RR KAKA A A RR RR RR RA A EK KK KKK HK unsigned char vnc_wr_cmd char wr_cmd unsigned char offset vnc_offset length of command for offset 2strlen wr cmd offset offset if vnc_wr_byte wr_cmd return 1 error overflow command was not accepted wr_cmd send carrage return a command to monitor ends with OxOD if vnc wr byte 0xOD return 1 error overflow command was not accepted return 0 J AERE K ERKKA K KK KKK KK KKK KKK E E K EKEK KKK KEE REKKE RE EE EEE KKK EEKE EKE ERE EE EEE VNC1L Receive a string Wait until the monitor returns info from firmware ex Firmware Version Device Detected Last 12 digits are significant Parameter wr string String address Return status 0 0K 1 string was not received from VNCIL RRR RR RR RA KK A A A A RR RR RR RR RA A A A A A AK KK KKK HK unsigned char vnc_wait_for char wr_string 49 unsigned char length String length Offset unsigned char match index number of matches unsigned char buff index Buffer index unsigned char i unsigned char status unsigned int rd answer count rd answer count TIM EOUT COMMUNICATION TIMEOUT error abo
113. the mediator VNCIL instead of mega1284 To send data to a slave USB device and to receive data from it the M CU host simply makes appropriate API calls and communicates with the device through the command monitor interface of the VNCIL The bulk of this project is getting familiar with the firmware its monitor commands and their operations Mainly three libraries were created for three different types of popular USB devices a flash drive a keyboard and a mouse Also each library was implemented twice one with SPI and the other with USART interface Each library comes with unique APIs in a firmware c file where the appropriate firmware commands are sent to the monitor to control the actions of a device and the response data from a device is parsed to determine the status of events that happened within the device With a VNCIL a USB flash drive can be used for a microcontroller project to provide additional memory and eliminate the limit of memory resources available to an M CU A data logging program could well utilize a USB drive to save enormous amount of data A USB keyboard as a user input device can provide many more options than a pushbutton or a keypad with only a few keys available on it A USB mouse can be a perfect choice as an input and control device for game projects or draw and paint projects Without the broad knowledge in the much complicated USB protocols students in ECE 4760 will be able to easily include a USB peripheral device o
114. tring and it s last character index count strlen vnc receive buffer 1 for x count x gt 0 x if vnc receive buffer x r fprintf stdout An vnc receive buffer x fprintf stdout 9oc vnc receive buffer x else fprintf stdout c vnc receive buffer x if x 0 break run IPA command before running ECS command Monitor commands in ASCII IPA mode vnc status vnc_wr_cmd IPA 71 if vnc status vnc error message 1 5 error command was not accepted by VNC1L vnc status vnc prompt check check if monitor returns prompt if vnc status vnc error message vnc status 5 Extented Command Set vnc status vnc_wr_cmd ECS if vnc status vnc_error_message 1 4 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 4 monitor returns prompt if command executed correctly Display firmware version vnc status vnc_wr_cmd FWV if vnc status vnc_error_message 1 6 error command was not accepted by VNC1L vnc status vnc_prompt_check check if monitor returns prompt if vnc status vnc_error_message vnc status 6 count strlen vnc receive_buffer 1 for x count x gt 0 x if vnc receive buffer x r fprintf stdout An vnc receive_buffer x fprintf stdout c vnc receive_buffer x else fprintf stdout c vnc r
115. tus vnc wr txtfile UART VNCFILE2 TXT file2 0 FILE NEW if vnc status vnc error message vnc status 9 Append text string to existing text file 1 vnc status vnc wr txtfile UART VNCFILE1 TXT file3 0 FILE APPEND if vnc status vnc error message vnc status 10 Write a binary bin file to disk vnc status vnc wr binfile UART VNCFILE3 BIN file4 80 file length 280 if vnc status vnc error message vnc status 11 Before reading a file you must get the length of it vnc status vnc rd dir UART VNCFILE2 TXT amp file length 12 file name length 12 if vnc status vnc error message vnc status 12 Now the file length is saved in file length if vnc status Read a text file of known length into file_buffer 80 vnc status vnc rd file UART VNCFILE2 TXT file buffer file length if vnc status vnc error message vnc status 13 fprintf stdout n r s n r file buffer Write text file 5 to disk vnc status vnc_wr_txtfile UART VNCFILE5 TXT file5 0 FILE NEW if vnc status vnc_error_message vnc status 14 Write text file 5 to disk using user input string vnc status vnc_wr_txtfile UART VNCFILE5 TXT my text FILE NEW if vnc status vnc error message vnc status 14 Get the length of file vnc status vnc rd dir UART VNCFILE5 TXT amp file length 12 if vnc status vnc error message vnc status 15 if vnc status Read a text f
116. uffer overflow II 51 File length 0 or gt 64kByte 99 Timeout JS EEKE KK KK KKK K K KKK KKK K KKK KK EE K K EEK KKK KK KK KK K KKK KEEFE EK KKK K KKK KKK KK K KKK KEE void vnc error message unsigned char error type unsigned char error num LED D1 ON LED turns on if there s an error fprintf stdout n rError type d Error number d n r error type error num error occured while 1 error keeps the system hanging 78 II KKK K KKK K K KKK K K KKK K K K KK KK K K KK K K K K K K KK K K KK K K KK K K KK K K KK KKK K K K KKK KKK K K K K Main program II KKK K KKK K K KKK K K KKK K K K KK KK K K KK K K K KK K K K K K KK K K KK K K KK K K KKK KKK K K KKK KKK K K K K int main void init_system start the LCD init Icd LCDclr put some stuff on LCD CopyStringtoLCD LCD VNCLL 0 0 start at char 0 line 0 CopyStringtoLCD LCD mega1284 0 1 start at char 0 line 1 my text 47 n my text 48 r my text 49 a a marks EOF end of file Regardless of the size of a buffer the last character of the buffer should be a To print what monitor returns fprintf stdout n r s n r vnc receive buffer note All output from the command monitor is LSB first If monitor return multiple lines of data they are followed by carriage return which overwrites a previous line on fprintf Wait for VNC1L to respond with firmware version and message if a device
117. us vnc error message vnc status 17 Append a text string to an existing file vnc status vnc wr txtfile VNCFILE5 TXT my str FILE APPEND append twice for some reason my str seems to cause the problem if vnc status vnc fehlermeldung vnc status 17 Append a text string to an existing file vnc status vnc_wr_txtfile VNCFILE5 TXT my text FILE APPEND if vnc status vnc error message vnc status 17 If you reached here then no error has occured LED blinks every second USB drive can be removed while 1 LED D1 ON delay ms 1000 1 sec LED D1 OFF delay ms 1000 fimware h define LED PIN 0 define SCLK PIN 3 define SDI PIN define SDO PIN define CS PIN define RE PIN NOU A define LED PORT PORTB define SPI PORT PORTA PORTD define LED DDR DDRB define SPI DDR DDRA DDRD define SPI PIN PINA PIND 43 RRR RRR RR KKK KR RK KK K K K K K K EE EK KK KR K K K K K RK K K K K K K KK K K K K KKK k define LED D1 ON LED PORT amp 1 ED PIN L
118. uses Port A for the emulated SPI communication and includes the LCD Port C and UART channel 0 PDO and PD1 libraries that students in ECE 4760 are familiar with and use in class The main program demonstrates how to write and read atext file to and from a USB drive and append text to an existing file by using a string of characters that are input by a user through PuTTy Once the VNC1L USB drive project with SPI worked well for mega1284 VNC1L USB UART project was implemented using the USART interface to give students another option to choose for the choice of serial communication USART channel 1 PD2 and PD3 for RX1 and TX1 without the flow control works fine Although their firmware c files have similar APIs for the same functions there are a few differences between the VNC1L USB drive project and the VNC1L USB UART project e Onlyin VNCIL USB drive vnc init must be called during the initialization process in main to hard reset the VNCIL and have the SPI interface ready e The data that is received from the monitor is saved in a reversed order in VNCIL USB drive and the buffer needs to be printed backwards for readability for a user In VNC1L USB UART however the data from the monitor is saved with a M SB first in the buffer with the index 0 and the buffer can be printed as it is for example to check a firmware version e In VNCIL USB drive vnc rd answer is called in vnc prompt check to check any error messages from the monitor
119. ve buffer BUTTONS NO BUTTON PRESSED buttons if vnc receive_buffer BUTTONS BIT 1 ON fprintf stdout n rLeft click else if vnc receive buffer BUTTONS BIT 2 ON fprintf stdout n rRight click else if vnc receive buffer BUTTONS BIT 4 ON fprintf stdout n rWheel else ll fprintf stdout n rNo movement n r X coordinate if pre_x vnc receive_buffer X_COORDINATE amp amp vnc receive buffer X COORDINATE ZNO M OVEM ENT fprintf stdout n rxX d vnc receive buffer X COORDINATE Y coordinate if pre_y vnc receive_buffer Y_COORDINATE amp amp vnc receive buffer Y COORDINATE NO_M OVEM ENT fprintf stdout n r Y d vnc receive buffer Y COORDINATE wheel rotation if pre wheel 2vnc receive buffer WHEEL COORDINATE amp amp vnc receive buffer WHEEL COORDINATE ZNO M OVEM ENT fprintf stdout nr Wheel d vnc receive buffer WHEEL COORDINATE pre vnc receive_buffer BUTTONS pre x vnc receive_buffer X_COORDINATE pre y vnc receive_buffer Y_COORDINATE pre wheel 2vnc receive buffer WHEEL COORDINATE FRR ICR RR KKK firmw are LE KKK KERR KKK KK KKK 115 define LED PIN 0 define LED PORT PORTB define LED DDR DDRB define RTS DDR DDRA define RTS PORT PORTA define RTS PIN 0 define CTS DDR DDRA define CTS PORT PORTA define CTS PIN 1 J RRR RRR KKK IG Ie KKK RK KR KK K K K K K K K K EK KK KR K K K KK K
120. ve buffer count 2 0x0D DA if vnc receive_buffer count 1 amp amp vnc receive buffer count 2 0x5C amp amp vnc receive buffer count 3 amp amp vnc receive buffer count 4 D return 0 count rd count return 1 no prompt timeout RR RR RR KK A AR RR ROR RR RR RA A A A EK KK KKK KK VNCIL Get device class from VNCIL for example 08 amp 00 for HID 119 Return 0 Prompt received Ceekeeereierelelelelelelelelelelelelelelelelelelererererererererereererelelelelelelelelelelelelelelelerererererererererererererek unsigned char vnc query port UART void int z get message from VNCIL and check prompt for z 20 z 13 z wait until a byte has been received while UCSR1A amp 1 RXC1 0 vnc receive buffer z UDR1 Il fprintf stdout n r c vnc receive buffer z count strlen vnc receive_buffer 1 get message from VNC1L and check prompt for z 20 z 13 z for x 20 x count x if vnc receive buffer z r fprintf stdout An vnc receive buffer z fprintf stdout c vnc receive buffer z else fprintf stdout c vnc receive buffer z return 0 Ceeeereeieielelelelelelelelelelelelelelelelelelerererererererererereerererelelelelelelelelelelelelelelerererererererererererererek VNC1L Get USB related info of a device Return 0 Prompt received J EARE KK KK KK KK K
121. vice requests are sent to a USB slave device ET NN bmRequestType Bitmap Characteristics of request D7 Data transfer direction 0 Host to device 1 Device to host 9 Type 0 Standard 1 Class 2 Vendor 3 Reserved 0 Recipient 0 Device 1 Interface 2 Endpoint 3 Other 4 31 Reserved bRequest iw Value Specific request referto Table 8 3 request refer to Table 9 3 wValue Value Word sized field that varies according to request windex 2 Index or Word sized field that varies according to Offset request typically used to pass an index or offset wLength 2 Count Number of bytes to transfer if there is a Data stage Excerpted from Universal Serial Bus Specification 2 0 on page 248 33 2 The format of the Setup packet for Class Specific requests Part Offset Size Bytes bmRequestType 0 1 bRequest 1 1 wValue 2 2 wIndex 4 2 wLength 6 2 Valid values of bRequest field Description Bits specifying characteristics of request Valid values are 10100001 or 00100001 only based on the following description Jg Data transfer direction 0 Host to device 1 Device to host 6 5 Type 1 Class 4 0 Recipient 1 Interface A specific request Numeric expression specifying word size field varies according to request Index or offset specifying word size field varies according to request Numeric expressions specifying number of bytes to transfer in the data phase
122. wo port pins that can be connected to D and D of the second USB A connector D and D are two Data and Data pinouts of a USB port Thus students can add another USB port to VDIP1 with external circuit and a USB type A receptacle although simply replacing VDIP1 with VDIP2 would be much easier How to add the second USB port to VDIP1 and the external circuit configuration is shown in the next figure as a reference Copied from FTDI website 10 Ferrite Bead USBA Connector x USBPort activity LED circuit Figure 3 Additional USB port configuration for VDIP1 Software VDAP Firmware version 3 69 The firmware programed on VNC1L is what makes a VDIP1 module the most attractive solution for this project Just as the Windows API functions magically take care of all complex USB protocol related transactions between a PC host and a USB device the command set of firmware can do the same for a microcontroller host and a USB slave device This unloads the microcontroller and only with the knowledge of the firmware command set students can easily make their M CU a USB host and incorporate a USB slave device in their final project Firmware Upgrade A VNCIL chip ships from the manufacture without being programmed while a VDIP1 module is programed with firmware However they are often shipped with an older version of firmware and it is important that you first check if an upgrade is needed There are two ways to upgrade
Download Pdf Manuals
Related Search
Related Contents
User Manual Manuel d`utilisation Manuale d`uso Manual do Utilizador manual F3 3.0 S Modo de empleo USER MANUAL LL A3 LINE W/N Portable Solar Power Kit(03-05-09) 取扱説明書 TR3-C202-A0-1 リーダライタモジュール Extron electronic HSA 400 User's Manual Copyright © All rights reserved.
Failed to retrieve file