Hi, I've made a board to use SAM7X's USB Port. the board works correctly with other functions like buttons and LEDs also SAM-BA work correctly (during test of SAM-BA I found that SAM-BA 2.12 don't support USB3 port). now I want to test it's USB feature but when I compile any example of USB (from atmel's website or other resources) the Keil compiler give errors about headers codes like this error :
Undefined symbol USB_Connect (referred from main.o). Undefined symbol USB_Init (referred from main.o).
with this errors I searched the help of keil and found migration page and RL-USB library and completely changed my codes to make it compatible with the library. after changing the code with challenges and obviating the errors, program compiled successfully and I programmed it into the chip. but after connecting it to USB port of computer, the windows (7 & 64bit) indicated "USB device not recognized" error. I think that the hardware don't have problems because the SAM-BA works correctly. what is the problem ? do I need to make any change in pins status other than DDM and DDP ?
#include <RTL.h> #include <rl_usb.h> #include <AT91SAM7X256.H> int main (void) { static U8 but_ex; U8 but; U8 buf[1]; usbd_init(); /* USB Device Initialization */ usbd_connect(__TRUE); /* USB Device Connect */ while (1) { /* Loop forever */ but = (((AT91C_BASE_PIOA->PIO_PDSR ^ (0x1F << 21)) >> 21) & 0x1F); if (but ^ but_ex) { buf[0] = but; usbd_hid_get_report_trigger(0, buf, 1); but_ex = but; } }; }
Please help me solve this problem. Thanks Best Regards.
I used 18.432MHZ crystal. I think the hardware don't have problem because the SAM-BA works correctly, is this true ?
with the changes below the problems resolved and PC detected the board and installed it but finally I used Atmel's sample and have problem with keil's sample yet.
#include <AT91SAM7X256.H> #include <AT91SAM7X-EK.h> #include <type.h> #include <usb.h> #include <usbcfg.h> #include <usbhw.h> #include <demo.h> AT91S_PIO * pPIO_Led = AT91D_BASE_PIO_LED; /* Global Pointer to PIO */ AT91S_PIO * pPIO_Sw = AT91D_BASE_PIO_SW; /* Global Pointer to PIO */ U8 InReport; /* HID Input Report */ /* Bit0..4: Buttons */ /* Bit5..7: Reserved */ U8 OutReport; /* HID Out Report */ /* Bit0..3: LEDs */ /* Bit4..7: Reserved */ /* * Get HID Input Report -> InReport */ void GetInReport (void) { U32 key; key = pPIO_Sw->PIO_PDSR; /* Read Pin Data */ InReport = 0x00; if ((key & AT91B_SW1) == 0) InReport |= 0x01; /* Check if SW1 is pressed */ if ((key & AT91B_SW2) == 0) InReport |= 0x02; /* Check if SW2 is pressed */ if ((key & AT91B_SW3) == 0) InReport |= 0x04; /* Check if SW3 is pressed */ if ((key & AT91B_SW4) == 0) InReport |= 0x08; /* Check if SW4 is pressed */ if ((key & AT91B_SW5) == 0) InReport |= 0x10; /* Check if SW5 is pressed */ } /* * Set HID Output Report <- OutReport */ void SetOutReport (void) { if (OutReport & 0x01) pPIO_Led->PIO_CODR = AT91B_LED1; else pPIO_Led->PIO_SODR = AT91B_LED1; if (OutReport & 0x02) pPIO_Led->PIO_CODR = AT91B_LED2; else pPIO_Led->PIO_SODR = AT91B_LED2; if (OutReport & 0x04) pPIO_Led->PIO_CODR = AT91B_LED3; else pPIO_Led->PIO_SODR = AT91B_LED3; if (OutReport & 0x08) pPIO_Led->PIO_CODR = AT91B_LED4; else pPIO_Led->PIO_SODR = AT91B_LED4; } /* Main Program */ int main (void) { /* Enable Clock for PIO */ AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA); /* Joystick */ AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOB); /* LEDs */ pPIO_Led->PIO_PER = AT91B_LED_MASK; /* Enable PIO for LED1..4 */ pPIO_Led->PIO_OER = AT91B_LED_MASK; /* LED1..4 are Outputs */ pPIO_Led->PIO_SODR = AT91B_LED_MASK; /* Turn off LED's ("1") */ USB_Init(); /* USB Initialization */ USB_Connect(__TRUE); /* USB Connect */ while (1); /* Loop forever */ }
.
also added hiduser.c usbcore.c usbdesc.c usbhw_SAM7X.c usbuser.c to the project and configured usbcfg.h.
Thanks, Best Regards.
I'm not sure, why above code change solves USB enumeration problem. Abvoe change swaps just LEDs/key switches/joystick ports from the original to yours. The change doesn't directly concern to USB setup. Maybe, one of the original ports causes power failure on your board.
Tsuneo