/*------------------------------------------------------- 功能 : 初始化 输入 : void 返回 : void Copyright : yitiandelan. ---------------------------------------------------------*/ void BSP_Init(void) { BSP_OSC_Init(); #if (configUSE_LED == 1) BSP_LED_Init(); #endif #if (configUSE_DAC == 1) BSP_DAC_Init(); #endif #if (configUSE_ADC123 == 1) BSP_ADC_Init(); #endif #if (configUSE_ExternADC == 1) BSP_ADC_ex_Init(); #endif #if (configUSE_LCD == 1) BSP_LCD_Init(); #endif #if (configUSE_CODEC == 1) BSP_CODEC_Init(); #endif #if (configUSE_PWM == 1) BSP_TIM3_Init(); #endif #if (configUSE_RTT == 1) BSP_RTT_Init(); #endif #if (configUSE_USB == 1) BSP_USB_Init(); #endif #if (configUSE_MPU == 1) BSP_MPU_Init(); #endif }
void BSP_Init(void) { BSP_RCC_Init(); BSP_UART_Init(); BSP_SW_Init(); BSP_ADC_Init(); BSP_LEDS_Init(); }
int main(void) { /* USER CODE BEGIN 1 */ trace_printf("Hello\n"); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ /* Initialize ADC */ BSP_ADC_Init(&hadc_bsp1,ADC_IN1,1,Indepenent_Mode); /* Modify ADC resolution in init structure */ hadc_bsp1.Init.Resolution = ADC_RESOLUTION8b; /* Initialize ADC again */ HAL_ADC_Init(&hadc_bsp1); /* Start ADC */ HAL_ADC_Start_IT(&hadc_bsp1); /* USER CODE END 2 */ /* 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 */ trace_printf("Hello\n"); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ /* Initialize ADC */ BSP_ADC_Init(&hadc_bsp2,ADC_IN2,1,Indepenent_Mode); /* Initialize LED */ BSP_LED_Init(LED5); /* Initialize ADC Watchdog */ BSP_ADC_Thr_Init(&hadc_bsp2,3412, 682); /* Start ADC */ HAL_ADC_Start_IT(&hadc_bsp2); /* USER CODE END 2 */ /* 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 */ trace_printf("Hello\n"); float Temperature; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ /* Initialize and start ADC */ BSP_ADC_Init(&hadc_bsp1,ADC_IN16,1,Temperature_Measure); HAL_ADC_Start(&hadc_bsp1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ Temperature = BSP_ADC_Get_Temperature(); // trace_printf("%3.6f",Temperature); HAL_Delay(200); } /* USER CODE END 3 */ }
void BSP_Init (void) { BSP_IntInit(); RCC_DeInit(); RCC_HSEConfig(RCC_HSE_ON); RCC_WaitForHSEStartUp(); RCC_HCLKConfig(RCC_SYSCLK_Div1); RCC_PCLK2Config(RCC_HCLK_Div1); RCC_PCLK1Config(RCC_HCLK_Div2); RCC_ADCCLKConfig(RCC_PCLK2_Div6); FLASH_SetLatency(FLASH_Latency_2); FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); RCC_PLLCmd(ENABLE); while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { ; } RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); while (RCC_GetSYSCLKSource() != 0x08) { ; } BSP_ADC_Init(); /* Initialize the I/Os for the ADC controls. */ BSP_LED_Init(); /* Initialize the I/Os for the LED controls. */ BSP_PB_Init(); /* Initialize the I/Os for the PB control. */ BSP_Joystick_Init(); /* Initialize the I/Os for the Joystick control. */ STM3210E_LCD_Init(); LCD_Clear(0xFFFF); }
void BSP_Init (void) { USART_InitTypeDef USART_InitStructure; /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; RCC_DeInit(); RCC_HSEConfig(RCC_HSE_ON); RCC_WaitForHSEStartUp(); RCC_HCLKConfig(RCC_SYSCLK_Div1); RCC_PCLK2Config(RCC_HCLK_Div1); RCC_PCLK1Config(RCC_HCLK_Div2); RCC_ADCCLKConfig(RCC_PCLK2_Div6); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); FLASH_SetLatency(FLASH_Latency_2); FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); RCC_PLLCmd(ENABLE); while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { ; } RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); while (RCC_GetSYSCLKSource() != 0x08) { ; } /* SCU_AHBPeriphClockConfig(__VIC,ENABLE); //VIC_DeInit(); VIC_Config(UART1_ITLine, VIC_IRQ, 15); VIC_ITCmd(UART1_ITLine, ENABLE); */ BSP_ADC_Init(); /* Initialize the I/Os for the ADC controls. */ BSP_LED_Init(); /* Initialize the I/Os for the LED controls. */ BSP_PB_Init(); /* Initialize the I/Os for the PB control. */ // BSP_Joystick_Init(); /* Initialize the I/Os for the Joystick control. */ GPIO_Configuration(); USART_Init(USART1,&USART_InitStructure); USART_Cmd(USART1, ENABLE); UART2_int(); }
void BSP_Init(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; __PWR_CLK_ENABLE() ; __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 7; HAL_RCC_OscConfig(&RCC_OscInitStruct); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); __GPIOB_CLK_ENABLE() ; GPIO_InitTypeDef GPIO_Init; GPIO_Init.Mode = GPIO_MODE_AF_PP; GPIO_Init.Pull = GPIO_NOPULL; GPIO_Init.Speed = GPIO_SPEED_FAST; GPIO_Init.Alternate = GPIO_AF2_TIM3; GPIO_Init.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4; HAL_GPIO_Init(LEDS_PORT, &GPIO_Init); __TIM3_CLK_ENABLE() ; TIM_MasterConfigTypeDef TIM_MasterConfig; TIM_OC_InitTypeDef TIM_OC_Init; TIM3_Handle.Instance = TIM3; TIM3_Handle.Init.Prescaler = 84 - 1; TIM3_Handle.Init.CounterMode = TIM_COUNTERMODE_UP; TIM3_Handle.Init.Period = 1500; TIM3_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2; HAL_TIM_PWM_Init(&TIM3_Handle); TIM_MasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; TIM_MasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&TIM3_Handle, &TIM_MasterConfig); TIM_OC_Init.OCMode = TIM_OCMODE_PWM2; TIM_OC_Init.Pulse = 0; TIM_OC_Init.OCPolarity = TIM_OCPOLARITY_HIGH; TIM_OC_Init.OCFastMode = TIM_OCFAST_ENABLE; HAL_TIM_PWM_ConfigChannel(&TIM3_Handle, &TIM_OC_Init, TIM_CHANNEL_1); HAL_TIM_PWM_ConfigChannel(&TIM3_Handle, &TIM_OC_Init, TIM_CHANNEL_3); HAL_TIM_PWM_ConfigChannel(&TIM3_Handle, &TIM_OC_Init, TIM_CHANNEL_4); HAL_TIM_PWM_Start(&TIM3_Handle, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&TIM3_Handle, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&TIM3_Handle, TIM_CHANNEL_4); BSP_ADC_Init(); }