static msg_t uart_thread(void *arg) { (void)arg; chRegSetThreadName("UART"); uartStart(&HW_UART_DEV, &uart_cfg); palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_ALTERNATE(HW_UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); palSetPadMode(HW_UART_RX_PORT, HW_UART_RX_PIN, PAL_MODE_ALTERNATE(HW_UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); systime_t time = chTimeNow(); for(;;) { time += MS2ST(1); if ((systime_t) ((float) chTimeElapsedSince(last_uart_update_time) / ((float) CH_FREQUENCY / 1000.0)) > (float)TIMEOUT) { mcpwm_set_brake_current(-10.0); } else { set_output(out_received); } chThdSleepUntil(time); } return 0; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 1, PA9 and PA10 are routed to USART1. */ uartStart(&UARTD1, &uart_cfg_1); palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); /* USART1 TX. */ palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(1)); /* USART1 RX. */ /* * Starts the transmission, it will be handled entirely in background. */ uartStartSend(&UARTD1, 13, "Starting...\r\n"); /* * Normal main() thread activity, in this demo it does nothing. */ while (TRUE) { chThdSleepMilliseconds(500); } }
void app_uartcomm_configure(uint32_t baudrate) { uart_cfg.speed = baudrate; if (is_running) { uartStart(&HW_UART_DEV, &uart_cfg); } }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 2 using the driver default configuration. */ uartStart(&UARTD2, &uart_cfg_1); /* * Starts the transmission, it will be handled entirely in background. */ uartStartSend(&UARTD2, 13, "Starting...\r\n"); /* * Normal main() thread activity, in this demo it does nothing. */ while (TRUE) { chThdSleepMilliseconds(500); } return 0; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Set the TX and the RX pin to use the USARTC0 module. * PIN3 (TXD0) as output for USARTC0. * PIN2 (RXD0) as input for USARTC0. */ palSetPadMode(IOPORT3, PIN3, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(IOPORT3, PIN2, PAL_MODE_INPUT_PULLUP); /* Start the USART1 (USARTC0). */ uartStart(&USART1D, &usart1cfg); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while (TRUE) { uartStartSend(&USART1D,14, (const uint8_t *)"Hello world!\r\n"); chThdSleepMilliseconds(2000); } }
void setup_uart(void) { /* * Initialize the Semaphore */ chSemInit(&uart_sem, 1); /* * Activate USART1 and USART3 * TODO: I would enable USART2, as well, but for some reason it doesn't * work when I2C1 is enabled. */ uartStart(&UARTD1, &uart1cfg); uartStart(&UARTD3, &uart3cfg); palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(7)); // USART1 TX palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(7)); // USART1 RX palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(7)); // USART3 TX palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(7)); // USART3 RX }
void dma_storm_uart_start(void){ uint32_t i; for (i=0; i<STORM_BUF_LEN; i++){ txbuf[i] = 0x55; rxbuf[i] = 0; } its = 0; uartStart(&UARTD6, &uart_cfg); uartStartReceive(&UARTD6, STORM_BUF_LEN, rxbuf); uartStartSend(&UARTD6, STORM_BUF_LEN, txbuf); }
void app_uartcomm_start(void) { packet_init(send_packet, process_packet, PACKET_HANDLER); uartStart(&HW_UART_DEV, &uart_cfg); palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_ALTERNATE(HW_UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); palSetPadMode(HW_UART_RX_PORT, HW_UART_RX_PIN, PAL_MODE_ALTERNATE(HW_UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); is_running = 1; chThdCreateStatic(packet_process_thread_wa, sizeof(packet_process_thread_wa), NORMALPRIO, packet_process_thread, NULL); }
void startTsPort(ts_channel_s *tsChannel) { #if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_USB_SERIAL || defined(__DOXYGEN__) if (isCommandLineConsoleOverTTL()) { print("TunerStudio over USB serial"); /** * This method contains a long delay, that's the reason why this is not done on the main thread */ usb_serial_start(); // if console uses UART then TS uses USB tsChannel->channel = (BaseChannel *) CONSOLE_USB_DEVICE; } else #endif { if (CONFIGB(useSerialPort)) { print("TunerStudio over USART"); efiSetPadMode("tunerstudio rx", engineConfiguration->binarySerialRxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); efiSetPadMode("tunerstudio tx", engineConfiguration->binarySerialTxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); #if TS_UART_DMA_MODE print("Using UART-DMA mode"); // init FIFO queue iqObjectInit(&tsUartDma.fifoRxQueue, tsUartDma.buffer, sizeof(tsUartDma.buffer), NULL, NULL); // start DMA driver tsDmaUartConfig.speed = CONFIGB(tunerStudioSerialSpeed); uartStart(TS_DMA_UART_DEVICE, &tsDmaUartConfig); // start continuous DMA transfer using our circular buffer tsUartDma.readPos = 0; uartStartReceive(TS_DMA_UART_DEVICE, sizeof(tsUartDma.dmaBuffer), tsUartDma.dmaBuffer); #else print("Using Serial mode"); tsSerialConfig.speed = CONFIGB(tunerStudioSerialSpeed); sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig); tsChannel->channel = (BaseChannel *) TS_SERIAL_UART_DEVICE; #endif /* TS_UART_DMA_MODE */ } else tsChannel->channel = (BaseChannel *) NULL; // actually not used } #else /* EFI_PROD_CODE */ tsChannel->channel = (BaseChannel *) TS_SIMULATOR_PORT; #endif /* EFI_PROD_CODE */ }
void setup_comm(void) { /* * Activate USART3. */ uartStart(&UARTD3, &uart3cfg); palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(7)); // USART3 TX palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(7)); // USART3 RX uint16_t i; b_index = 0; last_rx_char_index = 0; for (i=0; i<COMM_RECEIVE_BUFFER_LENGTH; i++) { cmd_buffer[i] = 0; } }
void setup(void) { // we need to release the JTAG reset pin to be used as a GPIO, otherwise we can't enable // or disable SBUS out AFIO->MAPR = AFIO_MAPR_SWJ_CFG_NOJNTRST; hal.rcin->init(); hal.rcout->init(); for (uint8_t i = 0; i< 14; i++) { hal.rcout->enable_ch(i); } iomcu.init(); iomcu.calculate_fw_crc(); uartStart(&UARTD2, &uart_cfg); uartStartReceive(&UARTD2, sizeof(iomcu.rx_io_packet), &iomcu.rx_io_packet); }
void comm_uart_init(void) { // Initialize UART uartStart(&UART_DEV, &uart_cfg); palSetPadMode(UART_TX_PORT, UART_TX_PIN, PAL_MODE_ALTERNATE(UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); palSetPadMode(UART_RX_PORT, UART_RX_PIN, PAL_MODE_ALTERNATE(UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); // Initialize the bldc interface and provide a send function bldc_interface_uart_init(send_packet); // Start processing thread chThdCreateStatic(packet_process_thread_wa, sizeof(packet_process_thread_wa), NORMALPRIO, packet_process_thread, NULL); // Start timer thread chThdCreateStatic(timer_thread_wa, sizeof(timer_thread_wa), NORMALPRIO, timer_thread, NULL); }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the UART driver 2, PA2(TX) and PA3(RX) are routed to USART2. */ uartStart(&UARTD2, &uart_cfg_1); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); /* * Normal main() thread activity, in this demo it does nothing. */ while (true) { if (palReadPad(GPIOA, GPIOA_BUTTON)) { /* * Starts both a transmission and a receive operations, both will be * handled entirely in background. */ uartStopReceive(&UARTD2); uartStopSend(&UARTD2); uartStartReceive(&UARTD2, 16, buffer); uartStartSend(&UARTD2, 16, message); } chThdSleepMilliseconds(500); } }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Initialize the UART interface. */ uartInit(); /* * Start the Uart 1 interface. */ uartStart(&UARTD1, &uartConf); /* * Send an message via the UART 1 interface. */ uartStartSend(&UARTD1, 15, (const void *) "Hello world!.\n\r"); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while (TRUE) { chThdSleepMilliseconds(1000); } }
void bus_init() { uartStart(&UARTD2, &uart_cfg); }