summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2020-09-20 12:06:38 +0200
committerxengineering <mail2xengineering@protonmail.com>2020-09-20 12:06:38 +0200
commit5d54be33f95f6ba2a6984cf29898c619e5482db7 (patch)
tree099dd4ca9e0736578491cacf53467b1b3359a869
parent9b7d53550645d693afbb338258af6bcd7b7b2539 (diff)
downloadstm32f103c8-examples-5d54be33f95f6ba2a6984cf29898c619e5482db7.tar
stm32f103c8-examples-5d54be33f95f6ba2a6984cf29898c619e5482db7.tar.zst
stm32f103c8-examples-5d54be33f95f6ba2a6984cf29898c619e5482db7.zip
Implement gpio_blink
-rw-r--r--gpio_blink/Makefile33
-rw-r--r--gpio_blink/main.c47
2 files changed, 80 insertions, 0 deletions
diff --git a/gpio_blink/Makefile b/gpio_blink/Makefile
new file mode 100644
index 0000000..038b93b
--- /dev/null
+++ b/gpio_blink/Makefile
@@ -0,0 +1,33 @@
+PROJECT = gpio_blink
+BUILD_DIR = bin
+
+#SHARED_DIR = ../libraries
+CFILES = main.c
+#CFILES += api.c
+#AFILES += api-asm.S
+
+# TODO - you will need to edit these two lines!
+DEVICE=stm32f103c8
+#OOCD_FILE = board/stm32f4discovery.cfg
+
+# You shouldn't have to edit anything below here.
+VPATH += $(SHARED_DIR)
+INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR))
+OPENCM3_DIR=../libopencm3
+
+include $(OPENCM3_DIR)/mk/genlink-config.mk
+include ../rules.mk
+include $(OPENCM3_DIR)/mk/genlink-rules.mk
+
+
+# Black Magic Probe:
+
+GDB=/usr/bin/arm-none-eabi-gdb
+BMP_DEVICE=/dev/ttyACM0
+
+bmp: $(PROJECT).elf
+ $(GDB) $(PROJECT).elf \
+ -ex 'set confirm off' \
+ -ex 'target extended-remote $(BMP_DEVICE)' \
+ -ex 'monitor swdp_scan' \
+ -ex 'attach 1'
diff --git a/gpio_blink/main.c b/gpio_blink/main.c
new file mode 100644
index 0000000..7a5290f
--- /dev/null
+++ b/gpio_blink/main.c
@@ -0,0 +1,47 @@
+
+
+#include <libopencm3/stm32/rcc.h>
+#include <libopencm3/stm32/gpio.h>
+
+
+#define DELAY 1000000
+
+
+void clock_init(void);
+void gpio_init(void);
+void delay(void);
+
+
+int main(void)
+{
+ clock_init();
+ gpio_init();
+
+ while(1){
+ gpio_toggle(GPIOC, GPIO13);
+ delay();
+ }
+
+ return 0;
+}
+
+
+void clock_init(void)
+{
+ rcc_periph_clock_enable(RCC_GPIOC); // for PC13 blinking
+}
+
+
+void gpio_init(void)
+{
+ gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
+ gpio_set(GPIOC, GPIO13);
+}
+
+
+void delay(void)
+{
+ for (int i = 0; i < DELAY; i++) {
+ __asm__("nop");
+ }
+}