USBFS Feedback Project

Discussion of the PSoC CY8C24x94 and other PSoC like USB parts from Cypress should be discussed here. This forum is limited to the discussion of USB portion of those parts. Other forums should still be used to discuss the non USB features of these parts.

Moderator: ericb

USBFS Feedback Project

Postby jefft » Fri Dec 13, 2013 7:01 am

Hi All,

I am designing a simple project in PSoC creator. The design purposes are to build the design so that when the PSoC 5lp board receives data from the PC/host a LED on the board will blink/turn on. The components I would be using are the USBFS communications and a PWM with a digital pin out. I have already set the appropriate VID and PID for the USBFS, I am just curious as to how or what settings are needed to have the USBFS read incoming data? And how to initialize the LED to turn on when such data is received from the host?

As you can tell I am very new to PSoC Development boards. I have worked with arduino's in the past. I just need some advice in the right direction. Please and Thank You.
jefft
Newbie
Newbie
 
Posts: 8
Joined: Tue Nov 19, 2013 1:29 pm

Re: USBFS Feedback Project

Postby bobmarlowe » Fri Dec 13, 2013 7:27 am

Welcome in the fascinating world of PSoCs.
When the LED is connected to the PWM, just use PWM_Start() to have the LED turned on.
Checking for data can be done with a call to USBFS_GetEPState() which has to be done frequently.

Very helpful for us to answer questions more precise could be if you tell us whether you use a development kit (and which one).


Happy coding
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: USBFS Feedback Project

Postby jefft » Fri Dec 13, 2013 7:46 am

Thank You very much. I am using the CY8CKIT-050 PSoC 5LP Development Kit.
jefft
Newbie
Newbie
 
Posts: 8
Joined: Tue Nov 19, 2013 1:29 pm

Re: USBFS Feedback Project

Postby jefft » Fri Dec 13, 2013 8:20 am

Within the same project I am also adding a LCD component. Do you know what I need to call within my main.c in order to have the option of writing data to the PSoC board from the PC? That data would then appear on the LCD screen.

if(state != 0u)
{
if(state & USBUART_1_LINE_CODING_CHANGED) /* Show new settings */
{
sprintf(lineStr,"BR:%4ld,DB:%d",USBUART_1_GetDTERate(),(uint16)USBUART_1_GetDataBits());
LCD_Position(0u, 0u);
LCD_PrintString(" ");
LCD_Position(0u, 0u);
LCD_PrintString(lineStr);
sprintf(lineStr,"SB:%s,Parity:%s", stop[(uint16)USBUART_1_GetCharFormat()], \
parity[(uint16)USBUART_1_GetParityType()]);
LCD_Position(1u, 0u);
LCD_PrintString(" ");
LCD_Position(1u, 0u);
LCD_PrintString(lineStr);
}
if(state & USBUART_1_LINE_CONTROL_CHANGED) /* Show new settings */
{
state = USBUART_1_GetLineControl();
sprintf(lineStr,"DTR:%s,RTS:%s", (state & USBUART_1_LINE_CONTROL_DTR) ? "ON" : "OFF", \
(state & USBUART_1_LINE_CONTROL_RTS) ? "ON" : "OFF");
LCD_Position(1u, 0u);
LCD_PrintString(" ");
LCD_Position(1u, 0u);
LCD_PrintString(lineStr);

}


I am using this code, except the USBUART_1 is from my previous project. I will be using USBFS as the name of the new communication component.
jefft
Newbie
Newbie
 
Posts: 8
Joined: Tue Nov 19, 2013 1:29 pm

Re: USBFS Feedback Project

Postby jefft » Fri Dec 13, 2013 9:26 am

This is my entire code so far. I am getting 11 errors of undefined references. I believe that the errors are because I haven't stated the references in the USBFS configuration? I want to have my device recognized as a generic USB device but it appears within the COM port in device manager. I have to use string descriptors only if I want it to be recognized as a generic USB device, right?




/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include <project.h>
#include <stdio.h>


#define BUFFER_LEN 64u

/* Declare defines for constant variables */
#define DEVICE_ID 0
#define OUT_ENDPOINT 0x02
#define UnassignedAddress 0

/* Array Positioning for OUT Data */
#define LED_State_Pos 0
#define PWM_DC_Pos 1

/* Input and Output Data Buffers */
uint8 OUT_Data_Buffer[8]; /* [0] = LED State, [1] = PWM Duty Cycle, [2..7] = Unused */
char8 *stop[] = { "1", "1.5", "2" };
char8 *parity[] = { "None", "Odd", "Even", "Mark", "Space" };

/* Various Application Variables */
uint8 OUT_COUNT;
int8 PWM_DutyCycle;

void main()
{

uint16 count;
char8 lineStr[20];
uint8 state;
uint8 buffer[BUFFER_LEN];

/*Enable Global Interrupts */
CYGlobalIntEnable;


/*Initalize PWM */
PWM_Start();
PWM_WriteCompare(10);

/*Initalize LED Off */
LED_Write(1);

/* Start LCD */
LCD_Start();
LCD_PrintString("USB Device");


/* Wait for Device to be assigned an address */
while(USBFS_deviceAddress == UnassignedAddress)
{
/* Waiting for device address to be assigned */
}

/* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
for(;;)
{
/* Check to see if the OUT Endpoint is full from a recieved transaction. */
if(USBFS_GetEPState(OUT_ENDPOINT) == USBFS_OUT_BUFFER_FULL)
{
/* Get the number of bytes recieved */
OUT_COUNT = USBFS_GetEPCount(OUT_ENDPOINT);
/* Read the OUT endpoint and store data in OUT_Data_Buffer */
USBFS_ReadOutEP(OUT_ENDPOINT, OUT_Data_Buffer, OUT_COUNT);
/* Re-enable OUT endpoint */
USBFS_EnableOutEP(OUT_ENDPOINT);
}
{
if(USBFS_DataIsReady() != 0u) /* Check for input data from PC */
{
count = USBFS_GetAll(buffer); /* Read received data and re-enable OUT endpoint */
if(count != 0u)
{
while(USBFS_CDCIsReady() == 0u); /* Wait till component is ready to send more data to the PC */
USBFS_PutData(buffer, count); /* Send data back to PC */
}
}

state = USBFS_IsLineChanged(); /* Check for Line settings changed */
if(state != 0u)
{
if(state & USBFS_LINE_CODING_CHANGED) /* Show new settings */
{
sprintf(lineStr,"BR:%4ld,DB:%d",USBFS_GetDTERate(),(uint16)USBFS_GetDataBits());
LCD_Position(0u, 0u);
LCD_PrintString(" ");
LCD_Position(0u, 0u);
LCD_PrintString(lineStr);
sprintf(lineStr,"SB:%s,Parity:%s", stop[(uint16)USBFS_GetCharFormat()], \
parity[(uint16)USBFS_GetParityType()]);
LCD_Position(1u, 0u);
LCD_PrintString(" ");
LCD_Position(1u, 0u);
LCD_PrintString(lineStr);
}
if(state & USBFS_LINE_CONTROL_CHANGED) /* Show new settings */
{
state = USBFS_GetLineControl();
sprintf(lineStr,"DTR:%s,RTS:%s", (state & USBFS_LINE_CONTROL_DTR) ? "ON" : "OFF", \
(state & USBFS_LINE_CONTROL_RTS) ? "ON" : "OFF");
LCD_Position(1u, 0u);
LCD_PrintString(" ");
LCD_Position(1u, 0u);
LCD_PrintString(lineStr);

}
}
}

void Process_EP1 (void);
{
/* Update PWM Compare Value */
if((OUT_Data_Buffer[PWM_DC_Pos] > 0) && (OUT_Data_Buffer[PWM_DC_Pos] <= 100))
{
PWM_DutyCycle = OUT_Data_Buffer[PWM_DC_Pos];
PWM_WriteCompare(PWM_DutyCycle);
}

/* Check to see if LED_2 Should be on */
if(OUT_Data_Buffer[LED_State_Pos] != 0)
{
LED_2_Write(1);
}
else
{
LED_2_Write(0);
}
}
}
}
/* [] END OF FILE */
jefft
Newbie
Newbie
 
Posts: 8
Joined: Tue Nov 19, 2013 1:29 pm

Re: USBFS Feedback Project

Postby bobmarlowe » Fri Dec 13, 2013 9:53 am

Code snippets do not help too much, better would be to upload the complete project here, so we all can have a look at. From a snippet no one may say whether initialization ets are done correctly.

To do so: Creator -> File -> Create Workspace Bundle (minimal) and then attach the resulting .zip here.


Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: USBFS Feedback Project

Postby jefft » Fri Dec 13, 2013 10:04 am

Thanks Bob!!
Attachments
USB Device Interface.cywrk.Archive01.zip
USB Interface
(558.75 KiB) Downloaded 177 times
jefft
Newbie
Newbie
 
Posts: 8
Joined: Tue Nov 19, 2013 1:29 pm

Re: USBFS Feedback Project

Postby bobmarlowe » Fri Dec 13, 2013 10:06 am

Code: Select all
if(USBFS_GetEPState(OUT_ENDPOINT) == USBFS_OUT_BUFFER_FULL)
is not quite correct: The state is a bit pattern and so some bits may be set. A comparision to .equal. may fail. Better use
Code: Select all
if(USBFS_GetEPState(OUT_ENDPOINT) & USBFS_OUT_BUFFER_FULL) // Test bit Buffer Full 
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: USBFS Feedback Project

Postby bobmarlowe » Fri Dec 13, 2013 10:23 am

... and a 100 MHz clock is quite beyond the capabilities of a PSoC5, use 16 MHz and adjust the PWM accordingly.
Check by setting a breakpoint if
device gets enumerated
data is received


Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: USBFS Feedback Project

Postby jefft » Fri Dec 13, 2013 10:45 am

Thank You very much Bob!! You've been very helpful and quick to respond!!

I've made the changes you've suggested, I still receive the errors. I believe they are from the USBFS component within my top design. The errors are undefined references all regarding to the USBFS function I am calling. I am confused as to why they are giving errors because they are defined in the workspace folder.
jefft
Newbie
Newbie
 
Posts: 8
Joined: Tue Nov 19, 2013 1:29 pm

Re: USBFS Feedback Project

Postby bobmarlowe » Fri Dec 13, 2013 10:59 am

In the USBFS datasheet is a list of all functions supported. Your flagged functions are not supported, where did you get their names from? Stick to the datasheet.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany


Return to “%s” USB

Who is online

Users browsing this forum: No registered users and 1 guest

cron