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); }
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); }