Exemple #1
0
void uart0_init( void ) {

  uart_periph_init(&uart0);
  uart0.reg_addr = UART0_BASE;

#ifdef USE_UART0_RX_ONLY
  // only use the RX0 P0.1 pin, no TX
  PINSEL0 = (PINSEL0 & ~U0_PINMASK_RX) | U0_PINSEL_RX;
#else
  // set port pins for UART0
  PINSEL0 = (PINSEL0 & ~U0_PINMASK) | U0_PINSEL;
#endif

  // initialize uart parameters
  uart_disable_interrupts(&uart0);
  uart_set_baudrate(&uart0, UART0_BAUD);

  // initialize the interrupt vector
  VICIntSelect &= ~VIC_BIT(VIC_UART0);                // UART0 selected as IRQ
  VICIntEnable = VIC_BIT(VIC_UART0);                  // UART0 interrupt enabled
  _VIC_CNTL(UART0_VIC_SLOT) = VIC_ENABLE | VIC_UART0;
  _VIC_ADDR(UART0_VIC_SLOT) = (uint32_t)uart0_ISR;    // address of the ISR

  uart_enable_interrupts(&uart0);
}
Exemple #2
0
void usbuart_init(void)
{
	UART_PIN_SETUP();
	
	periph_clock_enable(USBUART_CLK);
	__asm__("nop"); __asm__("nop"); __asm__("nop");
	
	uart_disable(USBUART);

	/* Setup UART parameters. */
	uart_clock_from_sysclk(USBUART);
	uart_set_baudrate(USBUART, 38400);
	uart_set_databits(USBUART, 8);
	uart_set_stopbits(USBUART, 1);
	uart_set_parity(USBUART, UART_PARITY_NONE);

	// Enable FIFO
	uart_enable_fifo(USBUART);

	// Set FIFO interrupt trigger levels to 1/8 full for RX buffer and
	// 7/8 empty (1/8 full) for TX buffer
	uart_set_fifo_trigger_levels(USBUART, UART_FIFO_RX_TRIG_1_8, UART_FIFO_TX_TRIG_7_8);

	uart_clear_interrupt_flag(USBUART, UART_INT_RX | UART_INT_RT);

	/* Enable interrupts */
	uart_enable_interrupts(UART0, UART_INT_RX| UART_INT_RT);

	/* Finally enable the USART. */
	uart_enable(USBUART);

	//nvic_set_priority(USBUSART_IRQ, IRQ_PRI_USBUSART);
	nvic_enable_irq(USBUART_IRQ);
}
Exemple #3
0
void uart1_init( void ) {

  uart_periph_init(&uart1);
  uart1.reg_addr = UART1_BASE;

#ifdef USE_UART1_RX_ONLY
  // only use the RX1 P0.9 pin, no TX
  PINSEL0 = (PINSEL0 & ~U1_PINMASK_RX) | U1_PINSEL_RX;
#else
  // set port pins for UART1
  PINSEL0 = (PINSEL0 & ~U1_PINMASK) | U1_PINSEL;
#endif

  uart_disable_interrupts(&uart1);
  uart_set_baudrate(&uart1, UART1_BAUD);

  // initialize the interrupt vector
  VICIntSelect &= ~VIC_BIT(VIC_UART1);                // UART1 selected as IRQ
  VICIntEnable = VIC_BIT(VIC_UART1);                  // UART1 interrupt enabled
  _VIC_CNTL(UART1_VIC_SLOT) = VIC_ENABLE | VIC_UART1;
  _VIC_ADDR(UART1_VIC_SLOT) = (uint32_t)uart1_ISR;    // address of the ISR

  // enable receiver interrupts
  uart_enable_interrupts(&uart1);
}
static void uart_setup(void)
{
	u32 pins;
	/* Enable GPIOA in run mode. */
	periph_clock_enable(RCC_GPIOA);
	/* Configure PA0 and PA1 as alternate function pins */
	pins = GPIO0 | GPIO1;
	GPIO_AFSEL(GPIOA) |= pins;
	GPIO_DEN(GPIOA) |= pins;
	/* PA0 and PA1 are muxed to UART0 during power on, by default */

	/* Enable the UART clock */
	periph_clock_enable(RCC_UART0);
	/* We need a brief delay before we can access UART config registers */
	__asm__("nop");
	/* Disable the UART while we mess with its setings */
	uart_disable(UART0);
	/* Configure the UART clock source as precision internal oscillator */
	uart_clock_from_piosc(UART0);
	/* Set communication parameters */
	uart_set_baudrate(UART0, 921600);
	uart_set_databits(UART0, 8);
	uart_set_parity(UART0, UART_PARITY_NONE);
	uart_set_stopbits(UART0, 1);
	/* Now that we're done messing with the settings, enable the UART */
	uart_enable(UART0);

}
Exemple #5
0
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
{
	uart_set_baudrate(USBUART, coding->dwDTERate);
	uart_set_databits(USBUART, coding->bDataBits);
	switch(coding->bCharFormat) {
	case 0:
	case 1:
		uart_set_stopbits(USBUART, 1);
		break;
	case 2:
		uart_set_stopbits(USBUART, 2);
		break;
	}
	switch(coding->bParityType) {
	case 0:
		uart_set_parity(USBUART, UART_PARITY_NONE);
		break;
	case 1:
		uart_set_parity(USBUART, UART_PARITY_ODD);
		break;
	case 2:
		uart_set_parity(USBUART, UART_PARITY_EVEN);
		break;
	}
}
Exemple #6
0
uart_t*
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size)
{
	uart_t* uart = (uart_t*) malloc(sizeof(uart_t));
	if(uart == NULL)
		return NULL;

	uart->uart_nr = uart_nr;
	uart->rx_overrun = false;

	switch(uart->uart_nr)
	{
	case UART0:
		uart->rx_enabled = (mode != UART_TX_ONLY);
		uart->tx_enabled = (mode != UART_RX_ONLY);
		if(uart->rx_enabled)
		{
			struct uart_rx_buffer_ * rx_buffer = (struct uart_rx_buffer_ *)malloc(sizeof(struct uart_rx_buffer_));
			if(rx_buffer == NULL)
			{
				free(uart);
				return NULL;
			}
			rx_buffer->size = rx_size;//var this
			rx_buffer->rpos = 0;
			rx_buffer->wpos = 0;
			rx_buffer->buffer = (uint8_t *)malloc(rx_buffer->size);
			if(rx_buffer->buffer == NULL)
			{
				free(rx_buffer);
				free(uart);
				return NULL;
			}
			uart->rx_buffer = rx_buffer;
		}
		break;

	case UART1:
		// Note: uart_interrupt_handler does not support RX on UART 1.
		uart->rx_enabled = false;
		uart->tx_enabled = (mode != UART_RX_ONLY);
		break;

	case UART_NO:
	default:
		// big fail!
		free(uart);
		return NULL;
	}

	uart_set_baudrate(uart, baudrate);

	UART[uart_nr] = uart;

	return uart;
}
Exemple #7
0
void dbg_console_create()
{
	_dbg_console = console_create(DBG_CONSOLE_UART, DBG_CONSOLE_TX_FIFO, DBG_CONSOLE_IRQ_PRIORITY);
	UART_BAUD baud;
	baud.data_bits = 8;
	baud.parity = 'N';
	baud.stop_bits = 1;
	baud.baud = DBG_CONSOLE_BAUD;
	uart_set_baudrate(DBG_CONSOLE_UART, &baud);

	_dbg_console_thread = thread_create_and_run("DBG console", DBG_CONSOLE_THREAD_STACK_SIZE, DBG_CONSOLE_THREAD_PRIORITY, dbg_console_thread, NULL);
}
Exemple #8
0
static inline void app_setup_dbg()
{
    BAUD baudrate;
    pin_enable(DBG_CONSOLE_TX_PIN, STM32_GPIO_MODE_OUTPUT_AF_PUSH_PULL_50MHZ, false);
    uart_open(DBG_CONSOLE, UART_MODE_STREAM | UART_TX_STREAM);
    baudrate.baud = DBG_CONSOLE_BAUD;
    baudrate.data_bits = 8;
    baudrate.parity = 'N';
    baudrate.stop_bits= 1;
    uart_set_baudrate(DBG_CONSOLE, &baudrate);
    uart_setup_printk(DBG_CONSOLE);
    uart_setup_stdout(DBG_CONSOLE);
    open_stdout();
}
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)
{
	enum uart_parity parity;
	uint8_t uart_stopbits;

	if (databits < 5 || databits > 8)
		return 0;

	switch (cdc_parity) {
	case USB_CDC_NO_PARITY:
		parity = UART_PARITY_NONE;
		break;
	case USB_CDC_ODD_PARITY:
		parity = UART_PARITY_ODD;
		break;
	case USB_CDC_EVEN_PARITY:
		parity = UART_PARITY_EVEN;
		break;
	default:
		return 0;
	}

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

	/* Disable the UART while we mess with its settings */
	uart_disable(UART1);
	/* Set communication parameters */
	uart_set_baudrate(UART1, baud);
	uart_set_databits(UART1, databits);
	uart_set_parity(UART1, parity);
	uart_set_stopbits(UART1, uart_stopbits);
	/* Back to work. */
	uart_enable(UART1);

	return 1;
}
Exemple #10
0
void
main_sh (void)
{
  led(0x40);

  uart_set_baudrate ();
  led(0x042);

  putstr ("CPU tests passed\n");
  led(0x043);
  putstr ("DDR Init\n");
  led(0x042);
  ddr_init ();

  putstr ("GDB Stub for HS-2J0 SH2 ROM\n");
  putstr (version_string);
  led(0x50);
}
Exemple #11
0
uint8_t USART_Init(struct USART_configuration config)
{
	// Add your code here. Don't forget that this function is supposed
	// to return an error code if something goes wrong!
	
	/* Create Buffers */
	rx_buf = rb_create(RX_BUFFLEN);
	tx_buf = rb_create(TX_BUFFLEN);

 	/* Enable UART receiver and transmitter */
  	uart_enable_rx();
  	uart_enable_tx();

  	/* Enable UART RX Complete Interrupt */
  	uart_enable_rx_complete_interrupt();

	/* set baudrate */
  	if (uart_set_baudrate(config.baudrate))
  		goto error;

 	/* Parity */
  	if (uart_set_parity(config.parity))
  		goto error;

 	/* Stop bit */
  	if (uart_set_stopbit(config.stopbits))
  		goto error;

 	/* Number of databits*/
  	if (uart_set_databits(config.databits))
  		goto error;

  	/* No errors in configuration */
  	return OK;

error:
	
	/* Reset; configuration to 8N1, 9600b */
 	uart_default_conf();
	return ERROR;
}
Exemple #12
0
void traceswo_init(void)
{
	periph_clock_enable(RCC_GPIOD);
	periph_clock_enable(TRACEUART_CLK);
	__asm__("nop"); __asm__("nop"); __asm__("nop");

	gpio_mode_setup(SWO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SWO_PIN);
	gpio_set_af(SWO_PORT, 1, SWO_PIN); /* U2RX */

	uart_disable(TRACEUART);

	/* Setup UART parameters. */
	uart_clock_from_sysclk(TRACEUART);
	uart_set_baudrate(TRACEUART, 800000);
	uart_set_databits(TRACEUART, 8);
	uart_set_stopbits(TRACEUART, 1);
	uart_set_parity(TRACEUART, UART_PARITY_NONE);

	// Enable FIFO
	uart_enable_fifo(TRACEUART);

	// Set FIFO interrupt trigger levels to 4/8 full for RX buffer and
	// 7/8 empty (1/8 full) for TX buffer
	uart_set_fifo_trigger_levels(TRACEUART, UART_FIFO_RX_TRIG_1_2, UART_FIFO_TX_TRIG_7_8);

	uart_clear_interrupt_flag(TRACEUART, UART_INT_RX | UART_INT_RT);

	/* Enable interrupts */
	uart_enable_interrupts(TRACEUART, UART_INT_RX | UART_INT_RT);

	/* Finally enable the USART. */
	uart_enable(TRACEUART);

	nvic_set_priority(TRACEUART_IRQ, 0);
	nvic_enable_irq(TRACEUART_IRQ);

	/* Un-stall USB endpoint */
	usbd_ep_stall_set(usbdev, 0x85, 0);

	gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3);
}
Exemple #13
0
int uart_ioctl(struct inode * inode, struct file * filp, unsigned int cmd, unsigned long arg)
{
	DPRINT(cmd);
	DPRINT(arg);

#define UART_SET_BUAD_RATE	0
#define UART_ENABLE_FIFO	1

	switch (cmd)
	{
		case UART_SET_BUAD_RATE:
			uart_set_baudrate(arg);
			break;

		case UART_ENABLE_FIFO:
			uart_enable_fifo();
			break;
	}

	return 0;
}
static void uart_setup(void)
{
	/* Enable GPIOA in run mode. */
	periph_clock_enable(RCC_GPIOA);
	/* Mux PA0 and PA1 to UART0 (alternate function 1) */
	gpio_set_af(GPIOA, 1, GPIO0 | GPIO1);

	/* Enable the UART clock */
	periph_clock_enable(RCC_UART0);
	/* We need a brief delay before we can access UART config registers */
	__asm__("nop");
	/* Disable the UART while we mess with its setings */
	uart_disable(UART0);
	/* Configure the UART clock source as precision internal oscillator */
	uart_clock_from_piosc(UART0);
	/* Set communication parameters */
	uart_set_baudrate(UART0, 921600);
	uart_set_databits(UART0, 8);
	uart_set_parity(UART0, UART_PARITY_NONE);
	uart_set_stopbits(UART0, 1);
	/* Now that we're done messing with the settings, enable the UART */
	uart_enable(UART0);
}
Exemple #15
0
void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud, bool_t hw_flow_control __attribute__ ((unused))) {
  uart_disable_interrupts(p);
  uart_set_baudrate(p, baud);
  uart_enable_interrupts(p);
}
Exemple #16
0
void traceswo_baud(unsigned int baud)
{
	uart_set_baudrate(TRACEUART, baud);
	uart_set_databits(TRACEUART, 8);
}
void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) {
  uart_disable_interrupts(p);
  uart_set_baudrate(p, baud);
  uart_enable_interrupts(p);
}
Exemple #18
0
static void cli_command_uart0(char *args)
{
	char *token;
	int value;

	cli_strip_spaces(&args);

	token = args;
	if(cli_strip_word(&args)) {
		uart_printf("1 Incorrect format, uart0 [speed [baudrate]] [parity [even|odd|none]] [bits [7|8]]\n");
		return;
	}

	if(strcmp(token, "speed") == 0) {
		++args;
		
		cli_strip_spaces(&args);		
	
		token = args;
		if(cli_strip_decimal_number(&args)) {
			uart_printf("2 Incorrect format, uart0 [speed [baudrate]] [parity [even|odd|none]] [bits [7|8]]\n");
			return;
		}
		value = atoi(token);

		uart_set_baudrate(value);

		++args;
		cli_strip_spaces(&args);

		token = args;
		cli_strip_word(&args);
	}
	if(strcmp(token, "parity") == 0) {
		++args;

		cli_strip_spaces(&args);

		token = args;
		if(cli_strip_word(&args)) {
			uart_printf("3 Incorrect format, uart0 [speed [baudrate]] [parity [even|odd|none]] [bits [7|8]]\n");
			return;
		}

		uart_set_parity(token);

		++args;
		cli_strip_spaces(&args);

		token = args;
		cli_strip_word(&args);
	}
	if(strcmp(token, "bits") == 0) {
		++args;

		cli_strip_spaces(&args);

		token = args;
		if(cli_strip_decimal_number(&args)) {
			uart_printf("4 Incorrect format, uart0 [speed [baudrate]] [parity [even|odd|none]] [bits [7|8]]\n");
			return;
		}

		uart_set_bits(token);
	}
}