]> mj.ucw.cz Git - home-hw.git/commitdiff
Protab: Blink with systick
authorMartin Mares <mj@ucw.cz>
Tue, 30 Jul 2019 20:34:19 +0000 (22:34 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 30 Jul 2019 20:34:19 +0000 (22:34 +0200)
protab/blink2/Makefile [new file with mode: 0644]
protab/blink2/blink.c [new file with mode: 0644]

diff --git a/protab/blink2/Makefile b/protab/blink2/Makefile
new file mode 100644 (file)
index 0000000..17a67e8
--- /dev/null
@@ -0,0 +1,6 @@
+ROOT=../..
+BINARY=blink
+OBJS=blink.o
+LIB_OBJS=
+
+include $(ROOT)/mk/bluepill.mk
diff --git a/protab/blink2/blink.c b/protab/blink2/blink.c
new file mode 100644 (file)
index 0000000..605e113
--- /dev/null
@@ -0,0 +1,33 @@
+#include <libopencm3/cm3/systick.h>
+#include <libopencm3/stm32/rcc.h>
+#include <libopencm3/stm32/gpio.h>
+
+static void delay_ms(unsigned int ms)
+{
+       systick_clear();
+       for (unsigned int i=0; i<ms; i++)
+               while (!systick_get_countflag())
+                       ;
+}
+
+int main(void)
+{
+       rcc_clock_setup_in_hse_8mhz_out_72mhz();
+       rcc_periph_clock_enable(RCC_GPIOC);
+
+       // PC13 = BluePill LED
+       gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
+
+       systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
+       systick_set_reload(71999);
+       systick_counter_enable();
+
+       for (;;) {
+               gpio_clear(GPIOC, GPIO13);
+               delay_ms(100);
+               gpio_set(GPIOC, GPIO13);
+               delay_ms(500);
+       }
+
+       return 0;
+}