MBed OS info RP2040 connect

Hi,

i found that arduino RP2040 connect boards uses Mbed os in the background when you download a sketch .

I need this board with dual core capabilities . I want to use arduino IDE also because i have a lot of libraries on hand.

I have some questions :

1.MBED os documentation is fully compatible with MBED os arduino port ?

2.To use it i just have to import mbed.h ?

3.Can both API be used on the same time ? Arduino API and MBED API?

4.Why you preistal this os ? Can i select another one for example FREE RTOS ?

Thank you,

I am a beginner using RTOS systems...

In general, boards with some form of networking stack use an RTOS to deal the the asynchronicity of networking. Arduino picked MBED.
Theoretically you can use some other OS, but it's likely to be "fussy."

If you use the Earl Philhower core for RP2040 Connect, I believe you'd start out with no RTOS (although, I'm not sure what it does for networking on boards with WiFi.)

(Note that the rp2040 Connect's WiFi module is a whole separate ESP32, which I believe uses FreeRTOS to run IT'S network stack, so I'm not really clear on why MBED is also involved.)

Hi @luci_codreanu.

For the most part. Arduino has applied some patches to Mbed OS:

They are mostly adding new targets for the Arduino boards. They would generally avoid making any changes to the Mbed OS API, and so don't affect the applicability of the documentation.

This, and add the mbed:: scoping operator to references to objects in the global Mbed OS namespace.

Here is an example of how you can use the Mbed OS API in an Arduino sketch to blink the built-in LED on the Nano RP2040 Connect board:

#include <mbed.h>
// See: https://os.mbed.com/docs/mbed-os/latest/apis/digitalout.html
// GPIO to Mbed OS pin names mapping here:
// https://github.com/arduino/mbed-os/blob/extrapatches-6.17.0/targets/TARGET_RASPBERRYPI/TARGET_RP2040/TARGET_NANO_RP2040_CONNECT/PinNames.h
mbed::DigitalOut myled(LED1);

void setup() {}

void loop() {
  // See: https://os.mbed.com/docs/mbed-os/latest/mbed-os-api-doxy/classmbed_1_1_digital_out.html#a25d1931bc29d014446294ab8dc470f2a
  myled.write(1);
  // See: https://os.mbed.com/docs/mbed-os/latest/mbed-os-api-doxy/namespacertos_1_1_this_thread.html#a770153ce44f174497a5c526e81b8fbb5
  rtos::ThisThread::sleep_for(1000);
  myled.write(0);
  rtos::ThisThread::sleep_for(1000);
}

Yes:

#include <mbed.h>
mbed::DigitalOut myled(LED1);

void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // Wait for serial port to be opened.
  delay(750);         // Give Serial Monitor some time to initialize.
  Serial.println("Enter the pin state to set the built-in LED (0/1).");
}

void loop() {
  if (Serial.available()) {
    char state = Serial.read();
    rtos::ThisThread::sleep_for(100);  // Allow the full message to arrive.
    while (Serial.available()) {
      Serial.read();  // Clear the receive buffer.
    }
    Serial.print("Setting pin to state ");
    Serial.println(state);

    switch (state) {
      case '0':
        {
          myled.write(0);
          break;
        }
      case '1':
        {
          myled.write(1);
          break;
        }
      default:
        {
          Serial.println("error: State is not valid");
        }
    }
  }
}

However, you do need to keep in mind that there can be conflicts between resources used by different parts of your code. That is even the case when you are only using the Arduino API and libraries though.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.