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) {