aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/stm32f1/internal.h2
-rw-r--r--src/stm32f1/main.c17
-rw-r--r--src/stm32f1/usbserial.c11
3 files changed, 24 insertions, 6 deletions
diff --git a/src/stm32f1/internal.h b/src/stm32f1/internal.h
index be9ea4d0..73aa179b 100644
--- a/src/stm32f1/internal.h
+++ b/src/stm32f1/internal.h
@@ -8,4 +8,6 @@
extern GPIO_TypeDef *const digital_regs[];
extern uint32_t const digital_pins[];
+void udelay(uint32_t usecs);
+
#endif // internal.h
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)
diff --git a/src/stm32f1/usbserial.c b/src/stm32f1/usbserial.c
index 20e1da0d..641aacc0 100644
--- a/src/stm32f1/usbserial.c
+++ b/src/stm32f1/usbserial.c
@@ -5,13 +5,13 @@
// This file may be distributed under the terms of the GNU GPLv3 license.
#include <string.h> // NULL
+#include "board/gpio.h" // gpio_out_setup
#include "board/io.h" // writeb
#include "board/usb_cdc.h" // usb_notify_ep0
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
+#include "internal.h" // GPIO
#include "sched.h" // DECL_INIT
#include "stm32f1xx.h" // USB
-#include "stm32f1xx_ll_gpio.h" // LL_GPIO_SetOutputPin
-#include "stm32f1xx_ll_utils.h" // LL_mDelay
/****************************************************************
@@ -226,10 +226,9 @@ void
usb_init(void)
{
// Pull the D+ pin low briefly to signal a new connection
- LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_12);
- LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_OUTPUT);
- LL_mDelay(5);
- LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_FLOATING);
+ gpio_out_setup(GPIO('A', 12), 0);
+ udelay(5000);
+ gpio_in_setup(GPIO('A', 12), 0);
// Setup USB packet memory
btable_configure();