FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Show Posts

You can view here all posts made by this member. Note that you can only see posts made in areas to which you currently have access.

Messages - Yvonne

Pages: [1]
1
Hello,

I kept tried to modified my code and now I can use the modified example code "USBHostHIDKbd" to scan data for the three HID devices (USB reader, barcode scanner and keyboard) mentioned previously. And data can be successfully scanned after plugin, remove and re-plugin. This example code is used based on opening the USBHost driver and attaching the HID driver.

However, I used the example code "USBHostHID2" to try to get the same function previously. In this code, I used the same enumeration function "usbhost_connect_state" as mentioned before. However, I can only scan data at the very first plugin for the HID device. When I remove the HID device and re-plugin another HID device, the enumeration can fail all the time. I wonther that in this usbhost_connect_state function, is it can always get the PORT_STATE_ENUMERATED state during several connection try? or could the state after doing the usbhost_connect_state function always stay in PORT_STATE_CONNECTED or PORT_STATE_DISCONNECTED? (which means I will alway not get ready for enumeration.)

I sometimes see the value of status show in PORT_STATE_CONNECTED and then becomes to PORT_STATE_ENUMERATED after a while in checking this function in both "USBHostHIDKbd" and "USBHostHID2" example codes. May I ask what's the difference between the PORT_STATE_CONNECTED and PORT_STATE_ENUMERATED? In the example code, the if condition only allow the state of PORT_STATE_ENUMERATED to go into reading data process.

I also write another function to get the status of "usbhost_connect_state" until the status become PORT_STATE_ENUMERATED which is shown as follows.
Code: [Select]
status = usbhost_connect_state(hUSBHOST_1);
while (status != PORT_STATE_ENUMERATED) {
                  close_drivers();
          vos_delay_msecs(100);
  open_drivers();

  status = usbhost_connect_state(hUSBHOST_1);
}

If I found my code encounter the situation that the first enumeration could success but the second, third and other enumeration afterwards could fail,  what could be the problem or any debug suggestions are appreciated in advanced!

Thank you so much!

Yvonne

2
Hello,

I am using the VNC2 chip as the USB host to handle HID devices (USB reader, barcode scanner and keyboard) scanning and transmitting data. Based on the example code "USBHostHIDKbd", I use the USBHost Driver and HID Driver in my code. In my code,  I use the "usbhost_connect_state" function to check whether the plugin HID device has completed the enumertaion process and got the status of enumeration become PORT_STATE_ENUMERATED.

The following is my code which is almost the same as the sample function provided in example code:
Code: [Select]
unsigned char usbhost_connect_state(VOS_HANDLE hUSB) {
    unsigned char connectstate = PORT_STATE_DISCONNECTED;
    usbhost_ioctl_cb_t hc_iocb;

    if (hUSB) {
    hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE;
    hc_iocb.get = &connectstate;
    vos_dev_ioctl(hUSB, &hc_iocb);

    // repeat if connected to see if we move to enumerated
    if (connectstate == PORT_STATE_CONNECTED) {
vos_dev_ioctl(hUSB, &hc_iocb);
    }
    }
    return connectstate;
}

I can successfully transmit data on the very first plugin after flashing the .rom file on the VNC2 chip. However, when I remove the first plugined HID device and re-plugin another HID device, the status of enumeration result can not get into PORT_STATE_ENUMERATED. This made the another HID device cannot scan and transmit data.

I look up the Vinculum II User Guide documentation and found another code as follows:
Code: [Select]
unsigned char changeInEnumeration(VOS_HANDLE hUsbHost)
{
    usbhost_ioctl_cb_t usbhost_iocb;
    static unsigned short prev;
    unsigned short i;
    // wait until enumeration change
   
func_count++;

do
    {
        vos_delay_msecs(1);
        usbhost_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_ENUMERATION_HANDLE;
        usbhost_iocb.get = &i;
        vos_dev_ioctl(hUsbHost, &usbhost_iocb);
    } while (i == prev);

    // keep handle for next call
    prev = i;
    return i;
}

When I declare the changeInEnumeration function in my code but not call it in main.c or any other functions, the enumeration works for all the HID devices no matter how many times for plugin, remove and re-plugin. I wonder is the changeInEnumeration function would be called in the background for VNC2 when plugin and remove the HID device? Or any suggestion to solve the enumeration between switches for different HID devices doing plugin and remove process of the HID devices are appreciated.

Thank you so much again!

Yvonne

3
Thank you for your kind reply!
I will try to figure out how to make it work by the help of the document "AN_151 Vinculum II User Guide" mentioned previously.

Anyway, I appreciate your kind reply a lot.
Thank you so mcuh!

Yvonne

4
Hello,

Thank you so much for the kind assistance in the past time thankfully!

I recently want to do the RFID of NFC reader function based on the V2DIP1-32 module which uses the VNC2-32Q IC as being the USB host. I had modified the example codes based on "USBHostHID" and "USBHostHID2" to read data from the HID device of barcode readers successfully. However, when I replace the HID device into the USB RFID reader, it does not work to read ID information from the card scaned by RFID reader. I use the debugger to trace my code, it shows the error code message "USBHOST_NOT_FOUND" when doing function "vos_dev_read".

I wondering that does the VNC2-32Q IC support for all types of HID devices? Or any suggestions for implementing RFID readers with VNC2 USB host are appreciated in advanced!

Thank you so much!
Yvonne


5
Hello,

Thank you so much for your kind reply and information.

I modified the example codes based on folders "USBHostHID" and "USBHostHID2" from the path you provided to do my project.

Thank you so much!
Yvonne

6
Hello,

Thank you for your kind reply. I have had read the return code again in the VNC2 User Guide document.

However, as I need the report id information from hid device in my project, could you give me the instruction that which exmaple code can get the report id info.?

Than you so much!

Yvonne

7
Hello,

I am using VNC2 as usb host controller transmitting data packets scan by barcode scanner.   
I give value 0x06 for bRequest in the SETUP TRANSFER code as shown in follows, however I get error code 0x14 on my IDE as shown in the attached figure. I could not find what 0x14 meant in the USBHost.h library (the values of USBHOST_STATUS are from -1~16). Therefore, what does the error code 0x14 mean? Any suggestion to fix this problem?

Also, I have two barcode scanners. When I use them to scan the barcode and I receive data in 8 bytes for one and 9 bytes for another. I looked up the data in wireshark on windows, the one more bytes one barcode scanner had is the report id. Therefore, I tried to get the "report id" infromation from the setup data. I tried to give 0x06 (GET_DESCRIPTOR) for bRequest and 0x07 (SET_DESCRIPTOR) for bRequest both, but all of the two command values got into error messgae when running code " vos_dev_ioctl(hUSBHOST_1, &hc_iocb)". One of the error message is 0x14.

Alternatively, I tried to attach the hid driver for usb host but cannnot get the correct report id information as shwon in the first data byte of the 9-bytes-based barcode scanner. My goal is that I want to get the correct report id information, or remover it, or set it into zero to let the two barcode scanners receive the same data byte length. Are there any configs I miss or made wrong? Or any suggestions are appreciated in advanced!

The following is part of my code:
////// test 1 /////////   
    desc_dev.bmRequestType = USB_BMREQUESTTYPE_HOST_TO_DEV | USB_BMREQUESTTYPE_CLASS | USB_BMREQUESTTYPE_DEVICE;
    desc_dev.bRequest = 0x06;
         
    hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER;
    hc_iocb.handle.ep = epCtrl;
    hc_iocb.set = &desc_dev;

    status = vos_dev_ioctl(hUSBHOST_1, &hc_iocb);
         
    if (status != USBHOST_OK) {
        break;
    }

    hid_reportid2 = desc_dev.wValue & 0xff;
///////////////////////
/////// test 2 /////////
    desc_dev.bmRequestType = USB_BMREQUESTTYPE_HOST_TO_DEV | USB_BMREQUESTTYPE_CLASS | USB_BMREQUESTTYPE_DEVICE;
    desc_dev.bRequest = 0x07;
    desc_dev.wValue = 0x0200;
            
    hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER;
    hc_iocb.handle.ep = epCtrl;
    hc_iocb.set = &desc_dev;

    status = vos_dev_ioctl(hUSBHOST_1, &hc_iocb);
    if (status != USBHOST_OK) {
        break;
    }

    hid_reportid3 = desc_dev.wValue & 0xff;
///////////////////////

Thank you so much for your kind help!

Yvonne

8
Hello,

I modified the sample code "USBHostHID.c" in project USBHostHID.

In my code, I want to scan data using barcode scanner first and then transmit the scanned data through SPI using VNC2. I wrote barcode scanner and SPI transmission into two functions. Barcode scanner function excutes first then spi function excutes after it. And then go back to barcode scanner function for scanning second data, then spi function for second data, and so on.

I can scan the first data successfully and transmit the first data via SPI interface successfully. When I scan the second data with barcode scanner during the first data transmission through SPI interface, it shows the message "USB Read Failed - code 0A
" after completing the first data transmission.

The usb status message 0x0A denotes "USBHOST_EP_HALTED". I looked over the documents "Vinculum II User Guide" and tryed to clear the halt state on the USB Host controller using the following codes:

hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_CLEAR_HOST_HALT;
hc_iocb.handle.ep = epCtrl;
hc_iocb.set = &desc_dev;
vos_dev_ioctl(hUSBHOST_1, &hc_iocb);

However, it doesn't work. Are there any suggestions to clear the halted endpoint in the USB Host Controller? Or anything that I missed or any configuration that I need to do?

Thank you for your kind help!

Yvonne



 

9
Hello,

Thank you for the suggestion for the interrupt library of VNC2 in the pdf document of Vinculum II User Guide.

Afterwards, I modified the sample code by enabling the DMA mode in the VNC2 SPI slave configuration using the following code. This works on my case for 1 MHz clock frequency of  VNC2 SPI. Hope this helps others who encounter the same issue.

// enable DMA
spi_iocb.ioctl_code = VOS_IOCTL_COMMON_ENABLE_DMA;
spi_iocb.set = DMA_ACQUIRE_AS_REQUIRED;
vos_dev_ioctl(hSPI_SLAVE_1,&spi_iocb);

Thank you very much!
Yvonne


10
Hello,

The following is my code which modified the example code "SPI to USB Memory Sample Application ROM", I paste it as in the following.

In my code, I use SPI slave in unmanaged SPI mode. And the SPI master sends data in 1M Hz, however the MISO will receive data string with double bytes for each data byte as shown in the attachment figure.

I wonder is it because the interrupt frequency of "vos_dev_write" slower than the SPI master clock frequency (here in my code should be 1 MHz), therefore when the clock is drived, the Tx Shift Register has no new data byte can be transmitted, and VNC2 can send the last data byte in the Tx Shift Register again until the new data byte copied from ram to the rgister in the following clock.

Is there anay advice to increase the interrupt frequency of "vos_dev_write" on the condition that SPI master can keep in 1 MHz clock frequency, and by doing this way, the MISO can receive data bytes with no double? Or any suggestion are appreciated!

Thank you very much!
Yvonne

===========
/*
** Filename: SPI2DSC.c
**
** Automatically created by Application Wizard 1.4.2
**
** Part of solution Firmware in project SPI2DSC
**
** Comments:
**
** Important: Sections between markers "FTDI:S*" and "FTDI:E*" will be overwritten by
** the Application Wizard
*/

#include "SPI2DSC.h"

/* FTDI:STP Thread Prototypes */
vos_tcb_t *tcbSETUP;
vos_tcb_t *tcbSPISLAVE;
vos_tcb_t *tcbBOMS;

void setup();
void SPISlave();
/* FTDI:ETP */

/* FTDI:SDH Driver Handles */
VOS_HANDLE hUSBHOST_1; // USB Host Port 1
VOS_HANDLE hSPI_SLAVE_1; // SPISlave Port 1 Interface Driver
VOS_HANDLE hFAT_FILE_SYSTEM; // FAT File System for FAT32 and FAT16
/* FTDI:EDH */

vos_semaphore_t setupSem;
vos_semaphore_t dataSem;
vos_mutex_t mBufAccess;

FILE *file;
unsigned char leds;
unsigned char buf[40];
unsigned short pBuf = 0;
unsigned short index = 0;

#define V2EVALBOARD_V1
#ifdef V2EVALBOARD_V1
unsigned char led0 = 0x02;
unsigned char led1 = 0x04;
unsigned char led2 = 0x20;
unsigned char led3 = 0x40;
unsigned char led4 = 0x00;
#else
unsigned char led0 = 0x08;
unsigned char led1 = 0x10;
unsigned char led2 = 0x20;
unsigned char led3 = 0x40;
unsigned char led4 = 0x00;
#endif

/* Declaration for IOMUx setup function */
void iomux_setup(void);
void monError();

/* Main code - entry point to firmware */
void main(void)
{
   /* FTDI:SDD Driver Declarations */
   // SPI Slave 0 configuration context
   spislave_context_t spisContext0;
   // USB Host configuration context
   usbhost_context_t usbhostContext;
   /* FTDI:EDD */

   /* FTDI:SKI Kernel Initialisation */
   vos_init(50, VOS_TICK_INTERVAL, VOS_NUMBER_DEVICES);
   vos_set_clock_frequency(VOS_48MHZ_CLOCK_FREQUENCY);
   vos_set_idle_thread_tcb_size(256);
   /* FTDI:EKI */

   iomux_setup();

   /* FTDI:SDI Driver Initialisation */
   // Initialise SPI Slave 0
   spisContext0.buffer_size = VOS_BUFFER_SIZE_512_BYTES;
   spisContext0.slavenumber = SPI_SLAVE_0;
   spislave_init(VOS_DEV_SPI_SLAVE_1,&spisContext0);

   // Initialise FAT File System Driver
   fatdrv_init(VOS_DEV_FAT_FILE_SYSTEM);

   // Initialise USB Host
   usbhostContext.if_count = 8;
   usbhostContext.ep_count = 16;
   usbhostContext.xfer_count = 2;
   usbhostContext.iso_xfer_count = 2;
   usbhost_init(-1, VOS_DEV_USBHOST_1, &usbhostContext);
   /* FTDI:EDI */

   /* FTDI:SCT Thread Creation */
   vos_create_thread_ex(25, 1024, setup, "Setup", 0);
   vos_create_thread_ex(24, 1024, SPISlave, "Read", 0);
   /* FTDI:ECT */

   vos_init_semaphore(&setupSem, 0);
   vos_init_semaphore(&dataSem, 0);
   vos_init_mutex(&mBufAccess, VOS_MUTEX_UNLOCKED);

   vos_start_scheduler();
   
main_loop:
   goto main_loop;
}

/* FTDI:SSP Support Functions */

unsigned char usbhost_connect_state(VOS_HANDLE hUSB)
{
   unsigned char connectstate = PORT_STATE_DISCONNECTED;
   usbhost_ioctl_cb_t hc_iocb;

   if (hUSB)
   {
      hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE;
      hc_iocb.get        = &connectstate;
      vos_dev_ioctl(hUSB, &hc_iocb);

      // repeat if connected to see if we move to enumerated
      if (connectstate == PORT_STATE_CONNECTED)
      {
         vos_dev_ioctl(hUSB, &hc_iocb);
      }
   }
   return connectstate;
}

/* FTDI:ESP */

void open_drivers(void)
{
        /* Code for opening and closing drivers - move to required places in Application Threads */
        /* FTDI:SDA Driver Open */
        hUSBHOST_1 = vos_dev_open(VOS_DEV_USBHOST_1);
        hSPI_SLAVE_1 = vos_dev_open(VOS_DEV_SPI_SLAVE_1);
        /* FTDI:EDA */
}

void monError()
{
   unsigned char leds;
   leds = led4;
   vos_gpio_write_port(GPIO_PORT_A, leds);
}

void setup()
{
   // Open a handle to all our devices...
   unsigned char status = 0;
   common_ioctl_cb_t spi_iocb;
   fat_context *fat_ctx = NULL;
   open_drivers();
   if (hUSBHOST_1 == NULL)
   {
      monError(); return;
   }

   // Set all pins to output.
   vos_gpio_set_port_mode(GPIO_PORT_A, 0xff);

   // SPI Slave setup...
   spi_iocb.ioctl_code = VOS_IOCTL_SPI_SLAVE_SCK_CPHA;
   spi_iocb.set.param = SPI_SLAVE_SCK_CPHA_0; // SPI_SLAVE_SCK_CPHA_0;
   vos_dev_ioctl(hSPI_SLAVE_1,&spi_iocb);

   spi_iocb.ioctl_code = VOS_IOCTL_SPI_SLAVE_SCK_CPOL;
   spi_iocb.set.param = SPI_SLAVE_SCK_CPOL_0; // SPI_SLAVE_SCK_CPOL_0;
   vos_dev_ioctl(hSPI_SLAVE_1,&spi_iocb);

   spi_iocb.ioctl_code = VOS_IOCTL_SPI_SLAVE_DATA_ORDER;
   spi_iocb.set.param = SPI_SLAVE_DATA_ORDER_MSB;
   vos_dev_ioctl(hSPI_SLAVE_1,&spi_iocb);

   spi_iocb.ioctl_code = VOS_IOCTL_SPI_SLAVE_SET_ADDRESS;
   spi_iocb.set.param = 0;
   vos_dev_ioctl(hSPI_SLAVE_1,&spi_iocb);

   spi_iocb.ioctl_code = VOS_IOCTL_SPI_SLAVE_SET_MODE;
   spi_iocb.set.param = SPI_SLAVE_MODE_UNMANAGED;
   vos_dev_ioctl(hSPI_SLAVE_1,&spi_iocb);

   vos_signal_semaphore(&setupSem);
}

void SPISlave()
{
   unsigned short numRead;
   common_ioctl_cb_t spi_iocb;
   unsigned short dataAvail = 0;
   unsigned char testdata;
   
   common_ioctl_cb_t spi_iocb2;
   unsigned short dataTx = 0;
   unsigned char report_buffer[15];
   unsigned short num_xfer;
   
   common_ioctl_cb_t uart_iocb;

   vos_wait_semaphore(&setupSem);
   vos_memset(report_buffer, 0, 15);

   while(1)
   {
         report_buffer[0] = 0x10;
         report_buffer[1] = 0x20;
         report_buffer[2] = 0x30;
         report_buffer[3] = 0x40;
         report_buffer[4] = 0x50;
         report_buffer[5] = 0x60;
         report_buffer[6] = 0x70;
         report_buffer[7] = 0x80;
         report_buffer[8] = 0x90;
         report_buffer[9] = 0xA0;
         report_buffer[10] = 0xB0;
         report_buffer[11] = 0xC0;
         report_buffer[12] = 0xD0;
         report_buffer[13] = 0xE0;
         report_buffer[14] = 0xF0;
         
         vos_dev_write(hSPI_SLAVE_1, &report_buffer[0], 15, &num_xfer);
         spi_iocb2.ioctl_code = VOS_IOCTL_COMMON_GET_TX_QUEUE_STATUS;
            vos_dev_ioctl(hSPI_SLAVE_1, &spi_iocb2);
            dataTx = spi_iocb2.get.queue_stat; // How much data is there?
      
   }
}

===========


11
General Discussion / Receive double bytes in SPI slave for VNC2 at somtimes
« on: November 08, 2022, 06:51:00 AM »
Hello,

I use the VNC2 as SPI slave of V2DIP1-32 board, which receives data from C232HM-DDHSL-0 as SPI master.

Now I can only receive the complete data bytes when setting the transmitting frequency of SPI master at around 300KHz or below (Here the sent data bytes are 0x10, 0x20, 0x30, ..., 0xF0), which can be shown in the first attached figure.

When the transmit frequency of SPI master is faster than 300KHz (for example 350KHz or larger than 350KHz such like 400KHz), I will receive the data string with double or triple bytes in some bytes as shown in second attached figure. The frequency of CPU for VNC2 as SPI slave is set to 48MHz in code.

Are there any other methods or suggestions to get faster frequency for SPI master sending data but not cause the data bytes be repeatly transmitted (i.e. I receive double or triple bytes in MISO)? Is this related to the tx FIFO size of the hardware of VNC2? How to adjust the tx FIFO size?

Or any suggestions or directions are appreciated.
Thanks in advanced!
Yvonne

12
Hello,

I am using C232HM-DDHSL-0 cable as SPI master sending data with FTD2XX, and I am using V2DIP1-32 board of VNC2 as SPI slave.

I modified the example code "SPI to USB Memory Sample Application ROM" to write the recieved data from SPI master into MISO (here I write two bytes of received data: 0x01, 0x02), and I see the received data all shifted one bit (the received data are: 0x00, 0x02, 0x04, 0x04, ..., 0x04) in the capture of logic analyzer as shown in attachment. Also, the first byte of the received data is 0x00, and then shift one bit in left direction for each received data (i.e., 0x01 -> 0x02, 0x02 -> 0x04) and repeat it until the end of MOSI data transaction.

I dont't really understand why the first received byte is 0x00, and why the other received data shifted one bit, is any configs of SPI slave mode that I made a mistake? or any idea will be grateful!

Thanks
Yvonne

Pages: [1]