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>
This commit is contained in:
parent
1096075d9b
commit
eb8db46ca3
|
@ -8,4 +8,6 @@
|
||||||
extern GPIO_TypeDef *const digital_regs[];
|
extern GPIO_TypeDef *const digital_regs[];
|
||||||
extern uint32_t const digital_pins[];
|
extern uint32_t const digital_pins[];
|
||||||
|
|
||||||
|
void udelay(uint32_t usecs);
|
||||||
|
|
||||||
#endif // internal.h
|
#endif // internal.h
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "autoconf.h"
|
#include "autoconf.h"
|
||||||
|
#include "board/internal.h" // udelay
|
||||||
|
#include "board/misc.h" // timer_read_time
|
||||||
#include "command.h" // DECL_CONSTANT
|
#include "command.h" // DECL_CONSTANT
|
||||||
#include "stm32f1xx.h"
|
#include "stm32f1xx.h"
|
||||||
#include "stm32f1xx_ll_system.h"
|
#include "stm32f1xx_ll_system.h"
|
||||||
|
@ -19,6 +21,7 @@
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, "stm32f103");
|
DECL_CONSTANT(MCU, "stm32f103");
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* dynamic memory pool
|
* dynamic memory pool
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
@ -128,6 +131,20 @@ void io_config(void)
|
||||||
LL_DBGMCU_SetTracePinAssignment(LL_DBGMCU_TRACE_NONE);
|
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
|
// Main entry point
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include <string.h> // NULL
|
#include <string.h> // NULL
|
||||||
|
#include "board/gpio.h" // gpio_out_setup
|
||||||
#include "board/io.h" // writeb
|
#include "board/io.h" // writeb
|
||||||
#include "board/usb_cdc.h" // usb_notify_ep0
|
#include "board/usb_cdc.h" // usb_notify_ep0
|
||||||
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
|
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
|
||||||
|
#include "internal.h" // GPIO
|
||||||
#include "sched.h" // DECL_INIT
|
#include "sched.h" // DECL_INIT
|
||||||
#include "stm32f1xx.h" // USB
|
#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)
|
usb_init(void)
|
||||||
{
|
{
|
||||||
// Pull the D+ pin low briefly to signal a new connection
|
// Pull the D+ pin low briefly to signal a new connection
|
||||||
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_12);
|
gpio_out_setup(GPIO('A', 12), 0);
|
||||||
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_OUTPUT);
|
udelay(5000);
|
||||||
LL_mDelay(5);
|
gpio_in_setup(GPIO('A', 12), 0);
|
||||||
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_FLOATING);
|
|
||||||
|
|
||||||
// Setup USB packet memory
|
// Setup USB packet memory
|
||||||
btable_configure();
|
btable_configure();
|
||||||
|
|
Loading…
Reference in New Issue