USB without ASF will not enable

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would really like very much to make tominf's USB diver (https://www.avrfreaks.net/forum/xmega-usb-bulk-transfer-without-asf-or-lufa) work on my ATxmega128A4U-project. However I'm not able to make it even enable the USB-module. When I use ASF on the same hardware, everything works fine. So I thought it might be clock settings and I took the ASF clock settings, but it stiil doesn't work. I testet that basic clock settings works by blinking a LED. Could anyone help me understand why nothing works using the setup code below?

int main(void)
{
    uint8_t data[2] = {0};                                // used to get USB character data

    uint8_t i, gotch;

// clock setup
   sysclk_init();
   irq_initialize_vectors();
   cpu_irq_enable();
   LED_INIT();

//    set up USB
    static uint8_t config_block[32] __attribute__((aligned(2))) = {0};    // grab 32 byte area, aligned to 2-byte word, for config table, which is 8 bytes each for:
                                                                        // ep0 OUT, ep0 IN, ep1 OUT, ep1 IN
    USB.EPPTR = (uint16_t)(&config_block);                                // tell USB where config table is

//    sr_printf("config block start address: %x\n", USB.EPPTR);

    static uint8_t epdata_block[256]  = {0};                                // grab 256 byte area for four 64 byte endpoints (ep0 OUT, ep0 IN, ep1 OUT, ep1 IN)

    ep0_out_data_p = (uint16_t)(&epdata_block) + 0;
    ep0_in_data_p  = (uint16_t)(&epdata_block) + 64;
    ep1_out_data_p = (uint16_t)(&epdata_block) + 128;
    ep1_in_data_p  = (uint16_t)(&epdata_block) + 192;

    USB_EP_t volatile * const ep0_out_p = (USB_EP_t *) (USB.EPPTR + 0);         // create ptr to structure of type USB_EP_t at base address of config_block - for ep0 OUT

    ep0_out_p->CTRL = 0x43;                                    // control ep, 64 byte size
    ep0_out_p->DATAPTR = ep0_out_data_p;                    // 64 byte data block at bottom of epdata_block

    USB_EP_t volatile * const ep0_in_p = (USB_EP_t *) (USB.EPPTR + 8);         // create ptr to structure of type USB_EP_t 1 slot above base address of config_block - for ep0 IN

    ep0_in_p->CTRL = 0x43;                                    // control ep, 64 byte size
    ep0_in_p->DATAPTR = ep0_in_data_p;                        // 64 byte data block 64 bytes above bottom of epdata_block (ep0 OUT is at 0; ep 0 IN is at 16, ep 1 OUT is at 32...)

    USB_EP_t volatile * const ep1_out_p = (USB_EP_t *) (USB.EPPTR + 16);         // create ptr to structure of type USB_EP_t 2 slots above base address of config_block - for ep1 OUT

    ep1_out_p->CTRL = 0x83;                                    // bulk ep, 64 byte size
    ep1_out_p->DATAPTR = ep1_out_data_p;                    // 64 byte data block 128 bytes above bottom of epdata_block

    USB_EP_t volatile * const ep1_in_p = (USB_EP_t *) (USB.EPPTR + 24);         // create ptr to structure of type USB_EP_t 3 slots above base address of config_block - for ep1 IN

    ep1_in_p->CTRL = 0x83;                                    // bulk ep, 64 byte size
    ep1_in_p->DATAPTR = ep1_in_data_p;                        // 64 byte data block 192 bytes above bottom of epdata_block

    USB_CTRLA = 0xD2;                // enable; full speed; max address is 1, store frame number
    USB_CTRLB = 0x01;                // attach

    USB_INTCTRLA = 0x42;            // bus event interrupts enabled (suspend, resume, reset); interrupt level is medium

    USB_INTCTRLB = 0x03;            // transaction complete and setup transaction complete interrupts enabled

//------------------------------------------------

    while(1)

...