2018-11-08 12:52 AM
I want use two or more buffers with IO functions. One way I could imagine was if I use two different callbacks. I would call HAL_UART_Receive_IT using buffer A which calls HAL_UART_RxCpltCallback A which calls HAL_UART_Receive_IT using buffer B which calls HAL_UART_RxCpltCallback B which calls A and so on.
2018-11-08 04:21 AM
Just make a global buffers.
be careful not to adjust them in different threads.
"IO conditions" write buffers and set Flags in interrupts (or Polled)
a state machine process would check Flags and then check/process the buffer entries
The trick is:
only read or write a buffer from a thread.
The interrupt will write to the buffer and set a flag,
then the foreground state machine can check the flag and read/process the buffer
easy as.
2018-11-08 04:59 AM
Yes, flags are probably the easiest way of doing it, unless ST or some one else show an other way. I have worked with callbacks recently so that was my first idea.
2018-11-08 05:07 AM
A callback is related to the interrupt. one interrupt, one callback. as suggested, do the differenciation in the callback. Like the Linux top-half/bottom-half approach.
2018-11-08 06:32 AM
The form used here is clumsy. You could use different handles/objects, or you could extend/overload the structure you pass so it has your own buffers, data pointers and function pointer.
ie you wrap/encapsulate the UART_HandleTypeDef structure inside one of your own, and then pass that
2018-11-09 04:18 AM
Thank you for your ideas and suggestions. I looked at my code and what I'm trying to do with it and I think that the best way now is to change code in both ends of the UART and send data only when the receiver wants it. That makes buffering easier.