- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear sir,
i ahve developed one code to download my firmware to cypress FX2LP. i am using the cyusb's cyusb_control_transfer and i am catching the sent bytes and i get perfect match between the Bytes sent and the firmware file size
but sad part is my device doesnt get initialised
Note: Firmware is tested n works fine
i am pasting here my code please do rply and give suggestions.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../../include/cyusb.h"
unsigned int DownloadFirmware();
int main (void)
{
unsigned int a = 0;
a = DownloadFirmware();
if(a == 1)
{
printf("\nsuccessful fd\n");
}
}
unsigned int DownloadFirmware()
{
cyusb_handle *h;
int size, r;
int a, b, c, flag;
int Sum = 0, Done = 0;
const char *cbuf;
const char *filename = "/home/usb/FPR/firmware/fw.bix";
unsigned char *buf = NULL;
unsigned char *ptr;
unsigned char num_bytes = 0;
unsigned short address = 0;
unsigned char reset = 0;
FILE *fp; /* file pointer */
struct libusb_device_descriptor desc;
a = cyusb_open();
if ( a < 0 ) {
printf("Error opening library\n");
return -1;
}
else if ( a == 0 ) {
printf("No device foundd\n");
}
h = cyusb_gethandle(0);
b = cyusb_get_device_descriptor(h, &desc);
if(b){
printf("error getting device descriptor\n");
return -2;
}
struct stat st;
stat(filename, &st);
size = st.st_size;
printf("size of file = %d\n", size);
buf = (unsigned char*)malloc(size);
/* open file for read */
if ((fp = fopen("/home/usb/FPR/firmware/fw.bix", "r"))==NULL){
printf("Cannot open file \n");
}
fread(buf, size, 1 ,fp);
fclose(fp);
if(buf)
printf("file copied");
int ChunkSize = 4000; // seem to sending 4000 but not 5000 at one time
int BlockSize = size;
int entry = 0;
reset = 1;
sleep(1);
reset = 0;
r = cyusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0x00, &reset, 0x01, 1000);
if (!r) {
printf("Error in control_transfer\n");
return r;
}
sleep(1);
sleep(1);
ptr = buf;
while(!Done)
{
if(BlockSize < ChunkSize){
address += ChunkSize;
// buf = buf+ChunkSize;
ptr = ptr + ChunkSize;
ChunkSize = BlockSize;
flag = 1;
}
r = cyusb_control_transfer(h, 0x40, 0xA0, address, 0x00, ptr, ChunkSize, 30);
printf("\nturn no. %d\n", r);
if (!r) {
printf("Error in control_transfer. . .\n");
return r;
}
// buf = buf+ChunkSize;
ptr = ptr + ChunkSize;
BlockSize -= r;
Sum += r;
if(Sum == size)
Done = 1;
printf("\nsum = %d\n", Sum);
}
sleep(1);
reset = 1;
r = cyusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0x00, &reset, 0x01, 1000);
reset = 0;
r = cyusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0x00, &reset, 0x01, 1000);
sleep(2);
if(Done == 1){
return 1;
free(buf);
}
}
please help me i want to get out of this
Thanks in advance
Regards
Rohaan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content