Set CRS polarity; don't force software sync event on startup

This commit is contained in:
Ethan Zonca 2019-04-05 09:16:25 -04:00
parent f6a60edd48
commit 0bc8ec5b42
1 changed files with 7 additions and 10 deletions

View File

@ -66,33 +66,30 @@ void system_init(void)
#ifdef INTERNAL_OSCILLATOR
// Enable clock recovery system for internal oscillator
RCC_CRSInitTypeDef RCC_CRSInitStruct;
// Enable CRS Clock
__HAL_RCC_CRS_CLK_ENABLE();
// Default Synchro Signal division factor (not divided)
RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
// Set the SYNCSRC[1:0] bits according to CRS_Source value
RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
// Rising polarity
RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
// HSI48 is synchronized with USB SOF at 1KHz rate
RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000);
RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT;
// Set the TRIM[5:0] to the default value
RCC_CRSInitStruct.HSI48CalibrationValue = 0x20;
RCC_CRSInitStruct.HSI48CalibrationValue = 32;
// Start automatic synchronization
HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
// Force sync event
HAL_RCCEx_CRSSoftwareSynchronizationGenerate();
// Wait until synchronized
HAL_RCCEx_CRSWaitSynchronization(3000);
#endif
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);