芯片是STM32L031G6U6,芯片没有外部晶振引脚,想要高精度时钟只能通过PA0输入外部时钟,选用有源晶振8MHz
按照CubeMX生产的初始化时钟函数后发现启动不了,必须用HSI才行,仿真发现卡死在ADC校准函数 HAL_ADCEx_Calibration_Start(&stm32_adc_obj[i].ADC_Handler,ADC_SINGLE_ENDED); 这里
问题原因:此芯片的ADC时钟只能用HSI,初始化外部时钟时没有打开HSI
初始化代码增加使能HSI即可
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; RCC_OscInitStruct.HSIState = RCC_HSI_ON;//stm32L031芯片的adc必须启动HSI RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { Error_Handler(); } }
标签:STM32L031,ClkInitStruct,HSI,OscInitStruct,HAL,卡死,时钟,RCC From: https://www.cnblogs.com/arthurly/p/18365260