diff options
Diffstat (limited to 'firmware/targets/f6/cube/Src/main.c')
-rw-r--r-- | firmware/targets/f6/cube/Src/main.c | 349 |
1 files changed, 167 insertions, 182 deletions
diff --git a/firmware/targets/f6/cube/Src/main.c b/firmware/targets/f6/cube/Src/main.c index 8e65442d..d4ec7ec2 100644 --- a/firmware/targets/f6/cube/Src/main.c +++ b/firmware/targets/f6/cube/Src/main.c @@ -76,179 +76,167 @@ void MX_FREERTOS_Init(void); * @brief The application entry point. * @retval int */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_ADC1_Init(); - MX_I2C1_Init(); - MX_RTC_Init(); - MX_SPI1_Init(); - MX_SPI2_Init(); - MX_USB_Device_Init(); - MX_TIM1_Init(); - MX_TIM2_Init(); - MX_TIM16_Init(); - MX_COMP1_Init(); - MX_RF_Init(); - MX_PKA_Init(); - MX_RNG_Init(); - MX_AES1_Init(); - MX_AES2_Init(); - MX_CRC_Init(); - MX_USART1_UART_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - - /* Init scheduler */ - osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */ - MX_FREERTOS_Init(); - /* Start scheduler */ - osKernelStart(); - - /* We should never get here as control is now taken by the scheduler */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - } - /* USER CODE END 3 */ +int main(void) { + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_ADC1_Init(); + MX_I2C1_Init(); + MX_RTC_Init(); + MX_SPI1_Init(); + MX_SPI2_Init(); + MX_USB_Device_Init(); + MX_TIM1_Init(); + MX_TIM2_Init(); + MX_TIM16_Init(); + MX_COMP1_Init(); + MX_RF_Init(); + MX_PKA_Init(); + MX_RNG_Init(); + MX_AES1_Init(); + MX_AES2_Init(); + MX_CRC_Init(); + MX_USART1_UART_Init(); + /* USER CODE BEGIN 2 */ + + /* USER CODE END 2 */ + + /* Init scheduler */ + osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */ + MX_FREERTOS_Init(); + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while(1) { + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) - { - } - - /* HSE configuration and activation */ - LL_RCC_HSE_Enable(); - while(LL_RCC_HSE_IsReady() != 1) - { - } - - /* HSI configuration and activation */ - LL_RCC_HSI_Enable(); - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_PWR_EnableBkUpAccess(); - if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) - { - LL_RCC_ForceBackupDomainReset(); - LL_RCC_ReleaseBackupDomainReset(); - } - LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_MEDIUMLOW); - LL_RCC_LSE_Enable(); - - /* Wait till LSE is ready */ - while(LL_RCC_LSE_IsReady() != 1) - { - } - - LL_RCC_HSE_EnableCSS(); - LL_RCC_LSE_EnableCSS(); - /* Main PLL configuration and activation */ - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 8, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_Enable(); - LL_RCC_PLL_EnableDomain_SYS(); - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_PLLSAI1_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1Q_DIV_2); - LL_RCC_PLLSAI1_ConfigDomain_ADC(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1R_DIV_2); - LL_RCC_PLLSAI1_Enable(); - LL_RCC_PLLSAI1_EnableDomain_48M(); - LL_RCC_PLLSAI1_EnableDomain_ADC(); - - /* Wait till PLLSAI1 is ready */ - while(LL_RCC_PLLSAI1_IsReady() != 1) - { - } - - /* Sysclk activation on the main PLL */ - /* Set CPU1 prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - - /* Set CPU2 prescaler*/ - LL_C2_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Set AHB SHARED prescaler*/ - LL_RCC_SetAHB4Prescaler(LL_RCC_SYSCLK_DIV_1); - - /* Set APB1 prescaler*/ - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - - /* Set APB2 prescaler*/ - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - - /* Disable MSI */ - LL_RCC_MSI_Disable(); - while(LL_RCC_MSI_IsReady() != 0) - { - } - - /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ - LL_SetSystemCoreClock(64000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } - if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) - { - LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); - } - LL_RCC_EnableRTC(); - LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); - LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_PLLSAI1); - LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); - LL_RCC_SetRNGClockSource(LL_RCC_RNG_CLKSOURCE_CLK48); - LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLLSAI1); - LL_RCC_SetCLK48ClockSource(LL_RCC_CLK48_CLKSOURCE_PLLSAI1); - LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE); - LL_RCC_SetSMPSPrescaler(LL_RCC_SMPS_DIV_1); - LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_LSE); - /* USER CODE BEGIN Smps */ - - /* USER CODE END Smps */ +void SystemClock_Config(void) { + LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) { + } + + /* HSE configuration and activation */ + LL_RCC_HSE_Enable(); + while(LL_RCC_HSE_IsReady() != 1) { + } + + /* HSI configuration and activation */ + LL_RCC_HSI_Enable(); + while(LL_RCC_HSI_IsReady() != 1) { + } + + LL_PWR_EnableBkUpAccess(); + if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) { + LL_RCC_ForceBackupDomainReset(); + LL_RCC_ReleaseBackupDomainReset(); + } + LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_MEDIUMLOW); + LL_RCC_LSE_Enable(); + + /* Wait till LSE is ready */ + while(LL_RCC_LSE_IsReady() != 1) { + } + + LL_RCC_HSE_EnableCSS(); + LL_RCC_LSE_EnableCSS(); + /* Main PLL configuration and activation */ + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 8, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_Enable(); + LL_RCC_PLL_EnableDomain_SYS(); + while(LL_RCC_PLL_IsReady() != 1) { + } + + LL_RCC_PLLSAI1_ConfigDomain_48M( + LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1Q_DIV_2); + LL_RCC_PLLSAI1_ConfigDomain_ADC( + LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1R_DIV_2); + LL_RCC_PLLSAI1_Enable(); + LL_RCC_PLLSAI1_EnableDomain_48M(); + LL_RCC_PLLSAI1_EnableDomain_ADC(); + + /* Wait till PLLSAI1 is ready */ + while(LL_RCC_PLLSAI1_IsReady() != 1) { + } + + /* Sysclk activation on the main PLL */ + /* Set CPU1 prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + + /* Set CPU2 prescaler*/ + LL_C2_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { + } + + /* Set AHB SHARED prescaler*/ + LL_RCC_SetAHB4Prescaler(LL_RCC_SYSCLK_DIV_1); + + /* Set APB1 prescaler*/ + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + + /* Set APB2 prescaler*/ + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + + /* Disable MSI */ + LL_RCC_MSI_Disable(); + while(LL_RCC_MSI_IsReady() != 0) { + } + + /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ + LL_SetSystemCoreClock(64000000); + + /* Update the time base */ + if(HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } + if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) { + LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); + } + LL_RCC_EnableRTC(); + LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); + LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_PLLSAI1); + LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); + LL_RCC_SetRNGClockSource(LL_RCC_RNG_CLKSOURCE_CLK48); + LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLLSAI1); + LL_RCC_SetCLK48ClockSource(LL_RCC_CLK48_CLKSOURCE_PLLSAI1); + LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE); + LL_RCC_SetSMPSPrescaler(LL_RCC_SMPS_DIV_1); + LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_LSE); + /* USER CODE BEGIN Smps */ + + /* USER CODE END Smps */ } /* USER CODE BEGIN 4 */ @@ -259,18 +247,16 @@ void SystemClock_Config(void) * @brief This function is executed in case of error occurrence. * @retval None */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - __disable_irq(); - while (1) - { - } - /* USER CODE END Error_Handler_Debug */ +void Error_Handler(void) { + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while(1) { + } + /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. @@ -278,12 +264,11 @@ void Error_Handler(void) * @param line: assert_param error line source number * @retval None */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, +void assert_failed(uint8_t* file, uint32_t line) { + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ |