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);
}
Beispiel #2
0
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);
}
Beispiel #3
0
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);
}
Beispiel #4
0
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);

}
Beispiel #5
0
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);
}
static void usart_setup(void)
{
	/* Enable the USART1 interrupt. */
	nvic_enable_irq(NVIC_USART3_IRQ);

	/* Setup GPIO pins for USART3 transmit. */
	gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO10);

	/* Setup GPIO pins for USART3 receive. */
	gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11);
	gpio_set_output_options(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_25MHZ, GPIO11);

	/* Setup USART3 TX and RX pin as alternate function. */
	gpio_set_af(GPIOB, GPIO_AF7, GPIO10);
	gpio_set_af(GPIOB, GPIO_AF7, GPIO11);

	/* Setup USART3 parameters. */
	usart_set_baudrate(USART3, 115200);
	usart_set_databits(USART3, 8);
	usart_set_stopbits(USART3, USART_STOPBITS_1);
	usart_set_mode(USART3, USART_MODE_TX_RX);
	usart_set_parity(USART3, USART_PARITY_NONE);
	usart_set_flow_control(USART3, USART_FLOWCONTROL_NONE);

	/* Enable USART1 Receive interrupt. */
	usart_enable_rx_interrupt(USART3);

	/* Finally enable the USART. */
	usart_enable(USART3);
}
Beispiel #7
0
/**
 * \brief Initialize USART in SPI master mode.
 *
 * This function initializes the USART module in SPI master mode using the
 * usart_spi_options_t configuration structure and CPU frequency.
 *
 * \param usart The USART module.
 * \param opt The RS232 configuration option.
 */
void usart_init_spi(USART_t *usart, const usart_spi_options_t *opt)
{
	usart->UBRR = 0;

	usart_enable_module_clock(usart);
	usart_set_mode(usart, USART_CMODE_MSPI_gc);

	if (opt->spimode == 1 || opt->spimode == 3) {
		usart->UCSRnC |= USART_UCPHA_bm;
	} else {
		usart->UCSRnC &= ~USART_UCPHA_bm;
	}
	if (opt->spimode == 2 || opt->spimode == 3) {
		usart->UCSRnC |= USART_UCPOL_bm;
	} else {
		usart->UCSRnC &= ~USART_UCPOL_bm;
	}	
	
	if (opt->data_order) {
		usart->UCSRnC |= USART_DORD_bm;
	} else {
		usart->UCSRnC &= ~USART_DORD_bm;
	}
	
	
	usart_spi_set_baudrate(usart, opt->baudrate,
			sysclk_get_source_clock_hz());
	usart_tx_enable(usart);
	usart_rx_enable(usart);
}
Beispiel #8
0
/**
 * \brief Test physical loop-back with some characters in sunc mode.
 *
 * This function sends a character over USART on loop back to verify that init
 * and sending/receiving works. A jumper is connected on the USART.
 *
 * \param test Current test case.
 */
static void run_loopback_syncmode_test(const struct test_case *test)
{
	uint8_t out_c = 'c';
	uint8_t in_c  = 0;
        port_pin_t sck_pin;
        
        sysclk_enable_module(POWER_RED_REG0, PRUSART0_bm);
        
        usart_set_mode(&CONF_UNIT_USART, USART_CMODE_SYNCHRONOUS_gc);

	sck_pin = IOPORT_CREATE_PIN(PORTE, 2);
	ioport_configure_port_pin(ioport_pin_to_port(sck_pin),
				ioport_pin_to_mask(sck_pin),
				IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH );
        
        usart_spi_set_baudrate(&CONF_UNIT_USART, CONF_UNIT_BAUDRATE,
			sysclk_get_source_clock_hz());
	usart_tx_enable(&CONF_UNIT_USART);
	usart_rx_enable(&CONF_UNIT_USART);

	usart_putchar(&CONF_UNIT_USART, out_c);
	in_c = usart_getchar(&CONF_UNIT_USART);

	test_assert_true(test, in_c == out_c,
	   "Read character through sync mode is not correct: %d != %d", in_c, out_c);			
}
Beispiel #9
0
void uart7_cinit(uint32_t whichUsart)
{


	/* 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(whichUsart, 57600);
	usart_set_databits(whichUsart, 8);
	usart_set_stopbits(whichUsart, USART_STOPBITS_1);
	usart_set_mode(whichUsart, USART_MODE_TX_RX);
	usart_set_parity(whichUsart, USART_PARITY_NONE);
	usart_set_flow_control(whichUsart, USART_FLOWCONTROL_NONE);

	/* and enable */
	usart_enable(whichUsart);


#if 0
	usart_send_blocking(whichUsart, 'B');
	usart_send_blocking(whichUsart, 'B');
	usart_send_blocking(whichUsart, 'B');
	usart_send_blocking(whichUsart, 'B');

	while (true) {
		int c;
		c = usart_recv_blocking(whichUsart);
		usart_send_blocking(whichUsart, c);
	}

#endif
}
Beispiel #10
0
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);
}
Beispiel #11
0
void usart_setup(void)
{
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
	rcc_periph_clock_enable(RCC_GPIOA);
	rcc_periph_clock_enable(RCC_USART1);
	rcc_periph_clock_enable(RCC_AFIO);
/* 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);
}
static void usart_setup(void)
{
	/* Enable the USART1 interrupt. */
	nvic_enable_irq(NVIC_USART1_IRQ);

	/* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B 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 B for receive. */
	gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
		      GPIO_CNF_INPUT_FLOAT, GPIO_USART1_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);
}
Beispiel #13
0
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);

}
Beispiel #14
0
/**
 * 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);
}
Beispiel #15
0
void UART_Initialize()
{
    /* Enable clocks for GPIO port containing _USART and USART */
    rcc_periph_clock_enable(get_rcc_from_port(UART_CFG.uart));
    rcc_periph_clock_enable(get_rcc_from_pin(UART_CFG.rx));
    rcc_periph_clock_enable(get_rcc_from_pin(UART_CFG.tx));

    /* Enable DMA clock */
    rcc_periph_clock_enable(get_rcc_from_port(USART_DMA.dma));

    /* Setup GPIO pin GPIO_USARTX_TX on USART GPIO port for transmit.
       Set normal function to input as this is mode reverted to in half-duplex receive */
    GPIO_setup_input(UART_CFG.rx, ITYPE_FLOAT);
    GPIO_setup_output_af(UART_CFG.tx, OTYPE_PUSHPULL, UART_CFG.uart);

    /* Setup UART parameters. */
    UART_SetDataRate(0);
    UART_SetFormat(8, UART_PARITY_NONE, UART_STOPBITS_1);
    UART_SetDuplex(UART_DUPLEX_FULL);
    usart_set_flow_control(UART_CFG.uart, USART_FLOWCONTROL_NONE);
    usart_set_mode(UART_CFG.uart, USART_MODE_TX_RX);

    /* Finally enable the USART. */
    usart_enable(UART_CFG.uart);

    nvic_set_priority(get_nvic_dma_irq(USART_DMA), 3);
    nvic_enable_irq(get_nvic_dma_irq(USART_DMA));

#if HAS_AUDIO_UART
    /* Enable clocks for GPIO port C (for GPIO_UART5_TX) and UART5. */
    rcc_periph_clock_enable(get_rcc_from_port(AUDIO_UART_CFG.uart));
    rcc_periph_clock_enable(get_rcc_from_pin(AUDIO_UART_CFG.tx));

    /* Setup GPIO pins to use UART5 */
    GPIO_setup_output_af(AUDIO_UART_CFG.tx, OTYPE_PUSHPULL, AUDIO_UART_CFG.uart);

    /* Setup UART5 parameters. */
    usart_set_baudrate(AUDIO_UART_CFG.uart, 9600);
    usart_set_databits(AUDIO_UART_CFG.uart, 8);
    usart_set_stopbits(AUDIO_UART_CFG.uart, USART_STOPBITS_1);
    usart_set_parity(AUDIO_UART_CFG.uart, USART_PARITY_NONE);
    usart_set_mode(AUDIO_UART_CFG.uart, USART_MODE_TX);

    /* Finally enable the AUDIO_UART_CFG.uart. */
    usart_enable(AUDIO_UART_CFG.uart);
#endif
}
Beispiel #16
0
/**
 * 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);
}
Beispiel #17
0
/* 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);
}
Beispiel #18
0
void UART_Stop()
{
    UART_StopReceive();
    nvic_disable_irq(get_nvic_dma_irq(USART_DMA));
    usart_set_mode(UART_CFG.uart, 0);
    usart_disable(UART_CFG.uart);
    rcc_periph_clock_disable(get_rcc_from_port(UART_CFG.uart));
    GPIO_setup_input(UART_CFG.tx, ITYPE_FLOAT);
}
Beispiel #19
0
/* 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);
}
Beispiel #20
0
/**
 * \brief Initialize USART in RS232 mode.
 *
 * This function initializes the USART module in RS232 mode using the
 * usart_rs232_options_t configuration structure and CPU frequency.
 *
 * \param usart The USART module.
 * \param opt The RS232 configuration option.
 */
void usart_init_rs232(USART_t *usart, const usart_rs232_options_t *opt)
{
    usart_enable_module_clock(usart);
    usart_set_mode(usart, USART_CMODE_ASYNCHRONOUS_gc);
    usart_format_set(usart, opt->charlength, opt->paritytype,
                     opt->stopbits);
    usart_set_baudrate(usart, opt->baudrate, sysclk_get_per_hz());
    usart_tx_enable(usart);
    usart_rx_enable(usart);
}
void USART_L_init(void)
{
	usart_set_mode(&Wireless_L_USART,USART_CMODE_ASYNCHRONOUS_gc);
	usart_format_set(&Wireless_L_USART,USART_CHSIZE_8BIT_gc,USART_PMODE_DISABLED_gc,false);
	usart_set_rx_interrupt_level(&Wireless_L_USART,USART_INT_LVL_MED);
	//usart_set_tx_interrupt_level(&Wireless_L_USART,USART_INT_LVL_MED);
	usart_set_baudrate(&Wireless_L_USART,USART_BUADRATE,F_CPU);
	usart_tx_enable(&Wireless_L_USART);
	usart_rx_enable(&Wireless_L_USART);
}
/**
 * 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);
}
Beispiel #23
0
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);
}
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);
}
Beispiel #25
0
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);
}
Beispiel #26
0
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);
}
Beispiel #27
0
/**
 * \brief Initialize USART in RS232 mode.
 *
 * This function initializes the USART module in RS232 mode using the
 * usart_rs232_options_t configuration structure and CPU frequency.
 *
 * \param usart The USART module.
 * \param opt The RS232 configuration option.
 *
 * \retval true if the initialization was successfull
 * \retval false if the initialization failed (error in baud rate calculation)
 */
bool usart_init_rs232(USART_t *usart, const usart_rs232_options_t *opt)
{
	bool result;
	sysclk_enable_peripheral_clock(usart);
	usart_set_mode(usart, USART_CMODE_ASYNCHRONOUS_gc);
	usart_format_set(usart, opt->charlength, opt->paritytype,
			opt->stopbits);
	result = usart_set_baudrate(usart, opt->baudrate, sysclk_get_per_hz());
	usart_tx_enable(usart);
	usart_rx_enable(usart);
	
	return result;
}
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);
}
Beispiel #29
0
void usart_init(uint32_t arg_usart, uint32_t baudrate)
{
	usart_set_baudrate(arg_usart, baudrate);
	usart_set_databits(arg_usart, 8);
	usart_set_flow_control(arg_usart, USART_FLOWCONTROL_NONE);
	usart_set_mode(arg_usart, USART_MODE_TX | USART_MODE_RX);
	usart_set_parity(arg_usart, USART_PARITY_NONE);
	usart_set_stopbits(arg_usart, USART_STOPBITS_1);

	usart_enable_rx_interrupt(arg_usart);
	usart_enable(arg_usart);
	usart = arg_usart;
}
Beispiel #30
0
static void usart_setup(void) {
    /* 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 UART parameters. */
    usart_set_baudrate(USART1, 57600);
    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);
}