2022-01-04 06:07 AM
Hello Everyone. I'm a student and learning ST nowadays.
Forgive me for my childish question but I really don't get it.
HAL library's functions are usually returns a value of result of the process.
For example, HAL_Init func returns HAL_StatusTypeDef value. When I generate a project from CubeMX or CubeIDE, default codes doesn't use HAL_StatusTypeDef.
The program just inits and moves on. Never check if it if busy or gets error.
I don't know could I tell myself clearly
Thanks for reply, have a good day.
Solved! Go to Solution.
2022-01-04 06:57 AM
Yes, but the success code is HAL_OK. This is done many places in the CubeMX generated code. For example:
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
2022-01-04 06:22 AM
Welcome, @Amewp.1, to the community!
Well, it is up to the user to evaluate in his program the return values of the HAL calls and to react accordingly. In the source codes generated by STM32CubeMX/CubeIDE you can find examples like:
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
Of course this Error_Handler, which is typically located in main.c, must also be filled with actions, by default it is indeed empty. But it is also mentioned in the comments:
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
/* USER CODE END Error_Handler_Debug */
}
So you can insert any actions there: a reset, switching on a LED and subsequent while(1), output via a terminal, etc etc. You are completely free to do whatever you want.
Regards
/Peter
2022-01-04 06:53 AM
uint8_t errCode;
errCode = HAL_Init();
if (errCode != SUCCESS)
{
// do something
}
Ok I got the concept but can I use this kind of? Does it makes sense?
2022-01-04 06:57 AM
Yes, but the success code is HAL_OK. This is done many places in the CubeMX generated code. For example:
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
2022-01-04 07:20 AM
OK thak you for all perfect answers. Have a good day