From 321163da1a3a2bf90b4a50ebb926acba55b50929 Mon Sep 17 00:00:00 2001 From: Matthew McGowan Date: Wed, 25 May 2022 14:22:19 -0700 Subject: [PATCH] feat(swan_r5): blink the LED on startup. set VUSB_SELECT and DISCHARGE to floating to avoid any potential issues with them being outputs. --- ports/stm/boards/swan_r5/board.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ports/stm/boards/swan_r5/board.c b/ports/stm/boards/swan_r5/board.c index 5ad6d464bf..36f3946236 100644 --- a/ports/stm/boards/swan_r5/board.c +++ b/ports/stm/boards/swan_r5/board.c @@ -33,14 +33,19 @@ void initialize_discharge_pin(void) { /* Initialize the 3V3 discharge to be OFF and the output power to be ON */ __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + /* Set the DISCHARGE pin and the USB_DETECT pin to FLOAT */ + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; GPIO_InitStruct.Pin = GPIO_PIN_6; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6, GPIO_PIN_SET); + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); /* PE6 DISCHRG */ + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* PC6 is USB_DETECT */ + + /* Turn on the 3V3 regulator */ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; GPIO_InitStruct.Pin = GPIO_PIN_4; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET); @@ -53,6 +58,19 @@ void board_init(void) { // Set tick interrupt priority, default HAL value is intentionally invalid // Without this, USB does not function. HAL_InitTick((1UL << __NVIC_PRIO_BITS) - 1UL); + + initialize_discharge_pin(); + + __HAL_RCC_GPIOE_CLK_ENABLE(); + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + GPIO_InitStruct.Pin = GPIO_PIN_2; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET); + HAL_Delay(50); + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET); } bool board_requests_safe_mode(void) { @@ -60,7 +78,6 @@ bool board_requests_safe_mode(void) { } void reset_board(void) { - initialize_discharge_pin(); } void board_deinit(void) {