2025-01-27 12:38 PM
I am developing in C++ on a STM32U5, with HAL and was trying to figure how to embed interrupt handling in a class.
So I've questioned ChatGPT and DeepSeek for a solution and both gave an answer using pUserData field for storing object reference.
pUserData is a field provided by any handler (like UART_HandleTypeDef) and ... I do not have such field with my version of HAL that CubeIDE used for building my project.
I've pinpointed that problem to DeepSeek that gave me this answer:
Okay, the user mentioned that the HAL handlers don't have a pUserData field. Hmm, I need to recall which STM32 HAL versions include that. Oh right, older versions might not have it, especially before HAL introduced the MSP layer with user data pointers.
So, is there a version of HAL with that field ? My version of HAL seems not so old (and U5 family is rather new), so how much recent should be HAL version to have this field ? Or both AI are totally dumb ?
Solved! Go to Solution.
2025-01-27 01:05 PM
Good question, I've seen in used in the STM32_USB_Device_Library (L4 v1.14.0) as a means of passing a related user/extension to the primary handle.
In other situations I've seen nested-doll type structures passed as UART_HandleTypeDef, where user data you want to carry around with the pointer thru call-in and call-back gets appended to the end of ST's structure.
You could also modify the UART_HandleTypeDef structure to carry your own information/extension
2025-01-27 01:05 PM
Good question, I've seen in used in the STM32_USB_Device_Library (L4 v1.14.0) as a means of passing a related user/extension to the primary handle.
In other situations I've seen nested-doll type structures passed as UART_HandleTypeDef, where user data you want to carry around with the pointer thru call-in and call-back gets appended to the end of ST's structure.
You could also modify the UART_HandleTypeDef structure to carry your own information/extension
2025-01-27 01:40 PM - edited 2025-01-27 01:40 PM
Nothing like that exists in HAL. The pUserData field exists in the USB library, but despite the name it isn't a field the user can modify arbitrarily.
ChatGPT (and analogs) is set up to deliver convincing answers. It is not designed to deliver correct answers. With niche subjects like STM32, it is only good for very generic questions and even then still needs verified manually.
2025-01-28 12:21 AM
(...) You could also modify the UART_HandleTypeDef structure to carry your own information/extension (...)
Yes, this solution was also provided by both AI, but I would prefer not to modify anything in HAL files.
2025-01-28 12:43 AM - edited 2025-01-28 02:12 AM
@dimercur wrote:pUserData is a field provided by any handler (like UART_HandleTypeDef) ?
You (or your AI) seem to be confusing a handler and a handle.
PS:
UART_HandleTypeDef defines a handle (a data structure) - not a handler.
2025-01-28 01:51 AM
Hello @dimercur
Are you referring to a handle or a handler?
If you mean a handle, could you please specify which handle you are referring to? For example, I2C_HandleTypeDef.
2025-01-28 02:17 AM
Ok, sorry, my bad.
I am dealing with handle, like one created out of UART_HandleTypeDef. So, is there any version of HAL where such data structure defines a pUserData field ?
Thank you
2025-01-28 02:19 AM
@dimercur wrote:(...) You could also modify the UART_HandleTypeDef structure to carry your own information/extension (...)
Yes, this solution was also provided by both AI, but I would prefer not to modify anything in HAL files.
The handles are just global data - so you could provide your own, separate, global* structure for it ...
* Or whatever scope works for you.
2025-01-28 02:46 AM - edited 2025-01-28 02:47 AM
Hello @dimercur
Why you don't use the pTxBuffPtr and pRxBuffPtr?
2025-01-28 03:49 AM