9 years, 5 months ago.

[STM32] Just one xxx_HandleTypeDef for all instances of given peripheral?

I've noticed that in every driver implementation (i2c_api.c, serial_api.c, ...) there is always just one PPP_HandleTypeDef (I2C_HandleTypeDef, UART_HandleTypeDef…) and the PPP_HandleTypeDef.Instance pointer gets changed according to the hardware instance that is meant to be worked with (I2C1, I2C2 ..).

IMHO this is wrong and goes against the very design of STM32 HAL. http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00105879.pdf section 2.2.1 (p.59) states that each peripheral instance should have its own handle and it's only logical since it contains components like lock, buffer pointers, state,.. that should be specific for every peripheral instance.

Have I just misunderstood it, is it some ingenious use of the STM32 HAL or is really wrong?

Be the first to answer this question.