5 years, 3 months ago.

Correct usage of event_callback_t (attach method is deprecated?)


I am implementing a firmware on a STM32F303RE, and I am using the Serial.write method.

Here is a short version what I have:

Short example

#include "mbed.h"

Serial serialPort(USBTX, USBRX, 115200);

event_callback_t serialCallback;

void onSerialTxComplete(int event)
   // Do something

void receiveBytes()
  unsigned char byte = serialPort.getc();
  // Processes the data

int main()
  unsigned char buffer[64];
    serialPort.write((const unsigned char *)buffer, 64, serialCallback, SERIAL_EVENT_TX_COMPLETE);

Now, it does compile, but it also tells me that this implementation is deprecated:

Warning: Function "mbed::Callback<R (A0)>::attach(R (*)(A0)) [with R=void, A0=int]" (declared at line 918 of "/extras/mbed/platform/Callback.h") was declared "deprecated" in "main.cpp"

Anyone knows how the callbacks should be implemented now?

Thank you

1 Answer

5 years, 3 months ago.

Hi, if I got the line correct, the warning should also print what you can use instead. In this case, it would be to use assignment:

Callback cb = function;