这篇教程C++ HAL_Init函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中HAL_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_Init函数的具体用法?C++ HAL_Init怎么用?C++ HAL_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了HAL_Init函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mainint main(void){ HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); HAL_GPIO_WritePin(Led_gpio,Led_pin,GPIO_PIN_SET); HAL_Delay(1000); HAL_GPIO_WritePin(Led_gpio,Led_pin,GPIO_PIN_RESET); /* This is the buffer where we will store our message. */ uint8_t buffer[12]={0}; size_t message_length; bool status; /* Encode our message */ { /* Allocate space on the stack to store the message data. * * Nanopb generates simple struct definitions for all the messages. * - check out the contents of simple.pb.h! * It is a good idea to always initialize your structures * so that you do not have garbage data from RAM in there. */ SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that will write to our buffer. */ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); /* Fill in the lucky number */ message.lucky_number = 13; /* Now we are ready to encode the message! */ status = pb_encode(&stream, SimpleMessage_fields, &message); message_length = stream.bytes_written; /* Then just check for any errors.. */ if (!status) { //printf("Encoding failed: %s/n", PB_GET_ERROR(&stream)); return 1; } } /* Now we could transmit the message over network, store it in a file or * wrap it to a pigeon's leg. */ /* But because we are lazy, we will just decode it immediately. */ { /* Allocate space for the decoded message. */ SimpleMessage message2 = SimpleMessage_init_zero; /* Create a stream that reads from the buffer. */ pb_istream_t stream2 = pb_istream_from_buffer(buffer, message_length); /* Now we are ready to decode the message. */ status = pb_decode(&stream2, SimpleMessage_fields, &message2); /* Check for errors... */ if (!status) { //printf("Decoding failed: %s/n", PB_GET_ERROR(&stream));// return 1; } /* Print the data contained in the message. */ //printf("Your lucky number was %d!/n", message.lucky_number); } while (1) { HAL_GPIO_TogglePin(Led_gpio,Led_pin); HAL_Delay(500); }}
开发者ID:sinaaghli,项目名称:STM32DT,代码行数:76,
示例2: main/** * @brief Main program * @param None * @retval None */int main(void){ /* STM32F4xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 180 MHz */ SystemClock_Config(); /* Configure LED3 */ BSP_LED_Init(LED3); /* Compute the prescaler value to have TIM1 counter clock equal to 18MHz */ uwPrescalerValue = (uint32_t) ((SystemCoreClock / 18000000) - 1); /*##-1- Configure the TIM peripheral #######################################*/ /* --------------------------------------------------------------------------- 1/ Generate 3 complementary PWM signals with 3 different duty cycles: TIM1 input clock (TIM1CLK) is set to 2 * APB2 clock (PCLK2), since APB2 prescaler is different from 1. TIM1CLK = 2 * PCLK2 PCLK1 = HCLK / 2 => TIM1CLK = HCLK = SystemCoreClock TIM1CLK is fixed to SystemCoreClock, the TIM1 Prescaler is set to have TIM1 counter clock = 18MHz. The objective is to generate PWM signal at 10 KHz: - TIM1_Period = (TIM1 counter clock / 10000) - 1 The Three Duty cycles are computed as the following description: The channel 1 duty cycle is set to 50% so channel 1N is set to 50%. The channel 2 duty cycle is set to 25% so channel 2N is set to 75%. The channel 3 duty cycle is set to 12.5% so channel 3N is set to 87.5%. The Timer pulse is calculated as follows: - ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100 2/ Insert a dead time equal to (100/SystemCoreClock) us 3/ Configure the break feature, active at High level, and using the automatic output enable feature 4/ Use the Locking parameters level1. Note: SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. Each time the core clock (HCLK) changes, user had to update SystemCoreClock variable value. Otherwise, any configuration based on this variable will be incorrect. This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency --------------------------------------------------------------------------- */ /* Initialize TIM peripheral as follows: + Prescaler = (SystemCoreClock/18000000) - 1 + Period = (1800 - 1) (to have an output frequency equal to 10 KHz) + ClockDivision = 0 + Counter direction = Up */ /* Select the Timer instance */ TimHandle.Instance = TIM1; TimHandle.Init.Prescaler = uwPrescalerValue; TimHandle.Init.Period = PERIOD_VALUE; TimHandle.Init.ClockDivision = 0; TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TimHandle.Init.RepetitionCounter = 0; if(HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-2- Configure the PWM channels #########################################*/ /* Common configuration for all channels */ sPWMConfig.OCMode = TIM_OCMODE_PWM1; sPWMConfig.OCPolarity = TIM_OCPOLARITY_HIGH; sPWMConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH; sPWMConfig.OCIdleState = TIM_OCIDLESTATE_SET; sPWMConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET; sPWMConfig.OCFastMode = TIM_OCFAST_DISABLE; /* Set the pulse value for channel 1 *///.........这里部分代码省略.........
开发者ID:nidhiyanandh,项目名称:STM32Cube_FW_F4_V1.5.0_GCC_Makefile,代码行数:101,
示例3: main/** * @brief Main program * @param None * @retval None */int main(void){ /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LED4 */ BSP_LED_Init(LED4); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /*##-1- Configure the TIM peripheral #######################################*/ /* TIM1 configuration: Input Capture mode --------------------- The external signal is connected to TIM1 CH2 pin (PA.09) The Rising edge is used as active edge, The TIM1 CCR2 is used to compute the frequency value ------------------------------------------------------------ */ /* Set TIMx instance */ TimHandle.Instance = TIMx; /* Initialize TIMx peripheral as follows: + Period = 0xFFFF + Prescaler = 0 + ClockDivision = 0 + Counter direction = Up */ TimHandle.Init.Period = 0xFFFF; TimHandle.Init.Prescaler = 0; TimHandle.Init.ClockDivision = 0; TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TimHandle.Init.RepetitionCounter = 0; if(HAL_TIM_IC_Init(&TimHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-2- Configure the Input Capture channel ################################*/ /* Configure the Input Capture of channel 2 */ sICConfig.ICPolarity = TIM_ICPOLARITY_RISING; sICConfig.ICSelection = TIM_ICSELECTION_DIRECTTI; sICConfig.ICPrescaler = TIM_ICPSC_DIV1; sICConfig.ICFilter = 0; if(HAL_TIM_IC_ConfigChannel(&TimHandle, &sICConfig, TIM_CHANNEL_2) != HAL_OK) { /* Configuration Error */ Error_Handler(); } /*##-3- Start the Input Capture in interrupt mode ##########################*/ if(HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_2) != HAL_OK) { /* Starting Error */ Error_Handler(); } while (1) { }}
开发者ID:GreyCardinalRus,项目名称:stm32-cube,代码行数:75,
示例4: main/** * @brief Main program. * @param None * @retval None */int main(void){ /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LED4 */ BSP_LED_Init(LED4); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /*##-1- Configure the TIM peripheral #######################################*/ /* --------------------------------------------------------------------------- TIM3 configuration: PWM Input mode In this example TIM3 input clock (TIM3CLK) is set to APB1 clock (PCLK1), since APB1 prescaler is 1. TIM3CLK = PCLK1 PCLK1 = HCLK => TIM3CLK = HCLK = SystemCoreClock External Signal Frequency = TIM3 counter clock / TIM3_CCR2 in Hz. External Signal DutyCycle = (TIM3_CCR1*100)/(TIM3_CCR2) in %. --------------------------------------------------------------------------- */ /* Set TIMx instance */ TimHandle.Instance = TIMx; /* Initialize TIMx peripheral as follows: + Period = 0xFFFF + Prescaler = 0 + ClockDivision = 0 + Counter direction = Up */ TimHandle.Init.Period = 0xFFFF; TimHandle.Init.Prescaler = 0; TimHandle.Init.ClockDivision = 0; TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TimHandle.Init.RepetitionCounter = 0; if (HAL_TIM_IC_Init(&TimHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-2- Configure the Input Capture channels ###############################*/ /* Common configuration */ sConfig.ICPrescaler = TIM_ICPSC_DIV1; sConfig.ICFilter = 0; /* Configure the Input Capture of channel 1 */ sConfig.ICPolarity = TIM_ICPOLARITY_FALLING; sConfig.ICSelection = TIM_ICSELECTION_INDIRECTTI; if (HAL_TIM_IC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK) { /* Configuration Error */ Error_Handler(); } /* Configure the Input Capture of channel 2 */ sConfig.ICPolarity = TIM_ICPOLARITY_RISING; sConfig.ICSelection = TIM_ICSELECTION_DIRECTTI; if (HAL_TIM_IC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2) != HAL_OK) { /* Configuration Error */ Error_Handler(); } /*##-3- Configure the slave mode ###########################################*/ /* Select the slave Mode: Reset Mode */ sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET; sSlaveConfig.InputTrigger = TIM_TS_TI2FP2; sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_NONINVERTED; sSlaveConfig.TriggerPrescaler = TIM_TRIGGERPRESCALER_DIV1; sSlaveConfig.TriggerFilter = 0; if (HAL_TIM_SlaveConfigSynchronization(&TimHandle, &sSlaveConfig) != HAL_OK) { /* Configuration Error */ Error_Handler(); } /*##-4- Start the Input Capture in interrupt mode ##########################*/ if (HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_2) != HAL_OK) { /* Starting Error */ Error_Handler();//.........这里部分代码省略.........
开发者ID:GreyCardinalRus,项目名称:stm32-cube,代码行数:101,
示例5: main/** * @brief Main program. * @param None * @retval None */int main(void){ float capacitanceratio; /* STM32F3xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /******* Initialize LEDs available on STM32303E-EVAL RevC board ******************/ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Configure the system clock to 72 MHz */ SystemClock_Config(); /*##-1- Initialize the Key push-button and Joystick ####################################*/ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); BSP_JOY_Init(JOY_MODE_GPIO); /*##-2- Initialize the LCD #################################################*/ /* Initialize the LCD */ BSP_LCD_Init(); /*##-3- Display messages on LCD ############################################*/ /* Display Example Welcome message */ Display_ExampleDescription(); /* Wait For User inputs */ while (1) { if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { while (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET); break; } } /* Display Example Template */ HYGROMETER_SetHint(); /*##-4- Configure DACx #####################################################*/ /* configure DACx */ DACx_Config(); /*##-5- Configure Comparators ##############################################*/ /* configure COMPx */ COMPx_Config(); /*##-6- Configure Timers ###################################################*/ TIM3_Config(); TIM4_Config(); /*##-7- Start Example ######################################################*/ /* wait until first AvrgICReadValue is calculated */ while(AvrgICReadValue == 0); /* Enter Calibration menu */ Calibration_Menu(); /* Infinite loop */ while (1) { /* Calculate Trigger Time Value */ TriggerTime = (float) (AvrgICReadValue-ICError)/SystemCoreClock; /* Comp4 inverted input connected to DACx : * TriggerTime = RES * Capacitance * ln(VDD/(VDD - VREF)) * @VREF = 2.086V (generated by DAC), ln(VDD/(VDD - VREF)) is ~ 1 * ==> Capacitance = TriggerTime/RES */ Capacitance = (float) TriggerTime/RES; /* Calculate humidity value using reversed polynomial expression */ capacitanceratio = Capacitance/Capacitance55RH; /* RH (%) = -3.4656*10^3 * X^3 + 1.0732*10^4 * X^2 - 1.0457*10^4*X + 3.2459*10^3 with X = C (read) / [email C++ HAL_InitTick函数代码示例 C++ HAL_IS_BIT_CLR函数代码示例
|