Skip to content
Closed
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: 2 additions & 3 deletions ports/stm/boards/cygnet/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ void board_init(void) {
// enable the debugger while sleeping. Todo move somewhere more central (kind of generally useful in a debug build)
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);

// Set tick interrupt priority, default HAL value is intentionally invalid
// Without this, USB does not function.
HAL_InitTick((1UL << __NVIC_PRIO_BITS) - 1UL);
// Set tick interrupt priority lower than USB to ensure proper operation
HAL_InitTick(2);

__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
Expand Down
17 changes: 17 additions & 0 deletions ports/stm/peripherals/stm32l4/clocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ void stm32_peripherals_clocks_init(void) {

HAL_CHECK(HAL_RCC_OscConfig(&RCC_OscInitStruct));

#ifdef STM32L433xx
/* Enable CRS clock */
__HAL_RCC_CRS_CLK_ENABLE();

/* Configure CRS */
RCC_CRSInitTypeDef RCC_CRSInitStruct = {0};
RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000);
RCC_CRSInitStruct.ErrorLimitValue = 34;
RCC_CRSInitStruct.HSI48CalibrationValue = 32;

/* Start automatic synchronization */
HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
#endif

#ifdef STM32L4R5xx
/* Enable MSI Auto-calibration through LSE */
HAL_RCCEx_EnableMSIPLLMode();
Expand Down
5 changes: 5 additions & 0 deletions ports/stm/supervisor/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ static void init_usb_vbus_sense(void) {
}

void init_usb_hardware(void) {
#ifdef STM32L433xx
/* Set USB interrupt priority */
HAL_NVIC_SetPriority(USB_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(USB_IRQn);
#endif

/* Enable USB power on Pwrctrl CR2 register */
#ifdef PWR_CR2_USV
Expand Down
Loading