uint8_t USB_init(void) { __disable_interrupt(); // Disable global interrupts // configuration of USB module USBKEYPID = 0x9628; // set KEY and PID to 0x9628 -> access to configuration registers enabled USBPHYCTL = PUSEL; // use DP and DM as USB terminals USBPWRCTL = VUSBEN + SLDOEN + SLDOAON; // enable primary and secondary LDO (3.3 and 1.8 V) { volatile unsigned int i; for (i =0; i < 1000; i++); // wait some time for LDOs } USBPWRCTL = VUSBEN + SLDOEN + SLDOAON + VBONIE; // enable interrupt VBUSon USBKEYPID = 0x9600; // access to configuration registers disabled //init Serial Number #if (USB_STR_INDEX_SERNUM != 0) USB_InitSerialStringDescriptor(); #endif // init memcpy() function: DMA or non-DMA USB_initMemcpy(); __enable_interrupt(); // enable global interrupts return kUSB_succeed; }
//---------------------------------------------------------------------------- BYTE USB_init(VOID) { WORD bGIE = __get_SR_register() &GIE; //save interrupt status // atomic operation - disable interrupts __disable_interrupt(); // Disable global interrupts // configuration of USB module USBKEYPID = 0x9628; // set KEY and PID to 0x9628 -> access to configuration registers enabled USBPHYCTL = PUSEL; // use DP and DM as USB terminals (not needed because an external PHY is connected to port 9) USBPWRCTL = VUSBEN + SLDOAON; // enable primary and secondary LDO (3.3 and 1.8 V) { volatile unsigned int i; for (i =0; i < USB_MCLK_FREQ/1000*2/10; i++); // wait some time for LDOs (1ms delay) } USBPWRCTL = VUSBEN + SLDOAON + VBONIE; // enable interrupt VBUSon USBKEYPID = 0x9600; // access to configuration registers disabled //reset events mask wUsbEventMask = 0; //init Serial Number #if (USB_STR_INDEX_SERNUM != 0) USB_InitSerialStringDescriptor(); #endif // init memcpy() function: DMA or non-DMA USB_initMemcpy(); #ifdef _MSC_ MscResetCtrlLun(); #endif __bis_SR_register(bGIE); //restore interrupt status return kUSB_succeed; }