Exemple #1
0
/* Initialize pin and clocks for USB port */
static void usb_pin_clk_init(void)
{
	/* enable USB PLL and clocks */
	Chip_USB_Init();
	/* enable USB 1 port on the board */
	Board_USBD_Init(1);
}
Exemple #2
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
static void SetupHardware(void)
{
	SystemCoreClockUpdate();
	Board_Init();
	Chip_USB_Init();
	USB_Init(FlashDisk_MS_Interface.Config.PortNumber, USB_MODE_Host);
	/* Hardware Initialization */
	Board_Debug_Init();
}
Exemple #3
0
int skynet_cdc_init(void) {
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;

	RingBuffer_Init(&usb_tx_ringbuf, usb_tx_buf, sizeof(uint8_t), USB_TX_FIFO_QUEUE_SIZE);
	RingBuffer_Flush(&usb_tx_ringbuf);

	Chip_USB_Init();

	LPC_USB->USBClkCtrl = 0x12;                /* Dev, AHB clock enable */
	while ((LPC_USB->USBClkSt & 0x12) != 0x12);

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB_BASE + 0x200;
	usb_param.max_num_ep = 3;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB_IRQn);

			// first disable to simulate re-plug
			skynet_cdc_disconnect();

			msDelay(100);

			// and now enable connection
			skynet_cdc_connect();

			return 1;
		}
	}

	//char* welcome_msg = "# This is skynet dongle.\n";
	//vcom_write(welcome_msg, strlen(welcome_msg));
	return 0;
}
Exemple #4
0
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;

	/* Initialize board and chip */
	Board_Init();

	/* enable clocks */
	Chip_USB_Init();

	/* initialize USBD ROM API pointer. */
	g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->pUSBD;

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	/*	WORKAROUND for artf44835 ROM driver BUG:
	    Code clearing STALL bits in endpoint reset routine corrupts memory area
	    next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
	    EP2_IN are used we need to specify 3 here. But as a workaround for this
	    issue specify 4. So that extra EPs control structure acts as padding buffer
	    to avoid data corruption. Corruption of padding memory doesn’t affect the
	    stack/program behaviour.
	 */
	usb_param.max_num_ep = 2 + 1;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) USB_DeviceDescriptor;
	desc.string_desc = (uint8_t *) USB_StringDescriptor;

	/* Note, to pass USBCV test full-speed only devices should have both
	 * descriptor arrays point to same location and device_qualifier set
	 * to 0.
	 */
	desc.high_speed_desc = USB_FsConfigDescriptor;
	desc.full_speed_desc = USB_FsConfigDescriptor;
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		ret =
			usb_hid_init(g_hUsb,
						 (USB_INTERFACE_DESCRIPTOR *) &USB_FsConfigDescriptor[sizeof(USB_CONFIGURATION_DESCRIPTOR)],
						 &usb_param.mem_base, &usb_param.mem_size);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}

	}

	while (1) {
		__WFI();
	}
}
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	uint32_t prompt = 0, rdCnt = 0;

	SystemCoreClockUpdate();
	/* Initialize board and chip */
	Board_Init();

	/* enable clocks */
	Chip_USB_Init();

	/* initialize USBD ROM API pointer. */
	g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->pUSBD;

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	/*	WORKAROUND for artf44835 ROM driver BUG:
	    Code clearing STALL bits in endpoint reset routine corrupts memory area
	    next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
	    EP2_IN are used we need to specify 3 here. But as a workaround for this
	    issue specify 4. So that extra EPs control structure acts as padding buffer
	    to avoid data corruption. Corruption of padding memory doesn’t affect the
	    stack/program behaviour.
	 */
	usb_param.max_num_ep = 3 + 1;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}

	}

	DEBUGSTR("USB CDC class based virtual Comm port example!\r\n");

	while (1) {
		/* Check if host has connected and opened the VCOM port */
		if ((vcom_connected() != 0) && (prompt == 0)) {
			vcom_write("Hello World!!\r\n", 15);
			prompt = 1;
		}
		/* If VCOM port is opened echo whatever we receive back to host. */
		if (prompt) {
			rdCnt = vcom_bread(&g_rxBuff[0], 256);
			if (rdCnt) {
				vcom_write(&g_rxBuff[0], rdCnt);
			}
		}
		/* Sleep until next IRQ happens */
		__WFI();
	}
}
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void) {
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	uint32_t prompt = 0;

	SystemCoreClockUpdate();
	/* Initialize board and chip */
	Board_Init();
	Board_ADC_Init();

	/* Initialize PWM Units */
	handle0 = Chip_PWM_Init(0, 18, 100);
	handle1 = Chip_PWM_Init(0, 13, 100);

	/* enable clocks and pinmux */
	Chip_USB_Init();

	/* initialize USBD ROM API pointer. */
	g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	/*	WORKAROUND for artf44835 ROM driver BUG:
	 Code clearing STALL bits in endpoint reset routine corrupts memory area
	 next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
	 EP2_IN are used we need to specify 3 here. But as a workaround for this
	 issue specify 4. So that extra EPs control structure acts as padding buffer
	 to avoid data corruption. Corruption of padding memory doesn’t affect the
	 stack/program behaviour.
	 */
	usb_param.max_num_ep = 3 + 1;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	 descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/*	WORKAROUND for artf32219 ROM driver BUG:
		 The mem_base parameter part of USB_param structure returned
		 by Init() routine is not accurate causing memory allocation issues for
		 further components.
		 */
		usb_param.mem_base = USB_STACK_MEM_BASE
				+ (USB_STACK_MEM_SIZE - usb_param.mem_size);

		/*
		 Initialize ADC
		 */
		Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup);
		Chip_ADC_EnableChannel(_LPC_ADC_ID, ADC_CH0, ENABLE);
		Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, ADC_CH0, ENABLE);
		NVIC_SetPriority(_LPC_ADC_IRQ, 1);
		NVIC_EnableIRQ(_LPC_ADC_IRQ);

		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_SetPriority(USB0_IRQn, 1);
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}

	}

	DEBUGSTR("USB CDC class based virtual Comm port example!\r\n");

	/* Start BURST Mode (Continuously Convert and Interrupt) */
	Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
	Chip_RIT_Init(LPC_RITIMER);
	Chip_RIT_SetTimerInterval(LPC_RITIMER, CONTROL_INTERVAL);

	NVIC_EnableIRQ(RIT_IRQn);

	int read_mode = WAITING_HEADER;

	while (1) {

		/* Check if host has connected and opened the VCOM port */

		if ((vcom_connected() != 0) && (prompt == 0)) {
			//vcom_write("Hello World!!\r\n", 15);
			prompt = 1;
		}

		if (prompt) {

			unsigned char c;
			if (vcom_bread(&c, 1) != 0) {
				switch (read_mode) {
				case WAITING_HEADER:
					if (c == PACKET_HEADER) {
						g_buffCounter = 0;
						read_mode = WAITING_FOOTER;
					}
					break;
				case WAITING_FOOTER:
					if (c == PACKET_FOOTER) {
						onReceivePacket();
						read_mode = WAITING_HEADER;
					} else {
						g_rxBuff[g_buffCounter] = c;
						g_buffCounter++;
					}
					break;
				default:
					break;
				}
			}
		}
		/* Sleep until next IRQ happens */
		//__WFI();

	}
}
Exemple #7
0
int main(void) {

  USBD_API_INIT_PARAM_T usb_param;  
  USB_CORE_DESCS_T desc;
  USBD_MSC_INIT_PARAM_T msc_param;
  
  ErrorCode_t ret = LPC_OK;
  USB_INTERFACE_DESCRIPTOR* pIntfDesc;

  /* Initialize board and chip */
  Board_Init();
  
  Board_LED_Set(0, false);
  Board_LED_Set(1, false);
  Board_LED_Set(2, false);
  
  /* Enable EEPROM clock and reset EEPROM controller */
  Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_EEPROM);
  Chip_SYSCTL_PeriphReset(RESET_EEPROM);
  
  /* enable clocks */
  Chip_USB_Init();

  /* initialize USBD ROM API pointer. */
  g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->pUSBD;
  
  /* initialize call back structures */
  memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
  usb_param.usb_reg_base = LPC_USB0_BASE;
  /*  WORKAROUND for artf44835 ROM driver BUG:
      Code clearing STALL bits in endpoint reset routine corrupts memory area
      next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
      EP2_IN are used we need to specify 3 here. But as a workaround for this
      issue specify 4. So that extra EPs control structure acts as padding buffer
      to avoid data corruption. Corruption of padding memory doesn’t affect the
      stack/program behaviour.
  */
  usb_param.max_num_ep = 2 + 1;
  usb_param.mem_base = USB_STACK_MEM_BASE;
  usb_param.mem_size = USB_STACK_MEM_SIZE;
  
  /* Set the USB descriptors */
  desc.device_desc = (uint8_t *) USB_DeviceDescriptor;
  desc.string_desc = (uint8_t *) USB_StringDescriptor;

  /* Note, to pass USBCV test full-speed only devices should have both
   * descriptor arrays point to same location and device_qualifier set
   * to 0.
   */
  desc.high_speed_desc = USB_FsConfigDescriptor;
  desc.full_speed_desc = USB_FsConfigDescriptor;
  desc.device_qualifier = 0;

  /* USB Initialization */
  ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
  if(ret == LPC_OK) {
    usbd_msc_init();
    memset((void *) &msc_param, 0, sizeof(USBD_MSC_INIT_PARAM_T));
    msc_param.mem_base = usb_param.mem_base;
    msc_param.mem_size = usb_param.mem_size;
    msc_param.InquiryStr = InquiryStr;
    msc_param.BlockCount = USBD_MSC_MemorySize / USBD_MSC_BlockSize;
    msc_param.BlockSize = USBD_MSC_BlockSize;
    msc_param.MemorySize = USBD_MSC_MemorySize;
      
    pIntfDesc = (USB_INTERFACE_DESCRIPTOR*)((uint32_t)desc.high_speed_desc + USB_CONFIGURATION_DESC_SIZE);
    // check we are referencing to the proper interface descriptor
    if((pIntfDesc == 0) || (pIntfDesc->bInterfaceClass != USB_DEVICE_CLASS_STORAGE) || (pIntfDesc->bInterfaceSubClass != MSC_SUBCLASS_SCSI)) {
      errorUSB();
    }
    
    msc_param.intf_desc = (uint8_t*)pIntfDesc;
    
    // user defined functions
    msc_param.MSC_Write = MSC_Write;
    msc_param.MSC_Read = MSC_Read;
    msc_param.MSC_Verify = MSC_Verify;

    ret = USBD_API->msc->init(g_hUsb, &msc_param);
      
    if(ret == LPC_OK) {
      // enable USB interrupts
      NVIC_EnableIRQ(USB0_IRQn);
      // now connect
      USBD_API->hw->Connect(g_hUsb, 1);  
    }
    else {
      errorUSB();
    }
  }
  else {
    errorUSB();
  }

  while (1) {
    __WFI();
  }
}