|
|
|
#include <libopencm3/stm32/gpio.h>
|
|
|
|
|
|
|
|
#include <gpio.h>
|
|
|
|
|
|
|
|
int gpio_init(void)
|
|
|
|
{
|
|
|
|
/* Set up GPIOs for SPI 1 */
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO_SPI1_NSS);
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_SPI1_SCK |
|
|
|
|
GPIO_SPI1_MOSI);
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
|
|
|
|
GPIO_SPI1_MISO);
|
|
|
|
|
|
|
|
/* Set up GPIOs for user console (USART 1) */
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
|
|
|
GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX);
|
|
|
|
|
|
|
|
/* Set up GPIOs for admin console (USART 2) */
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
|
|
|
GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX);
|
|
|
|
|
|
|
|
/* Set up GPIOs for reset. */
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN,
|
|
|
|
GPIO1);
|
|
|
|
|
|
|
|
/* Set up GPIOs for timers. */
|
|
|
|
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON,
|
|
|
|
AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1);
|
|
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
|
|
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM2_PR1_CH1_ETR);
|
|
|
|
|
|
|
|
/* Set up GPIO for LED. */
|
|
|
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO0);
|
|
|
|
gpio_clear(GPIOB, GPIO0);
|
|
|
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
|
|
|
|
gpio_set(GPIOC, GPIO10);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_cleanup(void)
|
|
|
|
{
|
|
|
|
}
|