summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2021-09-27 11:09:17 +0200
committerxengineering <me@xengineering.eu>2021-09-27 11:26:12 +0200
commitcd9eaac6dacc0179815f16c9494b18633f1c6586 (patch)
tree1b890023aa956555764b2588408cf405ab9e083d
parent2b5ecc667ce57c50d831eaea6bad1be8a84bee0a (diff)
downloadledcontrol-cd9eaac6dacc0179815f16c9494b18633f1c6586.tar
ledcontrol-cd9eaac6dacc0179815f16c9494b18633f1c6586.tar.zst
ledcontrol-cd9eaac6dacc0179815f16c9494b18633f1c6586.zip
Calibrate Delays
-rw-r--r--src/main.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 74efae2..50d7fdc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,47 +1,52 @@
+// vim: shiftwidth=4 tabstop=4 noexpandtab
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
-#define DELAY 100000
+/*
+SYSCLK should be at 72.000.000 Hz
+--> 18.000.000 __asm__("nop") per second (one instruction --> 4 clock cycles)
+--> 18.000 __asm__("nop") per millisecond
+*/
+#define DELAY_MS 18000 // FIXME seems to be too slow by factor of 4
-void clock_init(void);
-void gpio_init(void);
-void delay(void);
+static void clock_init(void);
+static void gpio_init(void);
+static void delay(uint32_t delay);
-int main(void)
+void main(void)
{
clock_init();
gpio_init();
while(1){
gpio_toggle(GPIOC, GPIO13);
- delay();
+ delay(250 * DELAY_MS);
}
-
- return 0;
}
-void clock_init(void)
+static void clock_init(void)
{
+ rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);
rcc_periph_clock_enable(RCC_GPIOC); // for PC13 blinking
}
-void gpio_init(void)
+static 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)
+static void delay(uint32_t delay)
{
- for (int i = 0; i < DELAY; i++) {
+ for (uint32_t i = 0; i < delay; i++) {
__asm__("nop");
}
}