#include "mbed.h" #include "rtos.h" DigitalIn mybutton(USER_BUTTON); DigitalOut myled(LED1); Serial pc(SERIAL_TX, SERIAL_RX); Serial device(PA_0, PA_1); Mutex serial_mutex; void Thread1(void const *argument) { int i = 1; while(true) { Thread::wait(1000); serial_mutex.lock(); pc.printf("This program runs since %d seconds.\n", i++); fflush(stdout); serial_mutex.unlock(); } } void Thread2(void const *argument) { int x = 1; while(true) { Thread::wait(1000); serial_mutex.lock(); device.printf("This program runs since %d seconds.\n", x++); fflush(stdout); serial_mutex.unlock(); } } void Thread3(void const *argument) { while(true) { if(mybutton == 0) { printf("Thread3 printf\n"); Thread::wait(1000); } } } void SetupSerial() { device.baud(9600); device.format(8,SerialBase::None,1); pc.baud(9600); pc.format(8,SerialBase::None,1); } int main() { SetupSerial(); Thread thread_1(Thread1, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); Thread thread_2(Thread2, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); Thread thread_3(Thread3, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); while (true) { Thread::wait(500); myled = !myled; } }