Exemplo n.º 1
0
void
Board_FY20AP::com_fini(void)
{
	usart_disable(USART1);
	usart_disable_rx_interrupt(USART1);
	usart_disable_tx_interrupt(USART1);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
int stm32_test_usart(int id)
{
	int ret = -1;
	struct usart_data usart_data;
	uint8_t data[] = {'A', 'B', 'C', 'D', 'E', 'F' };

	usart_data.data = &data[0];
	usart_data.size = sizeof(data);

	/* set USART parameters */
	usart_set_word_length(id, 8);
	usart_set_baud_rate(id, 57600);
	usart_set_stop_bit(id, 1);

	/* enable USART2 */
	usart_enable(id);

	usart_start_tx(id, &usart_data);

	/* Disable USART2 */
	usart_disable(id);

	ret = 0;
	return ret;
}
Exemplo n.º 4
0
/** Configure the format. Set the number of bits, parity and the number of stop bits
 *
 * @param obj       The serial object
 * @param data_bits The number of data bits
 * @param parity    The parity
 * @param stop_bits The number of stop bits
 */
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
{
    uint16_t uen_flag = 0U;
    struct serial_s *p_obj = GET_SERIAL_S(obj);

    /* store the UEN flag */
    uen_flag = USART_CTL0(p_obj->uart) & USART_CTL0_UEN;

    /* disable the UART clock first */
    usart_disable(p_obj->uart);

    /* configurate the UART parity */
    switch (parity) {
        case ParityOdd:
            p_obj->parity = USART_PM_ODD;
            usart_parity_config(p_obj->uart, USART_PM_ODD);
            break;

        case ParityEven:
            p_obj->parity = USART_PM_EVEN;
            usart_parity_config(p_obj->uart, USART_PM_EVEN);
            break;

        case ParityForced0:
        case ParityForced1:
        default:
            p_obj->parity = USART_PM_NONE;
            usart_parity_config(p_obj->uart, USART_PM_NONE);
            break;
    }

    if (p_obj->parity == USART_PM_NONE) {
        if (data_bits == 9) {
            usart_word_length_set(p_obj->uart, USART_WL_9BIT);
        } else if (data_bits == 8) {
            usart_word_length_set(p_obj->uart, USART_WL_8BIT);
        } else if (data_bits == 7) {
            return;
        }
    } else {
        if (data_bits == 9) {
            return;
        } else if (data_bits == 8) {
            usart_word_length_set(p_obj->uart, USART_WL_9BIT);
        } else if (data_bits == 7) {
            usart_word_length_set(p_obj->uart, USART_WL_8BIT);
        }
    }

    if (stop_bits == 2) {
        usart_stop_bit_set(p_obj->uart, USART_STB_2BIT);
    } else {
        usart_stop_bit_set(p_obj->uart, USART_STB_1BIT);
    }

    /* restore the UEN flag */
    if (RESET != uen_flag) {
        usart_enable(p_obj->uart);
    }
}
/* === IMPLEMENTATION ====================================================== */
static inline void usart_configure_flowcontrol(void)
{
	struct usart_config config_usart;
#if UART_FLOWCONTROL_6WIRE_MODE == true
	usart_disable(&usart_instance);
	usart_reset(&usart_instance);
#endif
	usart_get_config_defaults(&config_usart);

	config_usart.baudrate = CONF_FLCR_BLE_BAUDRATE;
	config_usart.generator_source = CONF_FLCR_BLE_UART_CLOCK;
	config_usart.mux_setting = CONF_FLCR_BLE_MUX_SETTING;
	config_usart.pinmux_pad0 = CONF_FLCR_BLE_PINMUX_PAD0;
	config_usart.pinmux_pad1 = CONF_FLCR_BLE_PINMUX_PAD1;
	config_usart.pinmux_pad2 = CONF_FLCR_BLE_PINMUX_PAD2;
	config_usart.pinmux_pad3 = CONF_FLCR_BLE_PINMUX_PAD3;

	while (usart_init(&usart_instance, CONF_FLCR_BLE_USART_MODULE, &config_usart) != STATUS_OK);

	usart_enable(&usart_instance);
	
	/* register and enable usart callbacks */
	usart_register_callback(&usart_instance,
	serial_drv_read_cb, USART_CALLBACK_BUFFER_RECEIVED);
	usart_register_callback(&usart_instance,
	serial_drv_write_cb, USART_CALLBACK_BUFFER_TRANSMITTED);
	usart_enable_callback(&usart_instance, USART_CALLBACK_BUFFER_RECEIVED);
	usart_enable_callback(&usart_instance, USART_CALLBACK_BUFFER_TRANSMITTED);
	serial_read_byte(&rx_data);
}
Exemplo n.º 6
0
void rc100Terminate(void)
{

// Closing device
	usart_detach_interrupt(USART2);
	usart_disable(USART2);

}
Exemplo n.º 7
0
/** Configure the serial for the flow control. It sets flow control in the hardware
 *  if a serial peripheral supports it, otherwise software emulation is used.
 *
 * @param obj    The serial object
 * @param type   The type of the flow control. Look at the available FlowControl types.
 * @param rxflow The TX pin name
 * @param txflow The RX pin name
 */
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
{
    uint16_t uen_flag = 0U;
    struct serial_s *p_obj = GET_SERIAL_S(obj);

    /* store the UEN flag */
    uen_flag = USART_CTL0(p_obj->uart) & USART_CTL0_UEN;

    UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
    UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);

    p_obj->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
    MBED_ASSERT(p_obj->uart != (UARTName)NC);

    /* disable USART to modify CTS/RTS configuration */
    usart_disable(p_obj->uart);

    if (type == FlowControlNone) {
        p_obj->hw_flow_ctl = USART_HWCONTROL_NONE;
        usart_hardware_flow_cts_config(p_obj->uart, USART_CTS_DISABLE);
        usart_hardware_flow_rts_config(p_obj->uart, USART_RTS_DISABLE);
    }

    if (type == FlowControlRTS) {
        MBED_ASSERT(uart_rts != (UARTName)NC);
        p_obj->hw_flow_ctl = USART_HWCONTROL_RTS;
        p_obj->pin_rts = rxflow;
        pinmap_pinout(rxflow, PinMap_UART_RTS);
        usart_hardware_flow_cts_config(p_obj->uart, USART_CTS_DISABLE);
        usart_hardware_flow_rts_config(p_obj->uart, USART_RTS_ENABLE);
    }

    if (type == FlowControlCTS) {
        MBED_ASSERT(uart_cts != (UARTName)NC);
        p_obj->hw_flow_ctl = USART_HWCONTROL_CTS;
        p_obj->pin_cts = txflow;
        pinmap_pinout(txflow, PinMap_UART_CTS);
        usart_hardware_flow_rts_config(p_obj->uart, USART_RTS_DISABLE);
        usart_hardware_flow_cts_config(p_obj->uart, USART_CTS_ENABLE);
    }

    if (type == FlowControlRTSCTS) {
        MBED_ASSERT(uart_rts != (UARTName)NC);
        MBED_ASSERT(uart_cts != (UARTName)NC);
        p_obj->hw_flow_ctl = USART_HWCONTROL_RTS_CTS;
        p_obj->pin_rts = rxflow;
        p_obj->pin_cts = txflow;
        pinmap_pinout(txflow, PinMap_UART_CTS);
        pinmap_pinout(rxflow, PinMap_UART_RTS);
        usart_hardware_flow_cts_config(p_obj->uart, USART_CTS_ENABLE);
        usart_hardware_flow_rts_config(p_obj->uart, USART_RTS_ENABLE);
    }

    /* restore the UEN flag */
    if (RESET != uen_flag) {
        usart_enable(p_obj->uart);
    }
}
Exemplo n.º 8
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);
}
Exemplo n.º 9
0
void usart_setup(const usart_dev *dev, uint32_t baudRate, uint16_t wordLength,
	uint16_t stopBits, uint16_t parity, uint16_t mode, uint16_t hardwareFlowControl)
{
    /* Check the parameters */
    assert_param(IS_USART_ALL_PERIPH(dev->USARTx));
    assert_param(IS_USART_BAUDRATE(baud));
    assert_param(IS_USART_STOPBITS(stopbits));
    assert_param(IS_USART_PARITY(parity));
    assert_param(IS_USART_WORD_LENGTH(wordLength));
    assert_param(IS_USART_MODE(mode));
    assert_param(IS_USART_HARDWARE_FLOW_CONTROL(hardwareFlowControl));

    memset(dev->state, 0, sizeof(*dev->state));

    dev->state->txbusy = 0;
    dev->state->callback = 0;

    /* Disable USARTx */
    usart_disable(dev);

    rb_init(dev->txrb, USART_TX_BUF_SIZE, dev->state->tx_buf);
    rb_init(dev->rxrb, USART_RX_BUF_SIZE, dev->state->rx_buf);

    /* Enables the USART's 8x oversampling mode. */
    USART_OverSampling8Cmd(dev->USARTx, ENABLE);

    USART_ClockInitTypeDef USART_InitClock;
    USART_ClockStructInit(&USART_InitClock);
    USART_ClockInit(dev->USARTx, &USART_InitClock);

    USART_InitTypeDef USART_config;
    USART_StructInit(&USART_config);
    USART_config.USART_BaudRate = baudRate;
    USART_config.USART_WordLength = wordLength;
    USART_config.USART_StopBits = stopBits;
    USART_config.USART_Parity = parity;
    USART_config.USART_Mode = mode;
    USART_config.USART_HardwareFlowControl = hardwareFlowControl;

    USART_Init(dev->USARTx, &USART_config);

    dev->USARTx->CR1 &= ~(USART_MASK_IDLEIE | USART_MASK_RXNEIE | USART_MASK_TCEIE | USART_MASK_TXEIE | USART_MASK_PEIE);
    dev->USARTx->CR2 &= ~(USART_MASK2_LBDIE);
    dev->USARTx->CR3 &= ~(USART_MASK3_CTSIE | USART_MASK3_EIE);
    
    if(mode & USART_Mode_Rx) { /* Enable Rx request */
        USART_ClearFlag(dev->USARTx, USART_FLAG_RXNE);
        dev->USARTx->CR1 |= USART_MASK_RXNEIE;
    }

    if(mode & USART_Mode_Tx) {
        USART_ClearFlag(dev->USARTx, USART_FLAG_TC);
    }    

    enable_nvic_irq(dev->irq, UART_INT_PRIORITY);
}
Exemplo n.º 10
0
/*
 * Disables the serial port and turns off power to the NFC module.
 */
void module_power_down(void)
{
  // Sets USART pins to high impedance to avoid powering the module
  // through the I/O pins.
  usart_disable();
  _delay_ms(1);
  // Output high impedance = power off (bias transistor)
  MODULE_POWER_DDR &= ~_BV(MODULE_POWER_PIN);
  MODULE_POWER_PORT &= ~_BV(MODULE_POWER_PIN);
}
Exemplo n.º 11
0
/** Disable all USARTs. */
void usarts_disable()
{
  /* Disable DMA channels. */
  /* Disable all USARTs. */

  if (!all_uarts_enabled)
    return;

  usart_tx_dma_disable(&ftdi_state.tx);
  usart_rx_dma_disable(&ftdi_state.rx);
  usart_disable(USART6);

  usart_tx_dma_disable(&uarta_state.tx);
  usart_rx_dma_disable(&uarta_state.rx);
  usart_disable(USART1);

  usart_tx_dma_disable(&uartb_state.tx);
  usart_rx_dma_disable(&uartb_state.rx);
  usart_disable(USART3);
}
Exemplo n.º 12
0
void
usart_uninit(int usart, int irq) {
  /* Disable the IRQ. */
  nvic_disable_irq(irq);

  /* Disable the USART. */
  usart_disable(usart);

  /* Disable usart Receive interrupt. */
  USART_CR1(usart) &= ~USART_CR1_RXNEIE;
}
Exemplo n.º 13
0
int glue_set_line_coding_cb(uint32_t baud, uint8_t databits,
	enum usb_cdc_line_coding_bParityType cdc_parity,
	enum usb_cdc_line_coding_bCharFormat cdc_stopbits)
{
	int uart_parity;
	int uart_stopbits;

	if (databits < 8 || databits > 9) {
		return 0;
	}

	/* Be careful here, ST counts parity as a data bit */
	switch (cdc_parity) {
	case USB_CDC_NO_PARITY:
		uart_parity = USART_PARITY_NONE;
		break;
	case USB_CDC_ODD_PARITY:
		uart_parity = USART_PARITY_ODD;
		databits++;
		break;
	case USB_CDC_EVEN_PARITY:
		uart_parity = USART_PARITY_EVEN;
		databits++;
		break;
	default:
		return 0;
	}

	switch (cdc_stopbits) {
	case USB_CDC_1_STOP_BITS:
		uart_stopbits = USART_STOPBITS_1;
		break;
	case USB_CDC_2_STOP_BITS:
		uart_stopbits = USART_STOPBITS_2;
		break;
	default:
		return 0;
	}

	/* Disable the UART while we mess with its settings */
	usart_disable(USART2);
	/* Set communication parameters */
	usart_set_baudrate(USART2, baud);
	usart_set_databits(USART2, databits);
	usart_set_parity(USART2, uart_parity);
	usart_set_stopbits(USART2, uart_stopbits);
	/* Back to work. */
	usart_enable(USART2);

	return 1;
}
Exemplo n.º 14
0
/** Set up USART parameters for particular USART.
 * \param usart USART to set up parameters for.
 * \param baud  Baud rate to set.
 */
void usart_set_parameters(u32 usart, u32 baud)
{
  /* Setup UART parameters. */
  baud = baud;
  usart_disable(usart);
  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_set_mode(usart, USART_MODE_TX_RX);

  /* Enable the USART. */
  usart_enable(usart);
}
Exemplo n.º 15
0
static void setupUSART(usart_dev *dev, uint32 baud)
{
    uint32 i = USART_RX_BUF_SIZE;
    /* FIXME: need some preprocess here, according to specific board */
    if (dev == USART1) {
        gpio_set_mode(GPIOA, 9, GPIO_AF_OUTPUT_PP);
        gpio_set_mode(GPIOA, 10, GPIO_INPUT_FLOATING);
    }
    usart_init(dev);
    usart_set_baud_rate(dev, 72000000UL, baud);
    usart_disable(dev);
    usart_enable(dev);
    /* flush buffer */
    while (i--) {
        usart_putc(dev, '\r');
    }
}
Exemplo n.º 16
0
void
usart_init(int usart, int irq, int baudrate, int over8) {
  /* Setup USART parameters. */
  nvic_disable_irq(irq);
  usart_disable_rx_interrupt(usart);
  usart_disable_tx_interrupt(usart);
  usart_disable(usart);
  USART_CR1(usart) |= over8;  /* This doubles the listed baudrate. */
  usart_set_baudrate(usart, baudrate);
  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);
  /* Finally enable the USART. */
  usart_enable(usart);
  usart_enable_rx_interrupt(usart);
  usart_enable_tx_interrupt(usart);
  nvic_enable_irq(irq);
}
Exemplo n.º 17
0
/** Configure the baud rate
 *
 * @param obj      The serial object
 * @param baudrate The baud rate to be configured
 */
void serial_baud(serial_t *obj, int baudrate)
{
    uint16_t uen_flag = 0U;
    struct serial_s *p_obj = GET_SERIAL_S(obj);

    /* store the UEN flag */
    uen_flag = USART_CTL0(p_obj->uart) & USART_CTL0_UEN;

    /* disable the USART first */
    usart_disable(p_obj->uart);

    usart_baudrate_set(p_obj->uart, baudrate);

    p_obj->baudrate = baudrate;

    /* restore the UEN flag */
    if (RESET != uen_flag) {
        usart_enable(p_obj->uart);
    }
}
Exemplo n.º 18
0
/**
 * Set up USART2.
 * This one is connected via the virtual serial port on the Nucleo Board
 */
static void usart_setup(uint32_t baud)
{
    rcc_periph_clock_enable(RCC_GPIOA);
    rcc_periph_clock_enable(RCC_AFIO);
    rcc_periph_clock_enable(RCC_USART2);

    usart_disable(USART2);

    gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
                  GPIO_USART2_TX | GPIO_USART2_RX);

    usart_set_baudrate(USART2, baud);
    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);

    usart_enable(USART2);
}
Exemplo n.º 19
0
/*
 * usart_init() - Initialize USART Debug Port
 *
 * INPUT
 *     none
 * OUTPUT
 *     none
 */
void usart_init(void)
{
    /* Setup PB10 for USART-TX */
    gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO10);
    gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO10);

    /* Setup PB11 for USART-RX */
    gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11);
    gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO11);

    /* Set PB10 and PB11 to USART3 alternate aunction */
    gpio_set_af(GPIOB, 7, GPIO10);
    gpio_set_af(GPIOB, 7, GPIO11);

    /*enable USART3 clock source */
    rcc_periph_clock_enable(RCC_USART3);

    /* disable USART3 before you are allow to write to USART3 registers */
    usart_disable(USART3_BASE)  ;

    /* set Word Length */
    usart_set_databits(USART3_BASE, 8);

    /* Set Transmit/Receive mode */
    usart_set_mode(USART3_BASE, USART_CR1_RE | USART_CR1_TE);

    usart_set_stopbits(USART3_BASE, USART_CR2_STOPBITS_1);

    /* disable parity */
    usart_set_parity(USART3_BASE, 0); /* USART_CR1_PCE */

    usart_set_flow_control(USART3_BASE, 0);

    usart_set_baudrate(USART3_BASE, 115200);

    /* enable USART */
    usart_enable(USART3_BASE);

    /* Note : RDR= Read data, TDR=Transmit data */
}
Exemplo n.º 20
0
void HardwareSerial::end(void) {
    usart_disable(this->usart_device);
}
Exemplo n.º 21
0
/*---------------------------------------------------------------------------*/
static int
close(void)
{
  usart_disable(&usart_instance);
  return 1;
}
Exemplo n.º 22
0
otError otPlatUartDisable(void)
{
    usart_disable(&sUsartInstance);

    return OT_ERROR_NONE;
}
Exemplo n.º 23
0
void uart7_cfini(uint32_t whichUsart)
{
	usart_disable(whichUsart);
}
Exemplo n.º 24
0
/**
 * release the system resources associated with the specified usart device.
 */
void
usart_free(usart *us)
{
  usart_disable(us);
  system_free((byte *)us);
}
Exemplo n.º 25
0
void UARTClass::end( void )
{
    usart_disable(this->_dev);
}
Exemplo n.º 26
0
int  hal_uart_dma_set_baud(uint32_t baud){
	usart_disable(USART3);
	usart_set_baudrate(USART3, baud);
	usart_enable(USART3);
	return 0;
}
Exemplo n.º 27
0
void gps_end(void){
    usart_disable(GPS_USART);
    gpio_write_bit(GPIOA, 8, 0);
}
Exemplo n.º 28
0
void
uart_cfini(void)
{
	usart_disable(usart);
}
Exemplo n.º 29
0
void UART_Stop()
{
    usart_disable(_USART);
}
Exemplo n.º 30
0
void UART_Stop()
{
    usart_disable(USART1);
}