本文整理汇总了C++中HAL_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_Init函数的具体用法?C++ HAL_Init怎么用?C++ HAL_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int 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);
}
}
示例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 */
//.........这里部分代码省略.........
示例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)
{
}
}
示例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();
//.........这里部分代码省略.........
示例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 protected]%RH = capacitanceratio */
RelativeHumidity = RP3 * pow(capacitanceratio, 3) +
RP2 * pow(capacitanceratio, 2) +
RP1 * capacitanceratio +
RP0;
/* Restrict Relative Humidity Value to 0-99 Domain */
if (RelativeHumidity < 0)
{
RelativeHumidity = 0;
//.........这里部分代码省略.........
示例6: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure LED1, LED2, LED3 and LED4 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
/* Initialize Key button, will be used to trigger an interrupt each time it's pressed.
In the ISR the PLL source will be changed from HSE to HSI, and vice versa. */
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
/* Enable Power Control clock */
__PWR_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Enable HSE oscillator and configure the PLL to reach the max system frequency (168MHz)
when using HSE oscillator as PLL clock source. */
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 = 25;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers.
The SysTick 1 msec interrupt is required for the HAL process (Timeout management); by default
the configuration is done using the HAL_Init() API, and when the system clock configuration
is updated the SysTick configuration will be adjusted by the HAL_RCC_ClockConfig() API. */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Output SYSCLK divided by 2 on MCO2 pin(PC9) */
HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_2);
/* Toggle some LEDs in an infinite loop */
while (1)
{
/* Toggle LED1 */
BSP_LED_Toggle(LED1);
HAL_Delay(100);
/* Toggle LED2 */
BSP_LED_Toggle(LED2);
HAL_Delay(100);
/* Toggle LED4 */
BSP_LED_Toggle(LED4);
HAL_Delay(100);
}
}
示例7: main
int main(void) {
// TODO disable JTAG
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
// set the system clock to be HSE
SystemClock_Config();
// enable GPIO clocks
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
// enable the CCM RAM
__CCMDATARAMEN_CLK_ENABLE();
#if 0
#if defined(NETDUINO_PLUS_2)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
#if MICROPY_HW_HAS_SDCARD
// Turn on the power enable for the sdcard (PB1)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET);
#endif
// Turn on the power for the 5V on the expansion header (PB2)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET);
}
#endif
#endif
// basic sub-system init
pendsv_init();
led_init();
switch_init0();
int first_soft_reset = true;
uint reset_mode;
soft_reset:
// check if user switch held to select the reset mode
reset_mode = 1;
led_state(1, 0);
led_state(2, 1);
led_state(3, 0);
led_state(4, 0);
#if MICROPY_HW_HAS_SWITCH
if (switch_get()) {
for (uint i = 0; i < 3000; i++) {
if (!switch_get()) {
break;
}
HAL_Delay(20);
if (i % 30 == 29) {
reset_mode = (reset_mode + 1) & 7;
led_state(2, reset_mode & 1);
led_state(3, reset_mode & 2);
led_state(4, reset_mode & 4);
}
}
// flash the selected reset mode
for (uint i = 0; i < 6; i++) {
led_state(2, 0);
led_state(3, 0);
led_state(4, 0);
HAL_Delay(50);
led_state(2, reset_mode & 1);
led_state(3, reset_mode & 2);
led_state(4, reset_mode & 4);
HAL_Delay(50);
}
HAL_Delay(400);
}
#endif
#if MICROPY_HW_ENABLE_RTC
if (first_soft_reset) {
rtc_init();
}
#endif
// more sub-system init
//.........这里部分代码省略.........
示例8: 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 LED2 */
BSP_LED_Init(LED2);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/*##-1- Configure the TIM peripheral #######################################*/
/* -----------------------------------------------------------------------
In this example TIM3 input clock (TIM3CLK) is set to APB1 clock (PCLK1),
since APB1 prescaler is equal to 1.
TIM3CLK = PCLK1
PCLK1 = HCLK
=> TIM3CLK = HCLK = SystemCoreClock
To get TIM3 counter clock at 10 KHz, the Prescaler is computed as following:
Prescaler = (TIM3CLK / TIM3 counter clock) - 1
Prescaler = (SystemCoreClock /10 KHz) - 1
Note:
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f0xx.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
----------------------------------------------------------------------- */
/* Compute the prescaler value to have TIMx counter clock equal to 10000 Hz */
uwPrescalerValue = (uint32_t)(SystemCoreClock / 10000) - 1;
/* Set TIMx instance */
TimHandle.Instance = TIMx;
/* Initialize TIMx peripheral as follows:
+ Period = 10000 - 1
+ Prescaler = (SystemCoreClock/10000) - 1
+ ClockDivision = 0
+ Counter direction = Up
*/
TimHandle.Init.Period = 10000 - 1;
TimHandle.Init.Prescaler = uwPrescalerValue;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.RepetitionCounter = 0;
if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Start the TIM Base generation in interrupt mode ####################*/
/* Start Channel1 */
if (HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
while (1)
{
}
}
示例9: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
/* Configure LED1 and LED3 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED3);
/*##-1- Configure the TIM peripheral #######################################*/
/* ---------------------------------------------------------------------------
TIM3 Configuration: Output Compare Toggle Mode:
In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1),
since APB1 prescaler is different from 1.
TIM3CLK = 2 * PCLK1
PCLK1 = HCLK / 4
=> TIM3CLK = HCLK / 2 = SystemCoreClock /2
To get TIM3 counter clock at 18 MHz, the prescaler is computed as follows:
Prescaler = (TIM3CLK / TIM3 counter clock) - 1
Prescaler = ((SystemCoreClock /2) /18 MHz) - 1
CC1 update rate = TIM3 counter clock / uhCCR1_Val = 439.44 Hz
==> So the TIM3 Channel 1 generates a periodic signal with a
frequency equal to 219.72 Hz.
CC2 update rate = TIM3 counter clock / uhCCR2_Val = 878.9 Hz
==> So the TIM3 Channel 2 generates a periodic signal with a
frequency equal to 439.45 Hz.
CC3 update rate = TIM3 counter clock / uhCCR3_Val = 1757.81 Hz
==> So the TIM3 Channel 3 generates a periodic signal with a
frequency equal to 878.9 Hz.
CC4 update rate = TIM3 counter clock / uhCCR4_Val = 3515.62 Hz
==> So the TIM3 Channel 4 generates a periodic signal with a
frequency equal to 1757.81 Hz.
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
--------------------------------------------------------------------------- */
/* Compute the prescaler value to have TIMx counter clock equal to 21 MHz */
uwPrescalerValue = (uint32_t)(((SystemCoreClock /2) / 18000000) - 1);
/* Initialize TIMx peripheral as follow:
+ Prescaler = ((SystemCoreClock /2) / 18000000) - 1
+ Period = 65535
+ ClockDivision = 0
+ Counter direction = Up
*/
TimHandle.Instance = TIMx;
TimHandle.Init.Period = 65535;
TimHandle.Init.Prescaler = uwPrescalerValue;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_OC_Init(&TimHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure the Output Compare channels ##############################*/
/* Output Compare Toggle Mode configuration: Channel1 */
sConfig.OCMode = TIM_OCMODE_TOGGLE;
sConfig.Pulse = uhCCR1_Val;
sConfig.OCPolarity = TIM_OCPOLARITY_LOW;
if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
/* Output Compare Toggle Mode configuration: Channel2 */
sConfig.Pulse = uhCCR2_Val;
if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
//.........这里部分代码省略.........
示例10: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* This sample code shows how to use STM32F7xx CEC HAL API to transmit and
* receive data. The device is set in waiting to receive mode and sends
* messages when the evaluation board buttons are pushed by the user */
/* Configure the MPU attributes as Write Through */
MPU_Config();
/* Enable the CPU Cache */
CPU_CACHE_Enable();
/* STM32F7xx HAL library initialization:
- Configure the Flash ART accelerator
- 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 200 MHz MHz */
SystemClock_Config();
/*##-1- Initialize the SDRAM ##############################################*/
BSP_SDRAM_Init();
/*##-2- Initialize the LCD #################################################*/
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER);
/* Enable the LCD */
BSP_LCD_DisplayOn();
/* Select the LCD Foreground layer */
BSP_LCD_SelectLayer(1);
/* Display test description on screen */
CEC_SetHint();
/* -2- Configure touch screen */
BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
BSP_TS_ITConfig(); /* Touch screen interrupt configuration and enable */
/* -3- CEC configuration (transfer will take place in Interrupt mode) */
#if defined (DEVICE_1)
DestinationAddress = DEVICE_ADDRESS_2; /* follower address */
#elif defined (DEVICE_2)
DestinationAddress = DEVICE_ADDRESS_1; /* follower address */
#endif
hcec.Instance = CEC;
/* Deinitialize CEC to reinitialize from scratch */
HAL_CEC_DeInit(&hcec);
/* IP configuration */
CEC_Config(&hcec);
/* -4- CEC transfer general variables initialization */
ReceivedFrame = 0;
StartSending = 0;
NbOfReceivedBytes = 0;
CEC_FlushRxBuffer();
/* Test start */
/* Enter infinite reception loop: the CEC device is set in
* waiting to receive mode.
* The CEC "background" state is HAL_CEC_STATE_STANDBY_RX.
* Upon any message reception or transmission, the CEC
* comes back to that state.
* It is up to the user to define exit conditions in modifying
* accordingly the RX, TX or Error callback functions. */
HAL_CEC_Receive_IT(&hcec, (uint8_t *)&Tab_Rx);
while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_READY)
{
/* if no reception has occurred and no error has been detected,
* transmit a message if the user has pushed a button */
if( (StartSending == 1) && (ReceivedFrame == 0))
{
HAL_CEC_Transmit_IT(&hcec, DestinationAddress, (uint8_t *)&Tab_Tx, TxSize);
/* loop until TX ends or TX error reported */
while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_STANDBY_RX);
StartSending = 0;
}
/* if a frame has been received */
if (ReceivedFrame == 1)
{
if (Tab_Rx[1] == 0x44) /* Test on the opcode value */
//.........这里部分代码省略.........
示例11: main
int main()//OPTIMIZATION LEVEL = 0
{
HAL_Init();
SystemClockConfig();
ConfigLED();
ConfigTimer();
rtksvrstart(&svr);
ConfigUART(svr.format[0]);
fobs[0]=fobs[1]=0;
//svr.raw[1].time.time = 1429540822;//test SS2 data
//svr.raw[1].time.time = 1429539852;//test SS2 data
while (HAL_UART_Receive_DMA(&UartGPSHandle,svr.buff[0],MAX_RAW_LEN) != HAL_OK);
while (HAL_UART_Receive_DMA(&UartRFHandle,svr.buff[1],MAX_RAW_LEN) != HAL_OK);
HAL_Delay(3000);
sendRequest(svr.format[0]);
// test();
while(1)
{
#ifndef _TEST_RESULT
if (flagTimeout)
{
int index,temp;
flagTimeout=0;
//SendIntStr(UartGPSHandle.Instance->SR);
//SendIntStr(UartRFHandle.Instance->SR);
for (index=0;index<2;index++)
{
if (index==0)
temp = UartGPSHandle.hdmarx->Instance->NDTR & 0xffff;
else
temp = UartRFHandle.hdmarx->Instance->NDTR & 0xffff;
if (temp + svr.buffPtr[index] <= MAX_RAW_LEN)
svr.nb[index] = MAX_RAW_LEN - svr.buffPtr[index] - temp;
else
svr.nb[index] = 2*MAX_RAW_LEN - temp - svr.buffPtr[index];
fobs[index] = decode_raw(&svr,index);
svr.buffPtr[index] = MAX_RAW_LEN - temp;
}
// temp = UartGPSHandle.hdmarx->Instance->NDTR & 0xffff;
// if (temp + svr.buffPtr[0] <= MAX_RAW_LEN)
// svr.nb[0] = MAX_RAW_LEN - svr.buffPtr[0] - temp;
// else
// svr.nb[0] = 2*MAX_RAW_LEN - temp - svr.buffPtr[0];
// if (svr.buffPtr[0] + svr.nb[0] <= MAX_RAW_LEN)
// {
// for (i = svr.buff[0] + svr.buffPtr[0] ;
// i < svr.buff[0] + svr.buffPtr[0] + svr.nb[0]; i++)
// {
// HAL_UART_Transmit(&UartResultHandle,i,1,1);
// }
// }
// else
// {
// for (i = svr.buff[0] + svr.buffPtr[0] ;
// i < svr.buff[0] + MAX_RAW_LEN; i++)
// {
// HAL_UART_Transmit(&UartResultHandle,i,1,1);
// }
// for (i = svr.buff[0] ;
// i < svr.buff[0] + svr.nb[0] + svr.buffPtr[0] - MAX_RAW_LEN ; i++)
// {
// HAL_UART_Transmit(&UartResultHandle,i,1,1);
// }
// }
// svr.buffPtr[0] = MAX_RAW_LEN - temp;
//rtk positioning**********************************************************************
// if (0)
if (fobs[1])
{
fobs[1]=0;
LED4_TOGGLE;
}
if (fobs[0])
{
int i;
fobs[0]=0;
LED3_TOGGLE;
#ifdef TIME_MEASURE
start=HAL_GetTick();
#endif
temp=svr.obs[0].n;
for (i=0;i<temp;i++)
//.........这里部分代码省略.........
示例12: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F103xB 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 64 MHz */
SystemClock_Config();
/* Configure LED2 */
BSP_LED_Init(LED2);
/*##-1- Configure the UART peripheral ######################################*/
/* Put the USART peripheral in the Asynchronous mode (UART Mode) */
/* UART configured as follows:
- Word Length = 8 Bits (7 data bit + 1 parity bit) :
BE CAREFUL : Program 7 data bits + 1 parity bit in PC HyperTerminal
- Stop Bit = One Stop bit
- Parity = ODD parity
- BaudRate = 9600 baud
- Hardware flow control disabled (RTS and CTS signals) */
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 9600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_ODD;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
if (HAL_UART_Init(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Start the transmission process #####################################*/
/* User start transmission data through "TxBuffer" buffer */
if (HAL_UART_Transmit_DMA(&UartHandle, (uint8_t *)aTxBuffer, TXBUFFERSIZE) != HAL_OK)
{
/* Transfer error in transmission process */
Error_Handler();
}
/*##-3- Put UART peripheral in reception process ###########################*/
/* Any data received will be stored in "RxBuffer" buffer : the number max of
data received is 10 */
if (HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
/* Transfer error in reception process */
Error_Handler();
}
/*##-4- Wait for the end of the transfer ###################################*/
/* Before starting a new communication transfer, you need to check the current
state of the peripheral; if it’s busy you need to wait for the end of current
transfer before starting a new one.
For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)
{
}
/*##-5- Send the received Buffer ###########################################*/
if (HAL_UART_Transmit_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
/* Transfer error in transmission process */
Error_Handler();
}
/*##-6- Wait for the end of the transfer ###################################*/
/* Before starting a new communication transfer, you need to check the current
state of the peripheral; if it’s busy you need to wait for the end of current
transfer before starting a new one.
For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)
{
}
/* Infinite loop */
while (1)
{
}
}
示例13: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* 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();
/* Configure the system clock to 72 MHz */
SystemClock_Config();
/* Configure LEDs */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED4);
/*##-1- Configure the TSC peripheral #######################################*/
TscHandle.Instance = TSCx;
TscHandle.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL;
TscHandle.Init.CTPulseHighLength = TSC_CTPH_1CYCLE;
TscHandle.Init.CTPulseLowLength = TSC_CTPL_1CYCLE;
TscHandle.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW;
TscHandle.Init.MaxCountInterrupt = ENABLE;
TscHandle.Init.MaxCountValue = TSC_MCV_16383;
TscHandle.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV64;
TscHandle.Init.SpreadSpectrum = DISABLE;
TscHandle.Init.SpreadSpectrumDeviation = 127;
TscHandle.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1;
TscHandle.Init.SynchroPinPolarity = TSC_SYNC_POL_FALL;
TscHandle.Init.ChannelIOs = 0; /* Not needed yet. Will be set with HAL_TSC_IOConfig() */
TscHandle.Init.SamplingIOs = 0; /* Not needed yet. Will be set with HAL_TSC_IOConfig() */
TscHandle.Init.ShieldIOs = 0; /* Not needed yet. Will be set with HAL_TSC_IOConfig() */
if (HAL_TSC_Init(&TscHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure the touch-sensing IOs ####################################*/
IoConfig.ChannelIOs = TSC_GROUP8_IO2; /* Start with the first channel */
IoConfig.SamplingIOs = (TSC_GROUP8_IO1 | TSC_GROUP8_IO1 | TSC_GROUP6_IO1);
IoConfig.ShieldIOs = TSC_GROUP6_IO2;
if (HAL_TSC_IOConfig(&TscHandle, &IoConfig) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-3- Discharge the touch-sensing IOs ####################################*/
HAL_TSC_IODischarge(&TscHandle, ENABLE);
HAL_Delay(1); /* 1 ms is more than enough to discharge all capacitors */
/*##-4- Start the acquisition process ######################################*/
if (HAL_TSC_Start_IT(&TscHandle) != HAL_OK)
{
/* Acquisition Error */
Error_Handler();
}
/* Infinite loop */
while (1)
{
/*Suspend Tick increment to prevent wakeup by Systick interrupt.
Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/
HAL_SuspendTick();
/* The acquisition process is now performed in the HAL_TSC_ConvCpltCallback() function */
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
/* Resume Tick interrupt if disabled prior to sleep mode entry*/
HAL_ResumeTick();
}
}
示例14: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F3xx HAL library initialization:
- Configure the Flash prefetch
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Low Level Initialization
*/
HAL_Init();
/* Configure LED2 */
BSP_LED_Init(LED2);
/* Configure the system clock to 64 MHz */
SystemClock_Config();
/*##-1- Configure the TIM peripheral #######################################*/
/* -----------------------------------------------------------------------
In this example TIM2 input clock (TIM2CLK) is set to 2 * APB1 clock (PCLK1),
since APB1 prescaler is different from 1.
TIM2CLK = 2 * PCLK1
PCLK1 = HCLK / 2
=> TIM2CLK = HCLK = SystemCoreClock (Hz)
To get TIM2 counter clock at 10 KHz, the Prescaler is computed as following:
Prescaler = (TIM2CLK / TIM2 counter clock) - 1
Prescaler = (SystemCoreClock /10 KHz) - 1
Note:
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f3xx.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
----------------------------------------------------------------------- */
/* Compute the prescaler value to have TIMx counter clock equal to 10000 Hz */
uwPrescalerValue = (uint32_t)(SystemCoreClock / 10000) - 1;
/* Set TIMx instance */
TimHandle.Instance = TIMx;
/* Initialize TIMx peripheral as follows:
+ Period = 10000 - 1
+ Prescaler = (SystemCoreClock/10000) - 1
+ ClockDivision = 0
+ Counter direction = Up
*/
TimHandle.Init.Period = 10000 - 1;
TimHandle.Init.Prescaler = uwPrescalerValue;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.RepetitionCounter = 0;
if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Start the TIM Base generation in interrupt mode ####################*/
/* Start Channel1 */
if (HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
while (1)
{
}
}
示例15: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
/* Configure LED2 */
BSP_LED_Init(LED2);
/*##-1- Configure the TIM peripheral #######################################*/
/* 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;
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;
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();
}
/*##-5- Start the Input Capture in interrupt mode ##########################*/
if(HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_1) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
/* Infinite loop */
while (1)
{
}
}