aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32f1/main.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-02-01 10:14:56 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-02-06 22:03:09 -0500
commiteb8db46ca3dc23286da5cf5e1c23af2456080172 (patch)
treea594111424e8a51ed3b5082254282cfb35524aef /src/stm32f1/main.c
parent1096075d9b2d10302abd42cfdeef155f145f64e1 (diff)
downloadkutter-eb8db46ca3dc23286da5cf5e1c23af2456080172.tar.gz
kutter-eb8db46ca3dc23286da5cf5e1c23af2456080172.tar.xz
kutter-eb8db46ca3dc23286da5cf5e1c23af2456080172.zip
stm32f1: Use internal functions for early USB gpio toggle
Avoid using the "low-level" library timing utilities. This is in preparation for using SysTick as part of the timer implementation. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stm32f1/main.c')
-rw-r--r--src/stm32f1/main.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/stm32f1/main.c b/src/stm32f1/main.c
index e7a0cd91..3abb03a3 100644
--- a/src/stm32f1/main.c
+++ b/src/stm32f1/main.c
@@ -5,6 +5,8 @@
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "autoconf.h"
+#include "board/internal.h" // udelay
+#include "board/misc.h" // timer_read_time
#include "command.h" // DECL_CONSTANT
#include "stm32f1xx.h"
#include "stm32f1xx_ll_system.h"
@@ -19,6 +21,7 @@
DECL_CONSTANT(MCU, "stm32f103");
+
/****************************************************************
* dynamic memory pool
****************************************************************/
@@ -128,6 +131,20 @@ void io_config(void)
LL_DBGMCU_SetTracePinAssignment(LL_DBGMCU_TRACE_NONE);
}
+// Implement simple early-boot delay mechanism
+void
+udelay(uint32_t usecs)
+{
+ if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) {
+ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
+ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
+ }
+
+ uint32_t end = timer_read_time() + timer_from_us(usecs);
+ while (timer_is_before(timer_read_time(), end))
+ ;
+}
+
// Main entry point
int
main(void)