cancel
Showing results for 
Search instead for 
Did you mean: 

Error Trying to Implement a Project on another Project

Victor Queiroz
Associate II
Posted on March 15, 2018 at 20:32

Hello there,

I'm using the IAR to code my project for STM32F091VC to collect weather data from 9 sensors. Recently I changed the Wind Direction sensor that was at first digital and now is analogic. The problem is that the pin it was connected doesn't have an ADC to make the conversion and I needed to program the new sensor in another pin. 

Right now I have 2 projects. Nº 1 has all sensors programmed without the new Wind Direction analogic sensor. Nº 2 has only the new analogic sensor and it was generated from STM32CubeMX with PC0 as ADC Pin connection. I'm trying to copy the new configurations from nº2 to nº1 and when I'm trying to rebuild the nº1 project I'm getting this error with C Compiler:

Error[Pe159]: declaration is incompatible with previous '_Error_Handler' (declared at line 613) C:\Users\victo\Desktop\TEST_DRFARM\Test_1_DrFarm\Src\main.c 700

This is the stretch with the error wich was generated by STM32CubeMX:

/**

* @brief System Clock Configuration

* @retval None

*/

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct;

RCC_ClkInitTypeDef RCC_ClkInitStruct;

/**Initializes the CPU, AHB and APB busses clocks

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;

RCC_OscInitStruct.HSICalibrationValue = 16;

RCC_OscInitStruct.HSI14CalibrationValue = 16;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Initializes the CPU, AHB and APB busses clocks

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configure the Systick interrupt time

*/

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick

*/

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */

HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

/* ADC init function */

static void MX_ADC_Init(void)

{

ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

*/

hadc.Instance = ADC1;

hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;

hadc.Init.Resolution = ADC_RESOLUTION_8B;

hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

hadc.Init.LowPowerAutoWait = DISABLE;

hadc.Init.LowPowerAutoPowerOff = DISABLE;

hadc.Init.ContinuousConvMode = DISABLE;

hadc.Init.DiscontinuousConvMode = DISABLE;

hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

hadc.Init.DMAContinuousRequests = DISABLE;

hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;

if (HAL_ADC_Init(&hadc) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configure for the selected ADC regular channel to be converted.

*/

sConfig.Channel = ADC_CHANNEL_10;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES_5;

if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

/** Pinout Configuration

*/

static void MX_GPIO_Init(void)

{

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**

* @brief This function is executed in case of error occurrence.

* @param file: The file name as string.

* @param line: The line in file as a number.

* @retval None

*/

void _Error_Handler(char *file, int line)

{

/* USER CODE BEGIN Error_Handler_Debug */

/* User can add his own implementation to report the HAL error return state */

while(1)

{

}

/* USER CODE END Error_Handler_Debug */

}

Declared Line 613 is: 

    _Error_Handler(__FILE__, __LINE__);

From if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

What is confusing me is that when I build the nº2 project with this same functions configuration the project build with zero errors.

I try to use this guide 

https://community.st.com/0D50X00009XkXpXSAV

 but I'm not using C++ compiler. My version of IAR is 7.70.1 

Thank you.

#stm32f0 #adc-stm32f0 #stm32f0-hal
5 REPLIES 5
Andrew Neil
Evangelist
Posted on March 16, 2018 at 12:33

It is a basic requirement of the 'C' programming language that a symbol (ie, function or variable name) must be declared before it is used.

In the absence of an explicit declaration, a default

 may be used.

Looks like you have calls to 

_Error_Handler()  before it has been declared.

So you probably also have warnings telling you that the compiler has used a default declaration?

When it finds the actual declaration (at line 613), it does not match this default

declaration - hence the error.

The solution is to provide a prototype for 

_Error_Handler()  before any calls to it.

Again, this is standard 'C' stuff - nothing specifically to do with STM32 or IAR.

Here are some 'C' references for you: 

http://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/

  
Posted on March 16, 2018 at 15:08

Hi Andrew, 

Thank you for your answer but I already know it. 

This is the declaration of the function before it was called. This is line 90-94 of some functions of my project. As I said before, I copied the nº2 project's configuration and in nº2 project the code build with no errors.

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_ADC_Init(void);

void _Error_Handler(char *file, int line);
Posted on March 16, 2018 at 15:14

So show the full source file, and identify where are lines 613 and 700

Posted on March 16, 2018 at 16:56

So what you show as line 613 is a call.

The error message says

Error[Pe159]: declaration is incompatible with previous '_Error_Handler' (declared at line 613) C:\Users\victo\Desktop\TEST_DRFARM\Test_1_DrFarm\Src\main.c 700

So for some reason it thinks line 613 is a declaration - not a call.

Again, are there any other errors or warnings?

Are you sure you are looking at the right file?