Hello Bernhard,
Here are the details about hardware, software and compiler.
Hardware: This is a customized board. controller used is LPC1837 from NXP. these has two USB port. USB0 and USB1. we are using only USB0 with B type connector.
pin configuration are
USB0_PPWR - Not used,
USB0_PWR_FAULT- Port 8 pin 0.
USB0_IND0-Port 8 pin 2.
USB0_IND1- Not used.
USB0_DM - connected to signal D+
USB0_DP - connected to signal D-
USB0_VBUS - connected to signal VCC.
compiler - keil 5 version
Software: we are using CMSIS driver to develop the code.
following is my code please take a look at it and inform where i'm going wrong.
problems statement : this code is not able to communicate with PC. this not able to send or receive data from PC.
#include <stdint.h>
#include <stdbool.h>
#include "Driver_USBD.h"
#include "USB_LPC18xx.h"
#include "LPC18xx.h"
#include "rl_usb.h"
#include "usbd_config.h"
#include "usb_def.h"
/* The size of the packet buffer. */
#define PACKET_BUFFER_SIZE 4096
#define TRUE 1
#define FALSE 0
/* Application defined LUSB interrupt status
#define LUSB_DATA_PENDING _BIT(0)*/
/* Packet buffer for processing */
static uint8_t g_rxBuff[PACKET_BUFFER_SIZE];
static uint8_t g_txBuff[PACKET_BUFFER_SIZE];
usbd_data_t USB_data;
uint8_t Data_Received;
/*import USB 0 control block declarations*/
extern ARM_DRIVER_USBD Driver_USBD0;
/*declare USBD control block pointers*/
static ARM_DRIVER_USBD *USBDDrv = NULL;
extern usbdRequestStatus USBD_Device0_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, int32_t *len);
void USBSignalDeviceEvent(uint32_t u4l_event);
void USBSignalEndpointEvent(uint8_t u4l_ep_addr,uint32_t u4l_event);
extern void USBD_Device0_Initialize (void);
*****************************************************************************/
int main()
{
uint32_t u4l_status;
int32_t u4l_event;
uint8_t *u1l_data ;
uint8_t **u1l_len[64];
uint8_t data[64];
int32_t *len;
uint8_t address;
ARM_USBD_STATE s1l_status;
USBDDrv = &Driver_USBD0;
address =0x32;
u4l_event = 1024;
u1l_data = data;
len = &u4l_event;
/*initialize USB 0 drivers*/
USBDDrv->Initialize(USBSignalDeviceEvent, USBSignalEndpointEvent);
/*power up USB 0 controllers*/
USBDDrv->PowerControl(ARM_POWER_FULL);
/* USBD device connect */
USBDDrv->DeviceConnect();
/*event vbus on and HIGH enable*/
//USBD_SignalDeviceEvent(ARM_USBD_EVENT_VBUS_ON);
/* checking whether the USB is ready to communicate */
s1l_status = USBDDrv->DeviceGetState();
/* USB end point configured for read operation */
USBDDrv->EndpointConfigure(0x01,
ARM_USB_ENDPOINT_CONTROL,1024);
if(s1l_status.active==1)
{
/* USB end point transfer the read data to USB_data which
of STRUCT type USB_data_t*/
USBDDrv->EndpointTransfer(0x01,
(uint8_t *)&USB_data,1024);
}
/* USBD device connect
USBDDrv->DeviceDisconnect();*/
/*power up USB 0 controllers
USBDDrv->PowerControl(ARM_POWER_OFF);*/
/*initialize USB 0 drivers
USBDDrv->Uninitialize();*/
}
/******************************************************************************
* ARM_SignalUnitEvent
* Description: This routine provides the event status of the can controller
*
* Inputs:
* u4l_event uint32_t type of event.
*
* Outputs:
* None
*
* Returns:
* None
*****************************************************************************/
void USBSignalDeviceEvent(uint32_t u4l_event)
{
/* action to be taken when VBUS_ON event occurs */
if((ARM_USBD_EVENT_VBUS_ON == u4l_event))
{
/* do nothing */
}
/* action to be taken when VBUS_OFF event occurs */
if(ARM_USBD_EVENT_VBUS_OFF == u4l_event)
{
/* do nothing */
}
/* action to be taken when HIGH SPEED event occurs */
if(ARM_USBD_EVENT_HIGH_SPEED == u4l_event)
{
/* do nothing */
}
/* action to be taken when RESET event occurs */
if((ARM_USBD_EVENT_RESET == u4l_event))
{
/* do nothing */
}
/* action to be taken when SUSPEND event occurs */
if(ARM_USBD_EVENT_SUSPEND == u4l_event)
{
/* do nothing */
}
/* action to be taken when RESUME event occurs */
if(ARM_USBD_EVENT_RESUME == u4l_event)
{
/* do nothing */
}
}
/*****************************************************************************
* USB_SignalObjectEvent
* Description: This routine provides the object event status of the can
* controller.
*
* Inputs:
* u4l_obj_idx uint32_t event object id.
* u4l_event uint32_t type of event.
*
* Outputs:
* None
*
* Returns:
* None
*****************************************************************************/
void USBSignalEndpointEvent(uint8_t u4l_ep_addr,uint32_t u4l_event)
{
USB_SETUP_PACKET *u1l_setup_packet;
uint8_t u1l_rec_bytes;
uint8_t *u1l_data;
int32_t u1l_len;
/*check if the event object id is 1 and sent event is complete */
if((ARM_USBD_EVENT_SETUP == u4l_event))
{
/* Read setup packet received over Control Endpoint*/
USBDDrv->ReadSetupPacket(u1l_data);
/*set the data received flag to indicate the test as pass*/
Data_Received = TRUE;
}
/*check if the event object id is 0*/
if((ARM_USBD_EVENT_OUT == u4l_event))
{
/*number of bytes recevied */
u1l_rec_bytes=USBDDrv->EndpointTransferGetResult(
0x01);
}
/* check for the event recevice */
if((ARM_USBD_EVENT_IN == u4l_event))
{
/*number of bytes recevied */
USBDDrv->EndpointTransferGetResult(0x01);
}
}