Skip to main content
LMI2
Senior III
November 8, 2018
Question

Can I have two different callbacks? (to use two buffers)

  • November 8, 2018
  • 5 replies
  • 769 views

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.

    This topic has been closed for replies.

    5 replies

    T J
    Senior III
    November 8, 2018

    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.

    LMI2
    LMI2Author
    Senior III
    November 8, 2018

    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.

    AvaTar
    Senior III
    November 8, 2018

    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.

    Tesla DeLorean
    Guru
    November 8, 2018

    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

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    LMI2
    LMI2Author
    Senior III
    November 9, 2018

    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.