Skip to content

Commit 321163d

Browse files
committed
feat(swan_r5): blink the LED on startup. set VUSB_SELECT and DISCHARGE to floating to avoid any potential issues with them being outputs.
1 parent 65a5ad0 commit 321163d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

ports/stm/boards/swan_r5/board.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@
3333
void initialize_discharge_pin(void) {
3434
/* Initialize the 3V3 discharge to be OFF and the output power to be ON */
3535
__HAL_RCC_GPIOE_CLK_ENABLE();
36+
__HAL_RCC_GPIOC_CLK_ENABLE();
37+
3638
GPIO_InitTypeDef GPIO_InitStruct;
37-
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
39+
/* Set the DISCHARGE pin and the USB_DETECT pin to FLOAT */
40+
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
3841
GPIO_InitStruct.Pull = GPIO_NOPULL;
39-
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
4042
GPIO_InitStruct.Pin = GPIO_PIN_6;
41-
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
42-
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6, GPIO_PIN_SET);
43+
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); /* PE6 DISCHRG */
44+
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* PC6 is USB_DETECT */
45+
46+
/* Turn on the 3V3 regulator */
4347
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
48+
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
4449
GPIO_InitStruct.Pin = GPIO_PIN_4;
4550
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
4651
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET);
@@ -53,14 +58,26 @@ void board_init(void) {
5358
// Set tick interrupt priority, default HAL value is intentionally invalid
5459
// Without this, USB does not function.
5560
HAL_InitTick((1UL << __NVIC_PRIO_BITS) - 1UL);
61+
62+
initialize_discharge_pin();
63+
64+
__HAL_RCC_GPIOE_CLK_ENABLE();
65+
GPIO_InitTypeDef GPIO_InitStruct;
66+
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
67+
GPIO_InitStruct.Pull = GPIO_NOPULL;
68+
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
69+
GPIO_InitStruct.Pin = GPIO_PIN_2;
70+
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
71+
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET);
72+
HAL_Delay(50);
73+
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET);
5674
}
5775

5876
bool board_requests_safe_mode(void) {
5977
return false;
6078
}
6179

6280
void reset_board(void) {
63-
initialize_discharge_pin();
6481
}
6582

6683
void board_deinit(void) {

0 commit comments

Comments
 (0)