/** * \brief Multiplex group of pins to the given alternate function * * Mux the pin or group of pins to the given alternate function. Note that a * number of pins may be set but only with a single AF number. This is useful * when one or more of a peripheral's pins are assigned to the same alternate * function. * * Because AF0 is not used on the LM4F, passing 0 as the alt_func_num parameter * will disable the alternate function of the given pins. * * @param[in] gpioport GPIO block register address base @ref gpio_reg_base * @param[in] alt_func_num Pin alternate function number or 0 to disable the * alternate function multiplexing. * @param[in] gpios @ref gpio_pin_id. Any combination of pins may be specified * by OR'ing then together */ void gpio_set_af(uint32_t gpioport, uint8_t alt_func_num, uint8_t gpios) { uint32_t pctl32; uint8_t pin_mask; int i; /* Did we mean to disable the alternate function? */ if (alt_func_num == 0) { GPIO_AFSEL(gpioport) &= ~gpios; return; } /* Enable the alternate function */ GPIO_AFSEL(gpioport) |= gpios; /* Alternate functions are digital */ GPIO_DEN(gpioport) |= gpios; /* Now take care of the actual multiplexing */ pctl32 = GPIO_PCTL(gpioport); for (i = 0; i < 8; i++) { pin_mask = (1 << i); if (!(gpios & pin_mask)) { continue; } pctl32 &= ~PCTL_MASK(i); pctl32 |= PCTL_AF(i, (alt_func_num & 0xf)); } GPIO_PCTL(gpioport) = pctl32; }
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); }