Discussion in "Electronics" started by    ssssssara    Feb 25, 2013.
Mon Feb 25 2013, 04:22 pm
#1
Hi,
Does anyone out there has any experience in programming a FTDI VNC2? I have a Development Module (http://www.ftdichip.com/Support/Documents/DataSheets/Modules/DS_V2DIP1-32.pdf) which gives me headache...

I've managed to make an application where I can connect a USB keyboard to the FTDI DM and with the keyboard control a RS232 output. So far so good. But now I want to make another application where I can connect a USB memory stick and read files from this. I've partly followed an example from http://www.ftdichip.com/Support/Documents/AppNotes/AN_151%20Vinculum%20II%20User%20Guide.pdf. When the execution reaches this function call:
vos_dev_ioctl(hBoms, &boms_iocb);

it freezes. The function never returns. I have no idea why. What could possibly make this function never return?

I know this is a very specific question that probably no one can give me any straight answer to, but I have to try... Maybe someone can give me a push in the right direction how to move forward in the troubleshooting... I've attached my code.
Mon Feb 25 2013, 04:24 pm
#2
Hmm, attachments failed to attach. Insert my code instead:

UsbMain.c:
#include "vos.h"
#include "stdio.h"
#include "ioctl.h"
#include "UART.h"
#include "USB.h"
#include "USBHost.h"
#include "BOMS.h"
#include "GPIO.h"
#include "FAT.h"

//extern unsigned char tmr_init (unsigned char devNum, tmr_context_t* context);

vos_tcb_t *tcbFIRMWARE;

//UsbHost Interface Driver
VOS_HANDLE hUsbHost2;
//UART Interface Driver
VOS_HANDLE hUART;

tmr_ioctl_cb_t tmr_iocb;
//result of pin config init
uint16 pinres;

//Function prototypes...
void firmware();
uint16 iomux_setup(void);
void initUart();
void ParallellHandler(usbhost_device_handle_ex ifDev);


/**
 * Main code - entry point to firmware
 **/
void main(void) {
	//UART Driver configuration context
	uart_context_t uartContext;
	//USB Host configuration context
	usbhost_context_t usbHostContext;
	//GPIO configuration context
	gpio_context_t gpioContext;

	//Setup the kernel
	vos_init(50, VOS_TICK_INTERVAL, VOS_NUMBER_DEVICES);
	vos_set_clock_frequency(VOS_48MHZ_CLOCK_FREQUENCY);
	vos_set_idle_thread_tcb_size(256);

	//Setup the pins on the ic
	pinres = iomux_setup();

	//Initialise the 2nd USB port as Host
	usbHostContext.if_count = 4;
	usbHostContext.ep_count = 8;
	usbHostContext.xfer_count = 2;
	usbHostContext.iso_xfer_count = 2;
	usbhost_init(-1, VOS_DEV_USBHOST_2, &usbHostContext);

	//Initialise BOMS Device Driver
	boms_init(VOS_DEV_BOMS);
	//Initialise FAT File System Driver
	fatdrv_init(VOS_DEV_FAT_FILE_SYSTEM);

	//Initialise the UART
	uartContext.buffer_size = VOS_BUFFER_SIZE_128_BYTES;
	uart_init(VOS_DEV_UART, &uartContext);

	//Initialize the GPIO Port A
	gpioContext.port_identifier = GPIO_PORT_A;
	gpio_init(VOS_DEV_GPIO_PORT_A, &gpioContext);
	//Initialize the GPIO Port B
	gpioContext.port_identifier = GPIO_PORT_B;
	gpio_init(VOS_DEV_GPIO_PORT_B, &gpioContext);

	tcbFIRMWARE = vos_create_thread_ex(20, 512, firmware, "Application", 0);

	vos_start_scheduler();

	while(1);
}

void firmware() {
	usbhost_device_handle_ex ifDev;
	usbhost_ioctl_cb_class_t ioClass;

	usbhost_ioctl_cb_t hc_iocb;
	usbhost_ioctl_cb_class_t hc_iocb_class;
	unsigned char connectstate;

	initConfig();

	//Open the USB and UART interfaces
	hUsbHost2 = vos_dev_open(VOS_DEV_USBHOST_2);
	hUART = vos_dev_open(VOS_DEV_UART);

	//Setup the UART interface
	initUart();

	vos_delay_msecs(500);

	stdioAttach(hUART);
	#ifdef DEBUG
	printf("Pin-config-result: 0x%x\r\n", pinres);
	#endif

	while(1) {

		vos_delay_msecs(1000);

		// user ioctl to see if bus available
		hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE;
		hc_iocb.get = &connectstate;
		vos_dev_ioctl(hUsbHost2, &hc_iocb);
		if (connectstate == PORT_STATE_ENUMERATED)
		{
			// find and connect a BOMS device
			// USBHost ioctl to find first BOMS device on host
			hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS;
			hc_iocb.handle.dif = NULL;
			hc_iocb.set = &hc_iocb_class;
			hc_iocb.get = &ifDev;
			hc_iocb_class.dev_class = USB_CLASS_MASS_STORAGE;
			hc_iocb_class.dev_subclass = USB_SUBCLASS_MASS_STORAGE_SCSI;
			hc_iocb_class.dev_protocol = USB_PROTOCOL_MASS_STORAGE_BOMS;
			if (vos_dev_ioctl(hUsbHost2, &hc_iocb) != USBHOST_OK)
			{
				vos_delay_msecs(1000);
				break;
			}
			ParallellHandler(ifDev);
			printf("Parallell handler returned!\r\n");
		} else {
			printf("Fail!\r\n");
		}
	}

	printf("PROGRAM EXIT!\r\n");
}

void ParallellHandler(usbhost_device_handle_ex ifDev) {
	msi_ioctl_cb_t boms_iocb;
	boms_ioctl_cb_attach_t boms_att;
	fat_ioctl_cb_t fat_ioctl;
	fatdrv_ioctl_cb_attach_t fat_att;
	gpio_ioctl_cb_t gpio_iocb;
	unsigned char parallellVal;
	unsigned short numRead;
	
	#ifdef DEBUG
	printf("Attach BOMS Driver!\r\n");
	#endif

	//Attach the BOMS driver to the device
	hBOMS = vos_dev_open(VOS_DEV_BOMS);
	if(!hBOMS) {
		printf("BOMS error\r\n");
		return;
	}

	boms_att.hc_handle = hUsbHost2;
 	boms_att.ifDev = ifDev;
	boms_iocb.ioctl_code = MSI_IOCTL_BOMS_ATTACH;
	boms_iocb.set = &boms_att;
	boms_iocb.get = NULL;

	#ifdef DEBUG
	printf("STUCK!?\r\n");
	#endif
	if(vos_dev_ioctl(hBOMS, &boms_iocb) != MSI_OK) {  //get stuck!!!!!!!!!
		printf("USBerror1\r\n");   // never gets here!
		goto ParallellExit;
	}

	#ifdef DEBUG
	printf("Attach FAT driver!\r\n");  // never gets here!
	#endif

	//Attach the FAT driver to the BOMS driver
	hFAT = vos_dev_open(VOS_DEV_FAT_FILE_SYSTEM);
	if(!hFAT) {
		printf("FAT error");
		goto ParallellExit;
	}
	fat_ioctl.ioctl_code = FAT_IOCTL_FS_ATTACH;
	fat_ioctl.set = &fat_att;
	fat_att.msi_handle = hBOMS;
	fat_att.partition = 0;
	if(vos_dev_ioctl(hFAT, &fat_ioctl) != FAT_OK) {
		//Unable to open the FAT driver
		printf("USBerror2\r\n");
		goto ParallellExit;
	}

	#ifdef DEBUG
	SendMessage("Attach stdio file system!\r\n");
	#endif

	//Lastly attach the stdio file system to the FAT file system
	fsAttach(hFAT);

	while(1) {
		//do stuff...
	}
}


uint16 iomux_setup(void) {
	uint16 res = 0x00;

	//Debugger to pin 11 (IOBUS0) as Bi-Directional.
	if(vos_iomux_define_bidi(199, IOMUX_IN_DEBUGGER, IOMUX_OUT_DEBUGGER) != IOMUX_OK) res = res | 0x01;
	//GPIO PortA bit2 to pin 25(IOBUS6) as Input. BIT 0 USB-MEMORY ADR / BIT 0 NO ROWS SPEC
	if(vos_iomux_define_input(25, IOMUX_IN_GPIO_PORT_A_2) != IOMUX_OK) res = res | 0x002;
	//GPIO PortA bit3 to pin 26 (IOBUS7) as Input. BIT 1 USB-MEMORY ADR / BIT 1 NO ROWS SPEC
	if(vos_iomux_define_input(26, IOMUX_IN_GPIO_PORT_A_3) != IOMUX_OK) res = res | 0x004;
	//GPIO PortA bit4 to pin 29 (IOBUS8) as Input. BIT 2 USB-MEMORY ADR / BIT 2 NO ROWS SPEC
	if(vos_iomux_define_input(29, IOMUX_IN_GPIO_PORT_A_4) != IOMUX_OK) res = res | 0x008;
	//GPIO PortA bit5 to pin 30 (IOBUS9) as Input. BIT 3 USB-MEMORY ADR / BIT 0 PROTOCOL SPEC
	if(vos_iomux_define_input(30, IOMUX_IN_GPIO_PORT_A_5) != IOMUX_OK) res = res | 0x010;
	//GPIO PortA bit6 to pin 31 (IOBUS10) as Input. BIT 4 USB-MEMORY ADR / BIT 1 PROTOCOL SPEC
	if(vos_iomux_define_input(31, IOMUX_IN_GPIO_PORT_A_6) != IOMUX_OK) res = res | 0x020;
	//GPIO PortA bit7 to pin 32 (IOBUS11) as Input. BIT 5 USB-MEMORY ADR / BIT 2 PROTOCOL SPEC
	if(vos_iomux_define_input(32, IOMUX_IN_GPIO_PORT_A_7) != IOMUX_OK) res = res | 0x040;
	//GPIO PortB bit1 to pin 12 (IOBUS1) as Input. BIT 0 BAUDRATE SPEC
	if(vos_iomux_define_input(12, IOMUX_IN_GPIO_PORT_B_1) != IOMUX_OK) res = res | 0x080;
	//GPIO PortB bit2 to pin 14 (IOBUS2) as Input. BIT 1 BAUDRATE SPEC
	if(vos_iomux_define_input(14, IOMUX_IN_GPIO_PORT_B_2) != IOMUX_OK) res = res | 0x100;
	//GPIO PortB bit3 to pin 15 (IOBUS3) as Input. BIT 2 BAUDRATE SPEC
	if(vos_iomux_define_input(15, IOMUX_IN_GPIO_PORT_B_3) != IOMUX_OK) res = res | 0x200;
	// UART_TXD to pin 23 as Output.
	if(vos_iomux_define_output(23, IOMUX_OUT_UART_TXD) != IOMUX_OK)    res = res | 0x400;
	// UART_RXD to pin 24 as Input.
	if(vos_iomux_define_input(24, IOMUX_IN_UART_RXD) != IOMUX_OK)      res = res | 0x800;

	// enable pull-up 75KOhm-resistor
	vos_iocell_set_config(25, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(26, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(29, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(30, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(31, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(32, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(12, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(14, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);
	vos_iocell_set_config(15, VOS_IOCELL_DRIVE_CURRENT_4MA, VOS_IOCELL_TRIGGER_NORMAL, VOS_IOCELL_SLEW_RATE_FAST, VOS_IOCELL_PULL_UP_75K);

	return res;
}


/**
 * Initialize the UART. Set baudrate, data bits, parity etc.
 **/
void initUart() {
	common_ioctl_cb_t ioCtl;

	//Enable DMA
	ioCtl.ioctl_code = VOS_IOCTL_COMMON_ENABLE_DMA;
	vos_dev_ioctl(hUART, &ioCtl);

	//Set baud rate
	ioCtl.ioctl_code = VOS_IOCTL_UART_SET_BAUD_RATE;
	ioCtl.set.uart_baud_rate = GetBaudrate();
	vos_dev_ioctl(hUART, &ioCtl);

	//Set flow control
	ioCtl.ioctl_code = VOS_IOCTL_UART_SET_FLOW_CONTROL;
	ioCtl.set.param = UART_FLOW_NONE;
	vos_dev_ioctl(hUART, &ioCtl);

	//Set data bits
	ioCtl.ioctl_code = VOS_IOCTL_UART_SET_DATA_BITS;
	ioCtl.set.param = UART_DATA_BITS_8;
	vos_dev_ioctl(hUART, &ioCtl);

	//Set stop bits
	ioCtl.ioctl_code = VOS_IOCTL_UART_SET_STOP_BITS;
	ioCtl.set.param = UART_STOP_BITS_1;
	vos_dev_ioctl(hUART, &ioCtl);

	//Set parity
	ioCtl.ioctl_code = VOS_IOCTL_UART_SET_PARITY;
	ioCtl.set.param = UART_PARITY_NONE;
	vos_dev_ioctl(hUART, &ioCtl);
}



UsbMain.h:
#ifndef _UsbMain_H_
#define _UsbMain_H_


#define VOS_DEV_USBHOST_2		0
#define VOS_DEV_UART			1
#define VOS_DEV_FAT_FILE_SYSTEM 	2
#define VOS_DEV_BOMS			3
#define VOS_DEV_GPIO_PORT_A		4
#define VOS_DEV_GPIO_PORT_B		5
#define VOS_NUMBER_DEVICES		6

#define DEBUG				1

#endif


[ Edited Mon Feb 25 2013, 04:26 pm ]
Tue Feb 26 2013, 03:06 am
#3


vos_dev_ioctl(hBoms, &boms_iocb);

it freezes. The function never returns. I have no idea why. What could possibly make this function never return?

ssssssara


Actually that is quite easy, it happens all the time,
the call crashes
Is your code able to throw and handle exceptions ?

My best guess is that one of the values in the boms_iocb structure is wrong.
Check that you are passing the right parameters to vos_dev_ioctl();
Check that your are passing addresses where needed and data where needed.


Could vos_dev_open(VOS_DEV_BOMS) return an error code, not just 0 if it fails. ?

It could also be that the call tries to access hardware and cannot, causing it to
wait forever.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am