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

usbpd_stm32g4: Configure UCPD before disabling the dead battery mode #21430

Merged
merged 1 commit into from
Jul 2, 2023
Merged
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
7 changes: 5 additions & 2 deletions platforms/chibios/drivers/usbpd_stm32g4.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

// Initialises the USBPD subsystem
__attribute__((weak)) void usbpd_init(void) {
// Disable dead-battery signals
PWR->CR3 |= PWR_CR3_UCPD_DBDIS;
// Enable the clock for the UCPD1 peripheral
RCC->APB1ENR2 |= RCC_APB1ENR2_UCPD1EN;

Expand All @@ -46,6 +44,11 @@ __attribute__((weak)) void usbpd_init(void) {
CR |= UCPD_CR_ANAMODE | UCPD_CR_CCENABLE_Msk;
// Apply the changes
UCPD1->CR = CR;

// Disable dead-battery signals only after UCPD1 is configured to ensure
// that the transition does not go through any intermediate state without
// any pull-down resistance.
PWR->CR3 |= PWR_CR3_UCPD_DBDIS;
}

// Gets the current state of the USBPD allowance
Expand Down