cancel
Showing results for 
Search instead for 
Did you mean: 

HAL Code Quality

torsten2
Associate II
Posted on June 21, 2016 at 10:20

Hello,

while I'm trying to figure out, why a project with USB support is not working as expected, I have to debug a lot in the HAL source code.

Nearly all HAL functions have a HAL_StatusTypeDef as return type. I check the result of such functions with an assert(), as I believe that most function will not return an error, if I used the API correctly or if the function does not run out of resources. All that checking is cumbersome and I wish that the called function would have integrated that assert() for API misuse and other SW developer errors. That would leave the return type only for functions that might fail at runtime even when used correctly.

But instead I find functions that will return always OK or that will simply ignore return values from called functions. So please:

- If there is a function that can not fail, please use void as return type.

- If a function can fail, please document under which circumstances the function will return which error code.

- If a function can only fail if used not correctly (is called with not given precondition, wrong state, wrong parameters), please do the assert() for us and change the return type to void.

- Please, if a called function returns an error, promote that error to the caller and do not simply swallow it.

I know that we all have to work under resource constrains, but every minute saved on HAL code quality will cost your users (costumers) a multitude of that time.

kind regards,

Torsten

#error-handling #hal #code-qualit
2 REPLIES 2
Amel NASRI
ST Employee
Posted on June 28, 2016 at 15:47

Hi robitzki.torsten,

Could you please provide examples of functions for which your comments are applicable?

It will be easier to understand then report internally for farther checks this way.

Thanks for any valuable comment you share.

-Mayla-

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.

Amel NASRI
ST Employee
Posted on July 15, 2016 at 12:22

The continuity of this discussion is [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/response%20to%20HAL%20Code%20Quality&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx&currentviews=36]here.

-Mayla-

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.