void usbuart_set_line_coding(struct usb_cdc_line_coding *coding) { usart_set_baudrate(USBUSART, coding->dwDTERate); usart_set_databits(USBUSART, coding->bDataBits); switch(coding->bCharFormat) { case 0: usart_set_stopbits(USBUSART, USART_STOPBITS_1); break; case 1: usart_set_stopbits(USBUSART, USART_STOPBITS_1_5); break; case 2: usart_set_stopbits(USBUSART, USART_STOPBITS_2); break; } switch(coding->bParityType) { case 0: usart_set_parity(USBUSART, USART_PARITY_NONE); break; case 1: usart_set_parity(USBUSART, USART_PARITY_ODD); break; case 2: usart_set_parity(USBUSART, USART_PARITY_EVEN); break; } }
void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity) { /* Configure USART parity and data bits */ if (parity == UPARITY_EVEN) { usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_EVEN); if (bits == UBITS_7) { usart_set_databits((uint32_t)p->reg_addr, 8); } else { // 8 data bits by default usart_set_databits((uint32_t)p->reg_addr, 9); } } else if (parity == UPARITY_ODD) { usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_ODD); if (bits == UBITS_7) { usart_set_databits((uint32_t)p->reg_addr, 8); } else { // 8 data bits by default usart_set_databits((uint32_t)p->reg_addr, 9); } } else { // 8 data bist, NO_PARITY by default usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_NONE); usart_set_databits((uint32_t)p->reg_addr, 8); // is 7bits without parity possible ? } /* Configure USART stop bits */ if (stop == USTOP_2) { usart_set_stopbits((uint32_t)p->reg_addr, USART_STOPBITS_2); } else { // 1 stop bit by default usart_set_stopbits((uint32_t)p->reg_addr, USART_STOPBITS_1); } }
void UART_SetFormat(int bits, uart_parity parity, uart_stopbits stopbits) { // STM counts parity bit as part of databits length // so bits and parity settings are interdependent. if (bits == 8) { if (parity == UART_PARITY_NONE) { usart_set_databits(UART_CFG.uart, 8); usart_set_parity(UART_CFG.uart, USART_PARITY_NONE); } else { usart_set_databits(UART_CFG.uart, 9); if (parity == UART_PARITY_EVEN) usart_set_parity(UART_CFG.uart, USART_PARITY_EVEN); else usart_set_parity(UART_CFG.uart, USART_PARITY_ODD); } } else if (bits == 7 && parity != UART_PARITY_NONE) { usart_set_databits(UART_CFG.uart, 8); if (parity == UART_PARITY_EVEN) usart_set_parity(UART_CFG.uart, USART_PARITY_EVEN); else usart_set_parity(UART_CFG.uart, USART_PARITY_ODD); } switch (stopbits) { case UART_STOPBITS_1: usart_set_stopbits(UART_CFG.uart, USART_STOPBITS_1); break; case UART_STOPBITS_1_5: usart_set_stopbits(UART_CFG.uart, USART_STOPBITS_1_5); break; case UART_STOPBITS_2: usart_set_stopbits(UART_CFG.uart, USART_STOPBITS_2); break; } }
void UART_Initialize() { /* Enable clocks for GPIO port containing _USART and USART */ rcc_peripheral_enable_clock(&_USART_RCC_APB_ENR_IOP, _USART_RCC_APB_ENR_IOP_EN); rcc_peripheral_enable_clock(&_USART_RCC_APB_ENR_USART, _USART_RCC_APB_ENR_USART_EN); /* Enable DMA clock */ // TODO ENABLED ALREADY FOR ADC? rcc_peripheral_enable_clock(&RCC_AHBENR, _RCC_AHBENR_DMAEN); /* Setup GPIO pin GPIO_USARTX_TX on USART GPIO port for transmit. */ gpio_set_mode(_USART_GPIO, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, _USART_GPIO_USART_TX); //gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, //GPIO_USART1_RX); /* Setup UART parameters. */ usart_set_baudrate(_USART, 115200); usart_set_databits(_USART, 8); usart_set_stopbits(_USART, USART_STOPBITS_1); usart_set_mode(_USART, USART_MODE_TX); usart_set_parity(_USART, USART_PARITY_NONE); usart_set_flow_control(_USART, USART_FLOWCONTROL_NONE); //usart_set_mode(USART1, USART_MODE_TX_RX); /* Finally enable the USART. */ usart_enable(_USART); nvic_set_priority(_USART_NVIC_DMA_CHANNEL_IRQ, 3); nvic_enable_irq(_USART_NVIC_DMA_CHANNEL_IRQ); #if HAS_AUDIO_UART5 /* Enable clocks for GPIO port C (for GPIO_UART5_TX) and UART5. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_UART5EN); /* Setup GPIO pins to use UART5 */ gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_UART5_TX); /* Setup UART5 parameters. */ usart_set_baudrate(UART5, 9600); usart_set_databits(UART5, 8); usart_set_stopbits(UART5, USART_STOPBITS_1); usart_set_parity(UART5, USART_PARITY_NONE); usart_set_mode(UART5, USART_MODE_TX); /* Finally enable the UART5. */ usart_enable(UART5); #endif }
void mew_bluetooth_init(void) { gpio_mode_setup(MEW_BLUETOOTH_POWER_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, MEW_BLUETOOTH_POWER_PIN); gpio_set_output_options(MEW_BLUETOOTH_POWER_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_100MHZ, MEW_BLUETOOTH_POWER_PIN); gpio_clear(MEW_BLUETOOTH_POWER_PORT, MEW_BLUETOOTH_POWER_PIN); gpio_mode_setup(MEW_BLUETOOTH_RESET_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, MEW_BLUETOOTH_RESET_PIN); gpio_set_output_options(MEW_BLUETOOTH_RESET_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_100MHZ, MEW_BLUETOOTH_RESET_PIN); gpio_set(MEW_BLUETOOTH_RESET_PORT, MEW_BLUETOOTH_RESET_PIN); gpio_mode_setup(MEW_BLUETOOTH_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, MEW_BLUETOOTH_PIN); gpio_set_af(MEW_BLUETOOTH_PORT, MEW_BLUETOOTH_PORT_AF, MEW_BLUETOOTH_PIN); usart_disable(MEW_BLUETOOTH_USART); usart_set_baudrate(MEW_BLUETOOTH_USART, MEW_BLUETOOTH_SPEED); usart_set_databits(MEW_BLUETOOTH_USART, 8); usart_set_stopbits(MEW_BLUETOOTH_USART, USART_STOPBITS_1); usart_set_mode(MEW_BLUETOOTH_USART, USART_MODE_TX_RX); usart_set_parity(MEW_BLUETOOTH_USART, USART_PARITY_NONE); usart_set_flow_control(MEW_BLUETOOTH_USART, USART_FLOWCONTROL_NONE); usart_enable_rx_interrupt(MEW_BLUETOOTH_USART); usart_disable_tx_interrupt(MEW_BLUETOOTH_USART); usart_enable_tx_dma(MEW_BLUETOOTH_USART); usart_enable(MEW_BLUETOOTH_USART); nvic_enable_irq(MEW_BLUETOOTH_IRQ); nvic_enable_irq(MEW_BLUETOOTH_DMA_NVIC_TX); memset(_mew_bt_buffer, 0, MEW_BT_RECEIVE_BUFFER_SIZE); }
/** * Initializes the clocks, the UART peripheral, and the RX and TX buffer * structures. */ static void comm_init(void) { os_char_buffer_init(&bsp_rx_buffer, rx_buffer_mem, BSP_RX_BUFFER_SIZE, NULL); os_char_buffer_init(&bsp_tx_buffer, tx_buffer_mem, BSP_TX_BUFFER_SIZE, enable_usart1_tx_interrupt); rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_USART1); gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO9 | GPIO10); gpio_set_af(GPIOA, GPIO_AF1, GPIO9 | GPIO10); usart_set_baudrate(USART1, 115200); usart_set_databits(USART1, 8); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_set_mode(USART1, USART_MODE_TX_RX); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_stopbits(USART1, USART_CR2_STOP_1_0BIT); usart_enable_rx_interrupt(USART1); usart_enable(USART1); nvic_set_priority(NVIC_USART1_IRQ, 0); nvic_enable_irq(NVIC_USART1_IRQ); }
void usart_setup(void) { /* Setup clock */ /* Enable GPIOA clock for USART. */ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); /* Enable clocks for USART2. */ rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN); /* Setup GPIO pins for USART2 transmit. */ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2); /* Setup USART2 TX pin as alternate function. */ gpio_set_af(GPIOA, GPIO_AF7, GPIO2); /* Setup USART2 parameters. */ usart_set_baudrate(USART2, 115200); usart_set_databits(USART2, 8); usart_set_stopbits(USART2, USART_STOPBITS_1); usart_set_mode(USART2, USART_MODE_TX); usart_set_parity(USART2, USART_PARITY_NONE); usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); /* Finally enable the USART. */ usart_enable(USART2); }
void usart_init( int baudrate ) { gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); #ifdef BUFFERED buffer_reset (&u1rx); buffer_reset (&u1tx); nvic_enable_irq(NVIC_USART1_IRQ); usart_enable_rx_interrupt(USART1); usart_disable_tx_interrupt(USART1); #endif // usart peripheral confguration usart_set_baudrate(USART1, baudrate); usart_set_databits(USART1, 8); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_mode(USART1, USART_MODE_TX_RX); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_enable(USART1); }
void uart_cinit(void *config) { usart = (uint32_t)config; /* board is expected to do pin and clock setup */ /* do usart setup */ //USART_CR1(usart) |= (1 << 15); /* because libopencm3 doesn't know the OVER8 bit */ usart_set_baudrate(usart, 115200); usart_set_databits(usart, 8); usart_set_stopbits(usart, USART_STOPBITS_1); usart_set_mode(usart, USART_MODE_TX_RX); usart_set_parity(usart, USART_PARITY_NONE); usart_set_flow_control(usart, USART_FLOWCONTROL_NONE); /* and enable */ usart_enable(usart); #if 0 usart_send_blocking(usart, 'B'); usart_send_blocking(usart, 'B'); usart_send_blocking(usart, 'B'); usart_send_blocking(usart, 'B'); while (true) { int c; c = usart_recv_blocking(usart); usart_send_blocking(usart, c); } #endif }
static void usart_setup(void) { /* Initialize output ring buffer. */ ring_init(&output_ring, output_ring_buffer, BUFFER_SIZE); /* Enable the USART2 interrupt. */ nvic_enable_irq(NVIC_USART2_IRQ); /* Setup GPIO pin GPIO_USART2_TX on GPIO port A for transmit. */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX); /* Setup GPIO pin GPIO_USART2_RX on GPIO port A for receive. */ gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX); /* Setup UART parameters. */ usart_set_baudrate(USART2, 230400); usart_set_databits(USART2, 8); usart_set_stopbits(USART2, USART_STOPBITS_1); usart_set_parity(USART2, USART_PARITY_NONE); usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); usart_set_mode(USART2, USART_MODE_TX_RX); /* Enable USART2 Receive interrupt. */ USART_CR1(USART2) |= USART_CR1_RXNEIE; /* Finally enable the USART. */ usart_enable(USART2); }
/****************************************************************************** Initialize the hardware to receive (USART based) CAN messages and start the timer for the CANopen stack. INPUT bitrate bitrate in kilobit (fixed at 115200) OUTPUT 1 if successful ******************************************************************************/ unsigned char canInit(unsigned int bitrate) { msg_recv_status = 0; msg_received = 0; /* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN | RCC_APB2ENR_USART1EN); /* Enable the USART1 interrupt. */ nvic_enable_irq(NVIC_USART1_IRQ); /* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port A for transmit. */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); /* Setup GPIO pin GPIO_USART1_RE_RX on GPIO port A for receive. */ gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); /* Setup USART parameters. */ usart_set_baudrate(USART1, 115200); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_set_mode(USART1, USART_MODE_TX_RX); /* Enable USART1 receive interrupts. */ usart_enable_rx_interrupt(USART1); usart_disable_tx_interrupt(USART1); /* Finally enable the USART. */ usart_enable(USART1); /* Initialise the send and receive buffers */ buffer_init(send_buffer,BUFFER_SIZE); buffer_init(receive_buffer,BUFFER_SIZE); return 1; }
void usart_setup(void) { /* Enable all required USART modules */ rcc_periph_clock_enable(USART_RCC_PORT); rcc_periph_clock_enable(USART_RCC_ID); /* Setup GPIO pins for USART transmit. */ gpio_mode_setup(USART_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, USART_RX); gpio_mode_setup(USART_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, USART_TX); // gpio_set_output_options(USART_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_25MHZ, USART_TX); /* Setup USART TX pin as alternate function. */ gpio_set_af(USART_PORT, GPIO_AF7, USART_RX); gpio_set_af(USART_PORT, GPIO_AF7, USART_TX); /* Setup USART parameters. */ usart_set_baudrate(USART_ID, USART_BAUD_RATE); usart_set_databits(USART_ID, 8); usart_set_stopbits(USART_ID, USART_STOPBITS_1); usart_set_mode(USART_ID, USART_MODE_TX_RX); usart_set_parity(USART_ID, USART_PARITY_NONE); usart_set_flow_control(USART_ID, USART_FLOWCONTROL_NONE); /* Finally enable the USART. */ usart_enable(USART_ID); }
static void usart_setup(void) { /* Enable the USART1 interrupt. */ nvic_enable_irq(NVIC_USART1_IRQ); /* Enable USART1 pin software remapping. */ AFIO_MAPR |= AFIO_MAPR_USART1_REMAP; /* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B for transmit. */ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX); /* Setup GPIO pin GPIO_USART1_RE_RX on GPIO port B for receive. */ gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RE_RX); /* Setup UART parameters. */ usart_set_baudrate(USART1, 230400); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_set_mode(USART1, USART_MODE_TX_RX); /* Enable USART1 Receive interrupt. */ USART_CR1(USART1) |= USART_CR1_RXNEIE; /* Finally enable the USART. */ usart_enable(USART1); }
void dbg_serial_init(void) { dbg_fifo_flush( &usart_rx_buf ); dbg_fifo_flush( &usart_tx_buf ); rcc_periph_clock_enable(RCC_AFIO); rcc_periph_clock_enable(DBG_USART_PERIPH); rcc_periph_clock_enable(DBG_USART_TX_PERIPH); #if (DBG_USART_RX_PERIPH != DBG_USART_TX_PERIPH) rcc_periph_clock_enable(DBG_USART_RX_PERIPH); #endif /* Enable the DBG_USART interrupt. */ nvic_enable_irq(DBG_USART_VECTOR); /* Setup GPIO pins for USART transmit. */ gpio_set_mode(DBG_USART_TX_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, DBG_USART_TX_PIN); /* Setup GPIO pins for USART receive. */ gpio_set_mode(DBG_USART_RX_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, DBG_USART_RX_PIN); gpio_set(DBG_USART_RX_PORT, DBG_USART_RX_PIN); /* Setup USART parameters. */ usart_set_baudrate (DBG_USART, 57600); usart_set_databits (DBG_USART, 8); usart_set_stopbits (DBG_USART, USART_STOPBITS_1); usart_set_mode (DBG_USART, USART_MODE_TX_RX); usart_set_parity (DBG_USART, USART_PARITY_NONE); usart_set_flow_control(DBG_USART, USART_FLOWCONTROL_NONE); /* Enable USART Receive interrupt. */ usart_enable_rx_interrupt(DBG_USART); /* Finally enable the USART. */ usart_enable(DBG_USART); }
void usart_setup(void) { /* Enable clocks for GPIO port B (for GPIO_USART1_TX) and USART1. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); gpio_clear(GPIOB, GPIO5); AFIO_MAPR |= AFIO_MAPR_USART1_REMAP; gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX); gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RE_RX); /* Setup UART parameters. */ usart_set_baudrate(USART1, 115200); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_mode(USART1, USART_MODE_TX_RX); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); /* Finally enable the USART. */ usart_enable(USART1); }
void usart_setup(void) { /* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN | RCC_APB2ENR_USART1EN); /* Enable the USART1 interrupt. */ nvic_enable_irq(NVIC_USART1_IRQ); /* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port A for transmit. */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); /* Setup GPIO pin GPIO_USART1_RE_RX on GPIO port A for receive. */ gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); /* Setup UART parameters. */ usart_set_baudrate(USART1, 115200); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_set_mode(USART1, USART_MODE_TX_RX); /* Enable USART1 receive interrupts. */ usart_enable_rx_interrupt(USART1); usart_disable_tx_interrupt(USART1); /* Finally enable the USART. */ usart_enable(USART1); }
/* Set up all the peripherals */ void setup(void) { rcc_clock_setup_in_hsi_out_48mhz(); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN | RCC_APB2ENR_USART1EN); /* GPIO pin for the LED */ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO2); /* GPIO pin for USART TX */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO9); /* Setup USART parameters. */ usart_set_baudrate(USART1, 19200); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_set_mode(USART1, USART_MODE_TX); /* Finally enable the USART. */ usart_enable(USART1); }
void bluetooth_init(void) { rcc_periph_clock_enable(RCC_B_WAKE_SW_PORT); rcc_periph_clock_enable(RCC_B_WAKE_HW_PORT); rcc_periph_clock_enable(RCC_B_CMD_PORT); gpio_mode_setup(B_WAKE_SW_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, B_WAKE_SW_PIN); gpio_mode_setup(B_WAKE_HW_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, B_WAKE_HW_PIN); gpio_mode_setup(B_CMD_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, B_CMD_PIN); //uart rcc_periph_clock_enable(RCC_B_USART); gpio_mode_setup(B_USART_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, B_USART_TX_PIN|B_USART_RX_PIN); gpio_set_af(B_USART_PORT, GPIO_AF1, B_USART_TX_PIN|B_USART_RX_PIN); usart_set_baudrate(B_USART, 115200);//9600 ); usart_set_databits(B_USART, 8); usart_set_stopbits(B_USART, USART_CR2_STOP_1_0BIT); usart_set_mode(B_USART, USART_MODE_TX_RX); usart_set_parity(B_USART, USART_PARITY_NONE); usart_set_flow_control(B_USART, USART_FLOWCONTROL_NONE); usart_enable(B_USART); }
static void usart_setup(void) { /* Enable the USART2 interrupt. */ nvic_enable_irq(NVIC_USART2_IRQ); /* Setup GPIO pins for USART2 transmit. */ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2); /* Setup GPIO pins for USART2 receive. */ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO3); gpio_set_output_options(GPIOA, GPIO_OTYPE_OD, GPIO_OSPEED_25MHZ, GPIO3); /* Setup USART2 TX and RX pin as alternate function. */ gpio_set_af(GPIOA, GPIO_AF7, GPIO2); gpio_set_af(GPIOA, GPIO_AF7, GPIO3); /* Setup USART2 parameters. */ usart_set_baudrate(USART2, 38400); usart_set_databits(USART2, 8); usart_set_stopbits(USART2, USART_STOPBITS_1); usart_set_mode(USART2, USART_MODE_TX_RX); usart_set_parity(USART2, USART_PARITY_NONE); usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); /* Enable USART2 Receive interrupt. */ usart_enable_rx_interrupt(USART2); /* Finally enable the USART. */ usart_enable(USART2); }
/** * Set UART speed * @param lc - UART parameters or NULL for value from cdcacm.c (started - B115200,8,N,1) */ void UART_setspeed(uint32_t UART) { usart_set_baudrate(UART, 9600); usart_set_databits(UART, 8); usart_set_stopbits(UART, USART_STOPBITS_1); usart_set_parity(UART, USART_PARITY_NONE); usart_set_flow_control(UART, USART_FLOWCONTROL_NONE); usart_set_mode(UART, USART_MODE_TX_RX); }
/* Debug output over USART1. */ void usart_setup(void) { usart_set_baudrate(USART1, 460800); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_mode(USART1, USART_MODE_TX_RX); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_enable(USART1); }
/* Configure USART2 as a 38400, 8N1 serial port that has an interrupt * driven receive function (transmit is blocking) */ void uart_setup(int baud) { /* Setup GPIO pins for USART2 transmit. */ gpio_mode_setup(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO6); gpio_mode_setup(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO7); gpio_set_output_options(GPIOC, GPIO_OTYPE_OD, GPIO_OSPEED_25MHZ, GPIO7); gpio_set_af(GPIOC, GPIO_AF8, GPIO6); gpio_set_af(GPIOC, GPIO_AF8, GPIO7); /* Setup USART6 parameters. */ usart_set_baudrate(USART6, baud); usart_set_databits(USART6, 8); usart_set_stopbits(USART6, USART_STOPBITS_1); usart_set_mode(USART6, USART_MODE_TX_RX); usart_set_parity(USART6, USART_PARITY_NONE); usart_set_flow_control(USART6, USART_FLOWCONTROL_NONE); /* Allow for receive interrupts */ buf_ndx = 0; read_ndx = 0; nvic_enable_irq(NVIC_USART6_IRQ); /* Finally enable the USART. */ usart_enable(USART6); usart_enable_rx_interrupt(USART6); /* Setup USART2 parameters. */ usart_set_baudrate(USART2, 38400); usart_set_databits(USART2, 8); usart_set_stopbits(USART2, USART_STOPBITS_1); usart_set_mode(USART2, USART_MODE_TX_RX); usart_set_parity(USART2, USART_PARITY_NONE); usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); /* Allow for receive interrupts */ buf_ndx = 0; read_ndx = 0; nvic_enable_irq(NVIC_USART2_IRQ); /* Finally enable the USART. */ usart_enable(USART2); usart_enable_rx_interrupt(USART2); }
void serial_initialize(u32 baud) { usart_set_baudrate(USART, baud); usart_set_databits(USART, 8); usart_set_stopbits(USART, USART_STOPBITS_1); usart_set_parity(USART, USART_PARITY_NONE); usart_set_flow_control(USART, USART_FLOWCONTROL_NONE); usart_enable(USART); usart_enable_rx_interrupt(USART); //usart_enable_tx_interrupt(USART); }
void usart_setup(int baud) { usart_set_baudrate(USART2, baud); usart_set_databits(USART2, 8); usart_set_stopbits(USART2, USART_CR2_STOP_1_0BIT); usart_set_mode(USART2, USART_MODE_TX_RX); usart_set_parity(USART2, USART_PARITY_NONE); usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); usart_enable(USART2); }
/** * Initalize the Output (TX) mode only (log) */ static void usart_init(void) { usart_set_baudrate(USART6, 921600); usart_set_databits(USART6, 8); usart_set_flow_control(USART6, USART_FLOWCONTROL_NONE); usart_set_mode(USART6, USART_MODE_TX); usart_set_parity(USART6, USART_PARITY_NONE); usart_set_stopbits(USART6, USART_STOPBITS_1); usart_enable(USART6); }
void usart_console_setup(void) { usart_set_baudrate(USART_CONSOLE, 115200); usart_set_databits(USART_CONSOLE, 8); usart_set_stopbits(USART_CONSOLE, USART_STOPBITS_1); usart_set_mode(USART_CONSOLE, USART_MODE_TX); usart_set_parity(USART_CONSOLE, USART_PARITY_NONE); usart_set_flow_control(USART_CONSOLE, USART_FLOWCONTROL_NONE); usart_enable(USART_CONSOLE); }
static void platform_init_usart() { /* USART initialization */ nvic_enable_irq(NVIC_USART1_IRQ); nvic_set_priority(NVIC_USART1_IRQ, 64); gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO6); gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO7); gpio_set_output_options(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_25MHZ, GPIO7); /* Setup USART1 TX and RX pin as alternate function. */ gpio_set_af(GPIOB, GPIO_AF7, GPIO6); gpio_set_af(GPIOB, GPIO_AF7, GPIO7); /* Setup USART2 parameters. */ usart_set_baudrate(USART1, config.console.baud); usart_set_databits(USART1, config.console.data_bits); switch (config.console.stop_bits) { case 1: usart_set_stopbits(USART1, USART_STOPBITS_1); break; default: while (1); } usart_set_mode(USART1, USART_MODE_TX_RX); switch (config.console.parity) { case 'N': usart_set_parity(USART1, USART_PARITY_NONE); break; case 'O': usart_set_parity(USART1, USART_PARITY_ODD); break; case 'E': usart_set_parity(USART1, USART_PARITY_EVEN); break; } usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); /* Finally enable the USART. */ usart_enable(USART1); usart_rx_reset(); }
static void usart_setup(void) { /* Setup USART2 parameters. */ usart_set_baudrate(USART2, 115200); usart_set_databits(USART2, 8); usart_set_stopbits(USART2, USART_STOPBITS_1); usart_set_mode(USART2, USART_MODE_TX_RX); usart_set_parity(USART2, USART_PARITY_NONE); usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); /* Finally enable the USART. */ usart_enable(USART2); }
void usart_peripheral_setup(void) { gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9); gpio_set_af(GPIOA, GPIO_AF7, GPIO9); usart_set_baudrate(USART1, 38400); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); usart_set_mode(USART1, USART_MODE_TX); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_enable(USART1); }
static void usart_setup(void) { /* Setup USART2 parameters. */ usart_set_baudrate(USART1, 38400); usart_set_databits(USART1, 8); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_stopbits(USART1, USART_CR2_STOP_1_0BIT); usart_set_mode(USART1, USART_MODE_TX); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); /* Finally enable the USART. */ usart_enable(USART1); }