开发环境安装
1.点击mdk_xxx.exe,安装MDK软件;
2.点击Keil.STM32FXxx_DFP.x.x.x.pack,安装芯片支持包
仿真器连接
连线方式
主控板程序烧写接口如下图:
ST-Link-V2各引脚定义:
SWCLK--------------------------->SWCLK
SWDIO--------------------------->SWDIO
VCC --------------------------->VCC
GND --------------------------->GND
时钟配置
STM32F4时钟树
时钟初始化代码
/*+------------时钟初始化----------------+*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {
0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {
0};
//Configure the main internal regulator output voltage
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
//Initializes the CPU, AHB and APB bus clocks
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI; //晶振
RCC_OscInitStruct.HSIState = RCC_HSI_ON; //内部时钟,16MHz
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; //HSI校准值
RCC_OscInitStruct.LSIState = RCC_LSI_ON; //32kHz,IWDG、AWU使用
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; //主时钟,参考时钟树
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 168;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; //主时钟168MHz
RCC_OscInitStruct.PLL.PLLQ = 7; //外设时钟48MHz
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
//Initializes the CPU, AHB and APB bus clocks
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider =<