71 lines
1.8 KiB
C
71 lines
1.8 KiB
C
#include "libopencm3/cm3/vector.h"
|
|
#include "system.h"
|
|
#include "timer.h"
|
|
#include "uart.h"
|
|
#include <libopencm3/cm3/nvic.h>
|
|
#include <libopencm3/cm3/systick.h>
|
|
#include <libopencm3/stm32/flash.h>
|
|
#include <libopencm3/stm32/gpio.h>
|
|
#include <libopencm3/stm32/rcc.h>
|
|
#include <libopencm3/stm32/usart.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
static void gpio_setup(void) {
|
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
|
|
gpio_set(GPIOC, GPIO12);
|
|
|
|
/* Setup GPIO6 and 7 (in GPIO port A) for LED use. */
|
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
|
|
|
|
/*
|
|
* Set TIM1 channel output pins to
|
|
* 'output alternate function push-pull'.
|
|
*/
|
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM2_CH1_ETR);
|
|
}
|
|
|
|
static void clock_setup(void) {
|
|
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);
|
|
|
|
/* Enable GPIOA clock (for LED GPIOs). */
|
|
rcc_periph_clock_enable(RCC_GPIOC);
|
|
|
|
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
|
rcc_periph_clock_enable(RCC_GPIOA);
|
|
rcc_periph_clock_enable(RCC_AFIO);
|
|
rcc_periph_clock_enable(RCC_USART1);
|
|
|
|
rcc_periph_clock_enable(RCC_GPIOC);
|
|
}
|
|
|
|
int main(void) {
|
|
clock_setup();
|
|
gpio_setup();
|
|
sys_tick_setup();
|
|
usart_setup();
|
|
timer_setup();
|
|
|
|
printf("Printf is working!\n");
|
|
|
|
gpio_clear(GPIOC, GPIO13);
|
|
gpio_set(GPIOC, GPIO13);
|
|
|
|
timer_pwm_set_duty(75.0);
|
|
|
|
uint64_t init = sys_ticks_get();
|
|
while (sys_ticks_get() == init);
|
|
|
|
uint64_t ref = 0;
|
|
for (int i = 0; i < 20;) {
|
|
if (sys_ticks_get() > ref) {
|
|
ref += 500;
|
|
i++;
|
|
gpio_toggle(GPIOC, GPIO13);
|
|
}
|
|
}
|
|
|
|
while (1);
|
|
|
|
return 0;
|
|
}
|