void dk_uart_init(void){ LPC_SC->PCONP |= (1 << 24); //podl. zrodla zegarowego LPC_SC->PCLKSEL1 |= (1<<16); //div cclk/1 LPC_UART2->LCR |= (1 << 7); //DLAB access LPC_UART2->LCR |= 3; //ramka 8-bit //ustawienie optymalnego preskalera LPC_UART2->DLL = 31; LPC_UART2->DLM = 0; LPC_UART2->FDR = (3 | (4<<4)); LPC_UART2->FCR = 7; //wl FIFO i reset PIN_Configure(0, 10, 1, 2, 0); //podl pinow PIN_Configure(0, 11, 1, 2, 0); LPC_UART2->LCR &= ~(1 << 7); //DLAB access //przerwanie odbioru danych LPC_UART2->IER |= (1<<0); NVIC_EnableIRQ(UART2_IRQn); }
/** \fn int32_t USB_PinsUnconfigure (void) \brief De-configure USB pins \return result of pin de-configuration - value 0: pins de-configured correctly - value -1: pins de-configuration has failed */ int32_t USB_PinsUnconfigure (void) { volatile uint8_t U1_role = 0U; volatile uint8_t U2_role = 0U; if (usb_pin_cfg == 0U) { return 0U; } #if (RTE_USB_PORT_CFG == 0) U1_role = ARM_USB_ROLE_DEVICE; U2_role = ARM_USB_ROLE_HOST; #elif (RTE_USB_PORT_CFG == 1) U1_role = ARM_USB_ROLE_HOST; U2_role = ARM_USB_ROLE_HOST; #elif (RTE_USB_PORT_CFG == 2) U1_role = ARM_USB_ROLE_NONE; U2_role = ARM_USB_ROLE_NONE; #elif (RTE_USB_PORT_CFG == 3) U1_role = ARM_USB_ROLE_HOST; U2_role = ARM_USB_ROLE_DEVICE; #endif #if (RTE_USB_PORT1_EN == 1) switch (U1_role) { // Host pins case ARM_USB_ROLE_HOST: #if (RTE_USB_PPWR1_PIN_EN == 1) // USB_PPWR1 if (PIN_Configure (RTE_USB_PPWR1_PORT, RTE_USB_PPWR1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_PWRD1_PIN_EN == 1) // USB_PWRD1 if (PIN_Configure (RTE_USB_PWRD1_PORT, RTE_USB_PWRD1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_OVRCR1_PIN_EN == 1) // USB_OVRCR1 if (PIN_Configure (RTE_USB_OVRCR1_PORT, RTE_USB_OVRCR1_BIT, IOCON_D_RST) != 0) { return -1; } #endif break; // Device pins case ARM_USB_ROLE_DEVICE: #if (RTE_USB_CONNECT1_PIN_EN == 1) // SoftConnect1 if (PIN_Configure (RTE_USB_CONNECT1_PORT, RTE_USB_CONNECT1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_VBUS_PIN_EN == 1) // VBUS if (PIN_Configure (RTE_USB_VBUS_PORT, RTE_USB_VBUS_BIT, IOCON_A_RST) != 0) { return -1; } #endif break; default: return -1; } // Common pins configuration #if (RTE_USB_UP_LED1_PIN_EN == 1) // USB_UP_LED1 if (PIN_Configure (RTE_USB_UP_LED1_PORT, RTE_USB_UP_LED1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_DP1_PIN_EN == 1) // USB_D+1 if (PIN_Configure (RTE_USB_DP1_PORT, RTE_USB_DP1_BIT, IOCON_U_RST) != 0) { return -1; } #endif #if (RTE_USB_DM1_PIN_EN == 1) // USB_D-1 if (PIN_Configure (RTE_USB_DM1_PORT, RTE_USB_DM1_BIT, IOCON_U_RST) != 0) { return -1; } #endif #if (RTE_USB_PORT1_OTG_EN == 1) #if (RTE_USB_INT1_PIN_EN == 1) // USB_INT1 if (PIN_Configure (RTE_USB_INT1_PORT, RTE_USB_INT1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_SCL1_PIN_EN == 1) // USB_SCL1 #if ((RTE_USB_SCL1_PORT == 0) && (RTE_USB_SCL1_BIT == 28)) if (PIN_Configure (RTE_USB_SCL1_PORT, RTE_USB_SCL1_BIT, IOCON_I_RST) != 0) { return -1; } #elif ((RTE_USB_SCL1_PORT == 1) && (RTE_USB_SCL1_BIT == 28)) if (PIN_Configure (RTE_USB_SCL1_PORT, RTE_USB_SCL1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #endif #if (RTE_USB_SDA1_PIN_EN == 1) // USB_SDA1 #if ((RTE_USB_SDA1_PORT == 0) && (RTE_USB_SDA1_BIT == 27)) if (PIN_Configure (RTE_USB_SDA1_PORT, RTE_USB_SDA1_BIT, IOCON_I_RST) != 0) { return -1; } #elif ((RTE_USB_SDA1_PORT == 1) && (RTE_USB_SDA1_BIT == 29)) if (PIN_Configure (RTE_USB_SDA1_PORT, RTE_USB_SDA1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #endif #if (RTE_USB_TX_E1_PIN_EN == 1) // USB_TX_E1 if (PIN_Configure (RTE_USB_TX_E1_PORT, RTE_USB_TX_E1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_TX_DP1_PIN_EN == 1) // USB_TX_DP1 if (PIN_Configure (RTE_USB_TX_DP1_PORT, RTE_USB_TX_DP1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_TX_DM1_PIN_EN == 1) // USB_TX_DM1 if (PIN_Configure (RTE_USB_TX_DM1_PORT, RTE_USB_TX_DM1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_RCV1_PIN_EN == 1) // USB_RCV1 if (PIN_Configure (RTE_USB_RCV1_PORT, RTE_USB_RCV1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_RX_DP1_PIN_EN == 1) // USB_RX_DP1 if (PIN_Configure (RTE_USB_RX_DP1_PORT, RTE_USB_RX_DP1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_RX_DM1_PIN_EN == 1) // USB_RX_DM1 if (PIN_Configure (RTE_USB_RX_DM1_PORT, RTE_USB_RX_DM1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_LS1_PIN_EN == 1) // USB_LS1 if (PIN_Configure (RTE_USB_LS1_PORT, RTE_USB_LS1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_SSPND1_PIN_EN == 1) // USB_SSPND1 if (PIN_Configure (RTE_USB_SSPND1_PORT, RTE_USB_SSPND1_BIT, IOCON_D_RST) != 0) { return -1; } #endif #endif #if (RTE_USB_PORT2_EN == 1) switch (U2_role) { // Host pins case ARM_USB_ROLE_HOST: #if (RTE_USB_PPWR2_PIN_EN == 1) // USB_PPWR2 if (PIN_Configure (RTE_USB_PPWR2_PORT, RTE_USB_PPWR2_BIT, IOCON_A_RST) != 0) { return -1; } #endif #if (RTE_USB_PWRD2_PIN_EN == 1) // USB_PWRD2 if (PIN_Configure (RTE_USB_PWRD2_PORT, RTE_USB_PWRD2_BIT, IOCON_A_RST) != 0) { return -1; } #endif #if (RTE_USB_OVRCR2_PIN_EN == 1) // USB_OVRCR2 if (PIN_Configure (RTE_USB_OVRCR2_PORT, RTE_USB_OVRCR2_BIT, IOCON_A_RST) != 0) { return -1; } #endif break; // Device pins case ARM_USB_ROLE_DEVICE: #if (RTE_USB_CONNECT2_PIN_EN == 1) // SoftConnect2 if (PIN_Configure (RTE_USB_CONNECT2_PORT, RTE_USB_CONNECT2_BIT, IOCON_D_RST) != 0) { return -1; } #endif #if (RTE_USB_VBUS_PIN_EN == 1) // VBUS if (PIN_Configure (RTE_USB_VBUS_PORT, RTE_USB_VBUS_BIT, IOCON_A_RST) != 0) { return -1; } #endif break; default: return -1; } // Common pins configuration #if (RTE_USB_UP_LED2_PIN_EN == 1) // USB_UP_LED2 if (PIN_Configure (RTE_USB_UP_LED2_PORT, RTE_USB_UP_LED2_BIT, IOCON_A_RST) != 0) { return -1; } #endif #if (RTE_USB_DP2_PIN_EN == 1) // USB_D+2 (USB_D-2: Dedicated pin) if (PIN_Configure (RTE_USB_DP2_PORT, RTE_USB_DP2_BIT, IOCON_U_RST) != 0) { return -1; } #endif #endif usb_pin_cfg = 1U; return 0U; #else return -1; #endif }