cancel
Showing results for 
Search instead for 
Did you mean: 

HAL Vs Firmware

waheed901
Associate II
Posted on August 11, 2015 at 14:22

Can anyone help me in understanding difference between HAL and firmware,

I can find plenty of examples useful for starter as complete project in HAL related stuff, while no such thing available for firmware stuff (at least to my limited knowledge)

If there is any, please share for me, I am interested in some project like inputcapture, (project of HAL, available online) in firmware, 

also please tell me equivalent to this instruction for HAL

TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);

Thanks in Advance
8 REPLIES 8
RomainR.
ST Employee
Posted on August 11, 2015 at 14:47

in HAL should be:

/**

  * @brief   Configures the clock source to be used

  * @param  htim: pointer to a TIM_HandleTypeDef structure that contains

  *                the configuration information for TIM module.

  * @param  sClockSourceConfig: pointer to a TIM_ClockConfigTypeDef structure that

  *         contains the clock source information for the TIM peripheral.

  * @retval HAL status

  */

HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig)  

  */

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on August 11, 2015 at 17:58

STM32F4xx_DSP_StdPeriph_Lib_V1.5.1\Project\STM32F4xx_StdPeriph_Examples\TIM\TIM_InputCapture

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
waheed901
Associate II
Posted on August 12, 2015 at 03:45

thanks rrom,

waheed901
Associate II
Posted on August 12, 2015 at 03:46

thanks clive

waheed901
Associate II
Posted on August 12, 2015 at 05:01

Is there any project available which can count external pulses (not the frequency) JUST NO OF EXTERNAL PULSES in HAL or firmware? if any one know this please guide me.

Thanks in advance

Posted on August 12, 2015 at 06:17

I'm only working with the SPL (Standard Peripheral Library)

For setting up the external count we have

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/STM32F4%20Timer%20External%20Pulse%20counting&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentview...

The current count being visible in TIMx->CNT, now you could probably augment that by latching the content into one of the capture registers, periodically, at a defined integration period that works for the frequency being used, and the width of the counter (16/32-bit). Perhaps every 1ms or 10ms.

http://www.st.com/web/en/resource/technical/document/application_note/DM000425pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
RomainR.
ST Employee
Posted on August 12, 2015 at 06:55

Some goods examples to watch on F0 device.

https://www.youtube.com/watch?v=R8UwAboFQGA

https://www.youtube.com/watch?v=_wE7tbilca4

Easily to use with others series

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

waheed901
Associate II
Posted on August 12, 2015 at 16:33

Thanks for the replies

I am trying to use TIM1 in  external counting mode, but some how the count is changing even I have not connected any signal to PE9 (even not to any pin). can any one tell me whats going on with the code? I am using STM32F4 Discovery

I am pasting my program: 

/********************************************

  * main.c 

  * 

  **************************  */

#include ''main.h''

TIM_HandleTypeDef      TimHandle;

TIM_ClockConfigTypeDef sClockSourceConfig;

TIM_MasterConfigTypeDef sMasterConfig;

uint32_t               uwIC2Value1 = 0;

uint32_t               uwIC2Value2 = 0;

uint32_t               uwDiffCapture = 0;

uint16_t               uhCaptureIndex = 0;

uint32_t               uwFrequency = 0;

uint32_t               uwFrequency1 = 0;

uint32_t               uwFrequency2 = 0;

uint32_t               uwFrequency3 = 0;

uint32_t               uw = 0;

uint32_t               uw2 = 0;

static void SystemClock_Config(void);

void MX_TIM1_Init(void);

void MX_GPIO_Init(void);

int main(void)

{

   HAL_Init();

  SystemClock_Config();

  MX_TIM1_Init();

 

MX_GPIO_Init();

 

  while (1)

  {

if(uhCaptureIndex == 0)

    {

      /* Get the 1st Input Capture value */

      uw=TIM1->CNT;

      uhCaptureIndex = 1;

    }

    else if(uhCaptureIndex == 1)

    {

      /* Get the 2nd Input Capture value */

      uw2=TIM1->CNT;

 

if (uw2 > uw)

      {

        uwDiffCapture = (uw2 - uw); 

      }

      else  /* (uwIC2Value2 <= uwIC2Value1) */

      {

        uwDiffCapture = ((0xFFFF - uw) + uw2); 

      }

uw=uw2;

uwFrequency=uwDiffCapture;

}

}

}

static void SystemClock_Config(void)

{

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable Power Control clock */

  __HAL_RCC_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 = 25;*/

RCC_OscInitStruct.PLL.PLLM = 8;

  /*RCC_OscInitStruct.PLL.PLLN = 360;*/

RCC_OscInitStruct.PLL.PLLN = 336;

  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

  RCC_OscInitStruct.PLL.PLLQ = 7;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2      clocks dividers */

  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;  

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

}

void MX_TIM1_Init(void)

{

 

/*##-1- Configure the TIM peripheral #########*/ 

  TimHandle.Instance = TIMx;

  TimHandle.Init.Period            = 0xFFFF;

  TimHandle.Init.Prescaler         = 0;

  TimHandle.Init.ClockDivision= TIM_CLOCKDIVISION_DIV1;

  TimHandle.Init.CounterMode       = TIM_COUNTERMODE_UP;

  TimHandle.Init.RepetitionCounter = 0;

  HAL_TIM_Base_Init(&TimHandle);

  sClockSourceConfig.ClockSource=TIM_CLOCKSOURCE_ETRMODE2;

sClockSourceConfig.ClockPolarity = TIM_CLOCKPOLARITY_NONINVERTED;

sClockSourceConfig.ClockPrescaler = TIM_CLOCKPRESCALER_DIV1;

sClockSourceConfig.ClockFilter = 0;

HAL_TIM_ConfigClockSource(&TimHandle, &sClockSourceConfig);

sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

HAL_TIMEx_MasterConfigSynchronization(&TimHandle, &sMasterConfig);

 __TIM1_CLK_ENABLE();

    TIM1->CNT=0; 

  //  TIM1->CR1|=0x0001; 

}  

void MX_GPIO_Init(void)

{

  GPIO_InitTypeDef   GPIO_InitStruct;

 

  /*##-1- Enable peripherals and GPIO Clocks ####*/

  /* TIMx Peripheral clock enable */

  TIMx_CLK_ENABLE(); // TIM 1 clc enable

    

  /* Enable GPIO channels Clock */

  TIMx_CHANNEL_GPIO_PORT(); // Port E enable

  

  /* Configure  (TIMx_Channel) in Alternate function, push-pull and 100MHz speed */

  GPIO_InitStruct.Pin = GPIO_PIN_CHANNEL2;  //GPIO_PIN_CHANNEL2 GPIO_PIN_11

 // GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

 // GPIO_InitStruct.Pull = GPIO_PULLUP;

  

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF_TIMx;

  HAL_GPIO_Init(GPIO_PORT, &GPIO_InitStruct);

  /*##-2- Configure the NVIC for TIMx ############*/

  /* Sets the priority grouping field */

  HAL_NVIC_SetPriority(TIMx_IRQn, 0, 1);  //# TIMx_IRQn       TIM1_CC_IRQn

  

  /* Enable the TIM4 global Interrupt */

  HAL_NVIC_EnableIRQ(TIMx_IRQn);    // TIMx_IRQHandler        TIM1_CC_IRQHandler

}