cancel
Showing results for 
Search instead for 
Did you mean: 

The__HANDLE__ para in the functions, how to call

AMP HF
Associate II
Posted on February 27, 2018 at 04:11

When I use this function __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) like this:

__HAL_TIM_SET_COMPARE(&htim3,TIM_CHANNEL_2,10);

//I should use the '&' with the handle para.

what will happen if I use it like 

__HAL_TIM_SET_COMPARE(htim3,TIM_CHANNEL_2,10) without '&'?

But when I use IWDG funtion __HAL_IWDG_RELOAD_COUNTER(__HANDLE__):

__HAL_IWDG_RELOAD_COUNTER(hiwdg);

//why no '&' here?

#stm32f0-hal #__handle__ #stm32
1 REPLY 1
Posted on February 27, 2018 at 05:03

You want to pass it as an address, so typically it would have and &

You're second case is where it is already an address (pointer) like inside 

HAL_IWDG_Init().

HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)

{

...

/* Reload IWDG counter with value defined in the reload register */

__HAL_IWDG_RELOAD_COUNTER(hiwdg);

..

}

vs top level stuff

static IWDG_HandleTypeDef IwdgHandle; // ACTUAL PHYSICAL STRUCTURE

..

/*##-3- Configure & Start the IWDG peripheral #########################################*/

/* Set counter reload value to obtain 1 sec. IWDG TimeOut.

IWDG counter clock Frequency = uwLsiFreq

Set Prescaler to 32 (IWDG_PRESCALER_32)

Timeout Period = (Reload Counter Value * 32) / uwLsiFreq

So Set Reload Counter Value = (1 * uwLsiFreq) / 32 */

IwdgHandle.Instance = IWDG;

IwdgHandle.Init.Prescaler = IWDG_PRESCALER_32;

IwdgHandle.Init.Reload = (uwLsiFreq / 32);

IwdgHandle.Init.Window = IWDG_WINDOW_DISABLE;

if(HAL_IWDG_Init(&IwdgHandle) != HAL_OK) // ADDRESS OF STRUCTURE

{

/* Initialization Error */

Error_Handler();

}

This would seem to be basic C pointer stuff.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..