aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32f1/main.c
diff options
context:
space:
mode:
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)