Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable DCDC and Si86xx isolators on USB suspend #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ static inline enum gs_can_termination_state get_term(unsigned int channel)
(void)channel;
return GS_CAN_TERMINATION_UNSUPPORTED;
}

#endif

void gpio_suspend(void);

void gpio_resume(void);
25 changes: 23 additions & 2 deletions src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,24 @@ void gpio_init(void)
HAL_GPIO_Init(nCANSTBY_Port, &GPIO_InitStruct); //xceiver standby.
#endif

#if defined(BOARD_cannette)
#ifdef DCDCEN_Pin
HAL_GPIO_WritePin(DCDCEN_Port, DCDCEN_Pin, GPIO_PIN_SET);
GPIO_InitStruct.Pin = DCDCEN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(DCDCEN_Port, &GPIO_InitStruct); //start DCDC (TODO : wait until enumerated)
#endif

#ifdef nSI86EN_Pin
HAL_GPIO_WritePin(nSI86EN_Port, nSI86EN_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = nSI86EN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(nSI86EN_Port, &GPIO_InitStruct); //enable si86
#endif // BOARD_cannette
#endif


#if defined(BOARD_STM32F4_DevBoard)
// initialize USB pins
Expand All @@ -158,3 +161,21 @@ void gpio_init(void)

gpio_init_term();
}

void gpio_suspend(void) {
#ifdef nSI86EN_Pin
HAL_GPIO_WritePin(nSI86EN_Port, nSI86EN_Pin, GPIO_PIN_SET);
#endif
#ifdef DCDCEN_Pin
HAL_GPIO_WritePin(DCDCEN_Port, DCDCEN_Pin, GPIO_PIN_RESET);
#endif
}

void gpio_resume(void) {
#ifdef DCDCEN_Pin
HAL_GPIO_WritePin(DCDCEN_Port, DCDCEN_Pin, GPIO_PIN_SET);
#endif
#ifdef nSI86EN_Pin
HAL_GPIO_WritePin(nSI86EN_Port, nSI86EN_Pin, GPIO_PIN_RESET);
#endif
}
2 changes: 2 additions & 0 deletions src/usbd_gs_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,14 @@ void USBD_GS_CAN_SuspendCallback(USBD_HandleTypeDef *pdev)
if (hcan != NULL && hcan->leds != NULL)
led_set_mode(hcan->leds, led_mode_off);

gpio_suspend();
is_usb_suspend_cb = true;
}

void USBD_GS_CAN_ResumeCallback(USBD_HandleTypeDef *pdev)
{
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*) pdev->pClassData;
hcan->TxState = 0;
gpio_resume();
is_usb_suspend_cb = false;
}