static int mcux_lpuart_init(struct device *dev) { const struct mcux_lpuart_config *config = dev->config->config_info; lpuart_config_t uart_config; struct device *clock_dev; u32_t clock_freq; clock_dev = device_get_binding(config->clock_name); if (clock_dev == NULL) { return -EINVAL; } if (clock_control_get_rate(clock_dev, config->clock_subsys, &clock_freq)) { return -EINVAL; } LPUART_GetDefaultConfig(&uart_config); uart_config.enableTx = true; uart_config.enableRx = true; uart_config.baudRate_Bps = config->baud_rate; LPUART_Init(config->base, &uart_config, clock_freq); #ifdef CONFIG_UART_INTERRUPT_DRIVEN config->irq_config_func(dev); #endif return 0; }
void serial_init(serial_t *obj, PinName tx, PinName rx) { uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX); uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX); obj->index = pinmap_merge(uart_tx, uart_rx); MBED_ASSERT((int)obj->index != NC); serial_setup_clock(); lpuart_config_t config; LPUART_GetDefaultConfig(&config); config.baudRate_Bps = 9600; config.enableTx = false; config.enableRx = false; LPUART_Init(uart_addrs[obj->index], &config, serial_get_clock()); pinmap_pinout(tx, PinMap_UART_TX); pinmap_pinout(rx, PinMap_UART_RX); if (tx != NC) { LPUART_EnableTx(uart_addrs[obj->index], true); pin_mode(tx, PullDefault); } if (rx != NC) { LPUART_EnableRx(uart_addrs[obj->index], true); pin_mode(rx, PullDefault); } if (obj->index == STDIO_UART) { stdio_uart_inited = 1; memcpy(&stdio_uart, obj, sizeof(serial_t)); } }
/*! * @brief Main function */ int main(void) { uint8_t ch; lpuart_config_t config; BOARD_InitPins(); BOARD_BootClockRUN(); CLOCK_SetLpuart1Clock(1U); /* * config.baudRate_Bps = 115200U; * config.parityMode = kLPUART_ParityDisabled; * config.stopBitCount = kLPUART_OneStopBit; * config.txFifoWatermark = 0; * config.rxFifoWatermark = 0; * config.enableTx = false; * config.enableRx = false; */ LPUART_GetDefaultConfig(&config); config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE; config.enableTx = true; config.enableRx = true; LPUART_Init(DEMO_LPUART, &config, CLOCK_GetFreq(DEMO_LPUART_CLKSRC)); LPUART_WriteBlocking(DEMO_LPUART, txbuff, sizeof(txbuff) - 1); while (1) { LPUART_ReadBlocking(DEMO_LPUART, &ch, 1); LPUART_WriteBlocking(DEMO_LPUART, &ch, 1); } }
void initLPUART(void) { lpuart_config_t config; lpuart_transfer_t xfer; /* * config.baudRate_Bps = 115200U; * config.parityMode = kLPUART_ParityDisabled; * config.stopBitCount = kLPUART_OneStopBit; * config.txFifoWatermark = 0; * config.rxFifoWatermark = 0; * config.enableTx = false; * config.enableRx = false; */ LPUART_GetDefaultConfig(&config); config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE; config.enableTx = true; config.enableRx = true; LPUART_Init(DEMO_LPUART, &config, CLOCK_GetFreq(DEMO_LPUART_CLKSRC)); LPUART_TransferCreateHandle(DEMO_LPUART, &g_lpuartHandle, LPUART_UserCallback, NULL); /* Send g_tipString out. */ xfer.data = g_tipString; xfer.dataSize = sizeof(g_tipString) - 1; txOnGoing = true; LPUART_TransferSendNonBlocking(DEMO_LPUART, &g_lpuartHandle, &xfer); /* Wait send finished */ while (txOnGoing) { } /* Start to echo. */ }
static rt_err_t imxrt_configure(struct rt_serial_device *serial, struct serial_configure *cfg) { struct imxrt_uart *uart; lpuart_config_t config; RT_ASSERT(serial != RT_NULL); RT_ASSERT(cfg != RT_NULL); uart = (struct imxrt_uart *)serial->parent.user_data; imxrt_uart_gpio_init(uart); LPUART_GetDefaultConfig(&config); config.baudRate_Bps = cfg->baud_rate; switch (cfg->data_bits) { case DATA_BITS_7: config.dataBitsCount = kLPUART_SevenDataBits; break; default: config.dataBitsCount = kLPUART_EightDataBits; break; } switch (cfg->stop_bits) { case STOP_BITS_2: config.stopBitCount = kLPUART_TwoStopBit; break; default: config.stopBitCount = kLPUART_OneStopBit; break; } switch (cfg->parity) { case PARITY_ODD: config.parityMode = kLPUART_ParityOdd; break; case PARITY_EVEN: config.parityMode = kLPUART_ParityEven; break; default: config.parityMode = kLPUART_ParityDisabled; break; } config.enableTx = true; config.enableRx = true; LPUART_Init(uart->uart_base, &config, GetUartSrcFreq()); LPUART_EnableInterrupts(uart->uart_base, kLPUART_RxDataRegFullInterruptEnable); return RT_EOK; }
void modem_init() { const gpio_pin_config_t OUTTRUE = {kGPIO_DigitalOutput, true}; const gpio_pin_config_t IN = {kGPIO_DigitalInput, false}; // initialize BOARD_CELL pins CLOCK_EnableClock(BOARD_CELL_UART_PORT_CLOCK); PORT_SetPinMux(BOARD_CELL_UART_PORT, BOARD_CELL_UART_TX_PIN, BOARD_CELL_UART_TX_ALT); PORT_SetPinMux(BOARD_CELL_UART_PORT, BOARD_CELL_UART_RX_PIN, BOARD_CELL_UART_RX_ALT); CLOCK_EnableClock(BOARD_CELL_PIN_PORT_CLOCK); PORT_SetPinMux(BOARD_CELL_PIN_PORT, BOARD_CELL_STATUS_PIN, kPORT_MuxAsGpio); GPIO_PinInit(BOARD_CELL_PIN_GPIO, BOARD_CELL_STATUS_PIN, &IN); #if BOARD_CELL_RESET_PIN PORT_SetPinMux(BOARD_CELL_PIN_PORT, BOARD_CELL_RESET_PIN, kPORT_MuxAsGpio); GPIO_PinInit(BOARD_CELL_PIN_GPIO, BOARD_CELL_RESET_PIN, &OUTTRUE); #endif PORT_SetPinMux(BOARD_CELL_PIN_PORT, BOARD_CELL_PWRKEY_PIN, kPORT_MuxAsGpio); GPIO_PinInit(BOARD_CELL_PIN_GPIO, BOARD_CELL_PWRKEY_PIN, &OUTTRUE); // the ring identifier is optional, only use if a pin and port exists #if BOARD_CELL_RI_PIN PORT_SetPinMux(BOARD_CELL_PIN_PORT, BOARD_CELL_RI_PIN, kPORT_MuxAsGpio); GPIO_PinInit(BOARD_CELL_PIN_GPIO, BOARD_CELL_RI_PIN, &IN); #endif #if BOARD_CELL_PWR_DOMAIN const gpio_pin_config_t OUTFALSE = {kGPIO_DigitalOutput, false}; CLOCK_EnableClock(BOARD_CELL_PWR_EN_CLOCK); PORT_SetPinMux(BOARD_CELL_PWR_EN_PORT, BOARD_CELL_PWR_EN_PIN, kPORT_MuxAsGpio); GPIO_PinInit(BOARD_CELL_PWR_EN_GPIO, BOARD_CELL_PWR_EN_PIN, &OUTFALSE); #endif // configure uart driver connected to the SIM800H lpuart_config_t lpuart_config; LPUART_GetDefaultConfig(&lpuart_config); lpuart_config.baudRate_Bps = 115200; lpuart_config.parityMode = kLPUART_ParityDisabled; lpuart_config.stopBitCount = kLPUART_OneStopBit; LPUART_Init(BOARD_CELL_UART, &lpuart_config, BOARD_CELL_PORT_CLOCK_FREQ); LPUART_EnableRx(BOARD_CELL_UART, true); LPUART_EnableTx(BOARD_CELL_UART, true); LPUART_EnableInterrupts(BOARD_CELL_UART, kLPUART_RxDataRegFullInterruptEnable); EnableIRQ(BOARD_CELL_UART_IRQ); }
void serial_init(serial_t *obj, PinName tx, PinName rx) { uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX); uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX); obj->index = pinmap_merge(uart_tx, uart_rx); MBED_ASSERT((int)obj->index != NC); // Need to initialize the clocks here as ticker init gets called before mbed_sdk_init if (SystemCoreClock == DEFAULT_SYSTEM_CLOCK) BOARD_BootClockRUN(); /* Set the LPUART clock source */ if (obj->index == LPUART_0) { CLOCK_SetLpuart0Clock(1U); } else { CLOCK_SetLpuart1Clock(1U); } lpuart_config_t config; LPUART_GetDefaultConfig(&config); config.baudRate_Bps = 9600; config.enableTx = false; config.enableRx = false; LPUART_Init(uart_addrs[obj->index], &config, CLOCK_GetFreq(uart_clocks[obj->index])); pinmap_pinout(tx, PinMap_UART_TX); pinmap_pinout(rx, PinMap_UART_RX); if (tx != NC) { LPUART_EnableTx(uart_addrs[obj->index], true); pin_mode(tx, PullUp); } if (rx != NC) { LPUART_EnableRx(uart_addrs[obj->index], true); pin_mode(rx, PullUp); } if (obj->index == STDIO_UART) { stdio_uart_inited = 1; memcpy(&stdio_uart, obj, sizeof(serial_t)); } }
/*! * @brief Main function */ int main(void) { lpuart_config_t config; BOARD_InitPins(); BOARD_BootClockRUN(); CLOCK_SetLpuart1Clock(1U); /* * config.baudRate_Bps = 115200U; * config.parityMode = kLPUART_ParityDisabled; * config.stopBitCount = kLPUART_OneStopBit; * config.txFifoWatermark = 0; * config.rxFifoWatermark = 0; * config.enableTx = false; * config.enableRx = false; */ LPUART_GetDefaultConfig(&config); config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE; config.enableTx = true; config.enableRx = true; LPUART_Init(DEMO_LPUART, &config, CLOCK_GetFreq(DEMO_LPUART_CLKSRC)); /* Send g_tipString out. */ LPUART_WriteBlocking(DEMO_LPUART, g_tipString, sizeof(g_tipString) / sizeof(g_tipString[0])); /* Enable RX interrupt. */ LPUART_EnableInterrupts(DEMO_LPUART, kLPUART_RxDataRegFullInterruptEnable); EnableIRQ(DEMO_LPUART_IRQn); while (1) { /* Send data only when LPUART TX register is empty and ring buffer has data to send out. */ while ((kLPUART_TxDataRegEmptyFlag & LPUART_GetStatusFlags(DEMO_LPUART)) && (rxIndex != txIndex)) { LPUART_WriteByte(DEMO_LPUART, demoRingBuffer[txIndex]); txIndex++; txIndex %= DEMO_RING_BUFFER_SIZE; } } }
static int mcux_lpuart_init(struct device *dev) { const struct mcux_lpuart_config *config = dev->config->config_info; lpuart_config_t uart_config; u32_t clock_freq; clock_freq = CLOCK_GetFreq(config->clock_source); LPUART_GetDefaultConfig(&uart_config); uart_config.enableTx = true; uart_config.enableRx = true; uart_config.baudRate_Bps = config->baud_rate; LPUART_Init(config->base, &uart_config, clock_freq); #ifdef CONFIG_UART_INTERRUPT_DRIVEN config->irq_config_func(dev); #endif return 0; }
void serial_init(serial_t *obj, PinName tx, PinName rx) { uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX); uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX); obj->index = pinmap_merge(uart_tx, uart_rx); MBED_ASSERT((int)obj->index != NC); /* Set the LPUART clock source */ if (obj->index == LPUART_0) { CLOCK_SetLpuart0Clock(1U); } else { CLOCK_SetLpuart1Clock(1U); } lpuart_config_t config; LPUART_GetDefaultConfig(&config); config.baudRate_Bps = 9600; config.enableTx = false; config.enableRx = false; LPUART_Init(uart_addrs[obj->index], &config, CLOCK_GetFreq(uart_clocks[obj->index])); pinmap_pinout(tx, PinMap_UART_TX); pinmap_pinout(rx, PinMap_UART_RX); if (tx != NC) { LPUART_EnableTx(uart_addrs[obj->index], true); pin_mode(tx, PullUp); } if (rx != NC) { LPUART_EnableRx(uart_addrs[obj->index], true); pin_mode(rx, PullUp); } if (obj->index == STDIO_UART) { stdio_uart_inited = 1; memcpy(&stdio_uart, obj, sizeof(serial_t)); } }
/*! * @brief Main function */ int main(void) { lpuart_config_t lpuartConfig; lpuart_transfer_t xfer; lpuart_transfer_t sendXfer; lpuart_transfer_t receiveXfer; BOARD_InitPins(); BOARD_BootClockRUN(); CLOCK_SetLpuartClock(1U); /* Initialize the LPUART. */ /* * lpuartConfig.baudRate_Bps = 115200U; * lpuartConfig.parityMode = kLPUART_ParityDisabled; * lpuartConfig.stopBitCount = kLPUART_OneStopBit; * lpuartConfig.txFifoWatermark = 0; * lpuartConfig.rxFifoWatermark = 0; * lpuartConfig.enableTx = false; * lpuartConfig.enableRx = false; */ LPUART_GetDefaultConfig(&lpuartConfig); lpuartConfig.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE; lpuartConfig.enableTx = true; lpuartConfig.enableRx = true; LPUART_Init(DEMO_LPUART, &lpuartConfig, CLOCK_GetFreq(DEMO_LPUART_CLKSRC)); /* Configure DMA. */ DMAMGR_Init(); /* Request dma channels from DMA manager. */ DMAMGR_RequestChannel(LPUART_TX_DMA_REQUEST, LPUART_TX_DMA_CHANNEL, &g_lpuartTxEdmaHandle); DMAMGR_RequestChannel(LPUART_RX_DMA_REQUEST, LPUART_RX_DMA_CHANNEL, &g_lpuartRxEdmaHandle); /* Create LPUART DMA handle. */ LPUART_TransferCreateHandleEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, LPUART_UserCallback, NULL, &g_lpuartTxEdmaHandle, &g_lpuartRxEdmaHandle); /* Send g_tipString out. */ xfer.data = g_tipString; xfer.dataSize = sizeof(g_tipString) - 1; txOnGoing = true; LPUART_SendEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &xfer); /* Wait send finished */ while (txOnGoing) { } /* Start to echo. */ sendXfer.data = g_txBuffer; sendXfer.dataSize = ECHO_BUFFER_LENGTH; receiveXfer.data = g_rxBuffer; receiveXfer.dataSize = ECHO_BUFFER_LENGTH; while (1) { /* If RX is idle and g_rxBuffer is empty, start to read data to g_rxBuffer. */ if ((!rxOnGoing) && rxBufferEmpty) { rxOnGoing = true; LPUART_ReceiveEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &receiveXfer); } /* If TX is idle and g_txBuffer is full, start to send data. */ if ((!txOnGoing) && txBufferFull) { txOnGoing = true; LPUART_SendEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &sendXfer); } /* If g_txBuffer is empty and g_rxBuffer is full, copy g_rxBuffer to g_txBuffer. */ if ((!rxBufferEmpty) && (!txBufferFull)) { memcpy(g_txBuffer, g_rxBuffer, ECHO_BUFFER_LENGTH); rxBufferEmpty = true; txBufferFull = true; } } }