2020-11-01 01:10 PM
Hello,
I just created a CubeMX project and tried to create a timer handler/ I am getting bellow error.
../Src/main.c:46:1: error: unknown type name 'TIM_HandleTypeDef'; did you mean 'I2C_HandleTypeDef'?
TIM_HandleTypeDef htimer2;
Here is the code:
#include "main.h"
#include "stm32h7xx_hal.h"
UART_HandleTypeDef huart2;
TIM_HandleTypeDef htimer2;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
void GPIO_Init(void);
void LSE_Config(void);
char *data = "Hello world, I made it using STM32 ARM Cortex M7!\r\n";
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
GPIO_Init();
MX_USART2_UART_Init();
char msg[100];
char *user_data = "Hello world, I made it using STM32 ARM Cortex M7!\r\n";
if (HAL_UART_Transmit(&huart2,(uint8_t*)user_data,strlen(user_data), HAL_MAX_DELAY) != HAL_OK)
{
// Error occurred
Error_Handler();
}
while(1);
data = "End of program\r\n";
HAL_UART_Transmit(&huart2,(uint8_t*)data,strlen(data), HAL_MAX_DELAY);
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
//RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
}
void GPIO_Init(void)
{
__HAL_RCC_GPIOD_CLK_ENABLE();
GPIO_InitTypeDef ledgpio;
ledgpio.Pin = GPIO_PIN_14;
ledgpio.Mode = GPIO_MODE_OUTPUT_PP;
ledgpio.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &ledgpio);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
data = "Something went wrong\r\n";
HAL_UART_Transmit(&huart2,(uint8_t*)data,strlen(data), HAL_MAX_DELAY);
while(1)
{
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
}
}
void LSE_Config(void)
{
RCC_OscInitTypeDef OSC_Init;
// Activating LSE
OSC_Init.OscillatorType = RCC_OSCILLATORTYPE_LSE;
OSC_Init.LSEState = RCC_LSE_ON;
if (HAL_RCC_OscConfig(&OSC_Init) != HAL_OK)
{
Error_handler();
}
// Configuring LSE to input pin
HAL_RCC_MCOConfig(RCC_MCO1,RCC_MCO1SOURCE_LSE,RCC_MCODIV_1);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Solved! Go to Solution.
2020-11-01 04:07 PM
Seems like the timer was not active when you generated the CubeMX code and you added it afterwards. Seems like you modified the main() function quite a bit as well.
You can go into the stm32*_hal_conf.h file and activate the timer module (#define HAL_TIM_MODULE_ENABLED). Or you can regenerate the CubeMX with the timer activated.
2020-11-01 04:07 PM
Seems like the timer was not active when you generated the CubeMX code and you added it afterwards. Seems like you modified the main() function quite a bit as well.
You can go into the stm32*_hal_conf.h file and activate the timer module (#define HAL_TIM_MODULE_ENABLED). Or you can regenerate the CubeMX with the timer activated.
2020-11-02 04:47 AM
Yes, you guessed it right. The timer was not active and worked just fine after uncommenting #define HAL_TIM_MODULE_ENABLED.
Also, I am in the learning phase, that's why main() is modified so much.
Thanks for the quick help!
2024-01-24 04:40 AM
Hi, TDK i try to enabled already but why i got this error " Description Resource Path Location Type
fatal error: stm32g0xx_hal_tim.h: No such file or directory stm32g0xx_hal_conf.h /X590-MB-G071KBU6/Core/Inc line 316 C/C++ Problem"
2024-01-24 06:10 AM
It sounds like the file doesn't exist at the specified location. Does it?
Please open a new thread with relevant information instead of re-posting in this one as your issue is not the same, and this thread is solved.