From bef47ab1bc11c069a63c8ef7f221f7dc8266a7c5 Mon Sep 17 00:00:00 2001 From: fenugrec Date: Wed, 23 Nov 2022 16:17:37 -0500 Subject: [PATCH 1/2] gpio : make DCDC_EN and nSI86EN pins generic other boards may eventually have similar functions. --- src/gpio.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gpio.c b/src/gpio.c index 4bf5aa4e..2474b71f 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -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 From 94ab1f700bdf34cd9bdccf7924335721cc99566d Mon Sep 17 00:00:00 2001 From: fenugrec Date: Wed, 23 Nov 2022 16:37:28 -0500 Subject: [PATCH 2/2] gpio : add _suspend() and _resume() funcs To comply with USB current consumption in Suspended state, it could be necessary to power-down external parts of the circuit. This adds the relevant functions to control CAN transceivers and DCDC converters. --- include/gpio.h | 5 ++++- src/gpio.c | 18 ++++++++++++++++++ src/usbd_gs_can.c | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/gpio.h b/include/gpio.h index 9cd764c2..9fefd6e1 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -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); diff --git a/src/gpio.c b/src/gpio.c index 2474b71f..de6feff2 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -161,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 +} diff --git a/src/usbd_gs_can.c b/src/usbd_gs_can.c index 5e4db3c5..8a426183 100644 --- a/src/usbd_gs_can.c +++ b/src/usbd_gs_can.c @@ -735,6 +735,7 @@ 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; } @@ -742,5 +743,6 @@ 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; }