7 years, 6 months ago.

mbed 5.2 example code in Handbook

mbed has changed it's API some time ago, but example codes still use now deprecated functions.

https://docs.mbed.com/docs/mbed-os-api-reference/en/5.2/APIs/tasks/rtos/

Especially in Thread, Ticker, Timeout but maybe also in other classes which implement an attach style of member function, there are examples using old-style usage of these classes. Also in Thread is no member function explanation of .start(callback(obj, method)) which would be necessary creating a Thread with the newer constructor.

Is there somewhere a place for the newer examples and I'm just looking at the wrong place?

2 Answers

7 years, 5 months ago.

I also have just had the exact same problem, is it thread.start() is it Thread t(); t.start(obj). The documentation is all over the shop. My threads are not starting, I can find 3 different examples of how to use threading

Example 1

  1. include "mbed.h"
  2. include "rtos.h"

DigitalOut led1(LED1); DigitalOut led2(LED2);

void led2_thread(void const *args) { while (true) { led2 = !led2; Thread::wait(1000); } }

int main() { Thread thread(led2_thread);

while (true) { led1 = !led1; Thread::wait(500); } }

Example 2:

Blink function toggles the led in a long running loop void blink(void) { while (running) { led1 = 0; Thread::wait(1000); led1 = 1; Thread::wait(1000); } }

int main() { running = true; thread.start(blink); }

Example 3 void some_function(int i);

int main(void) { int a = 2;

Thread t1(); t1.start(some_function, a); this won't work }

None are working for me. I appreciate that this is a technology preview but it appears to be chopping and changing so much the documentation is out of date making me less inclined to use mbeds.

7 years, 5 months ago.

The #include "rtos.h" statement clearly indicates that Example 1 is incorrect. In mbed 2 the rtos functionality was defined in a separate header file rtos.h. In mbed 5 the rtos functionality definitions were integrated into the mbed.h file and the rtos.h file is no longer used. When attempting to use mbed 5.2 one also need to make sure the mbed library included in the project is mbed-os and not mbed. The mbed library implements the old mbed 2 functionality. As of 11/23/2016 the online ide's library import wizard will not find the mbed-os library; however it can be added to an online ide project by using the import via URL option with the following url https://github.com/ARMmbed/mbed-os/. Also portions of the rtos functionality were broken in the 5.1.X releases of the mbed library; therefore one needs to ensure they are using the 5.2.0 or later release of the mbed-os library.

Hi steve , I have a little confusion over how does thread works ....

my program is here:-

  1. include "mbed.h"
  2. include "rtos.h"
  3. include "C12832.h"

C12832 lcd(p5, p7, p6, p8, p11);

void lcd_thread(void const *args) { while(true) { lcd.cls(); lcd.locate(0,0); lcd.printf("Welcome to USA"); Thread::wait(1000);

} }

int main() { Thread thread(lcd_thread); while(true) { lcd.locate(0,20); lcd.printf("Hello"); Thread::wait(1000); } }

when i am running this i am getting absurd kind of out put in the LCD attached in my MBED KIT

Kindly help ...

posted by Venkatesh Dixit 01 Oct 2017