10 years, 5 months ago.

Please help, mbed-rtos doesn't work when it compiled with codesourcery

Hi!

I built this rtos-basic example from mbed-official with Sourcery CodeBench Lite 2013.11-24.

rtos-basic example

#include "mbed.h"
#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);
    }
}

Unfortunately, the app gets stuck when I run it on my LPC1768. This app work fine when it's built with online mbed toolchain. By adding LED indication I found out, that problem occure when I try to create the Thread object. It looks like that mbed-rtos lib doesn't work with Codesourcery (I also tried Sourcery G++ Lite 2011.03-42 - the same issue). or I should do something else to make it work?

Do you have any chance to debug it what goes wrong there?

posted by Martin Kojtal 06 Jun 2014

No, unfortunately I don't

posted by Aida Mynzhasova 10 Jun 2014

2 Answers

9 years, 9 months ago.

There's an issue on github. The nrf51 does not have SysTick which is the timer used by RTX. Look at https://github.com/mbedmicro/mbed/issues/902

9 years, 10 months ago.

I've quite the same problem with GNU toolchain. Compiling it online works, but trying to compile offline with GNU toolchain make the CPU hangs even before the main(). Even a simple blinking led without RTOS thread was hanging as soon as the RTOS is linked with the project. Removing it from linkage make the led blinking again ...

I've done more investigations, I discovered something really interesting : First, let says that when I saw Aida's post, it brings me doubts. So, I then compile the rtos_basic example from mbed-online, it was working fine. So, I decided to re-export it to GNU toolchain, keeping my old one aside, unzipping the newest and compile, it was working fine too. OhOhOh, surprise ! Re-compiling the old one done few days ago, still hangs ! I then decided to diff between both ... Surprise, the Makefile is different in few places. Trying to figure out things, I discovered that the culprit is the linkage order of the OBJECTS (although SYS_OBJECTS order was also different, this one doesn't matter). I didn't narrowed the exact order, but here are the diffs :

BAD ORDER : OBJECTS = ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/HAL_CM3.o ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/SVC_Table.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Task.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_MemBox.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Robin.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mailbox.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_System.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Event.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Semaphore.o ./mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Time.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mutex.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_List.o ./mbed-rtos/rtx/TARGET_CORTEX_M/HAL_CM.o ./main.o ./mbed-rtos/rtos/RtosTimer.o ./mbed-rtos/rtos/Thread.o ./mbed-rtos/rtos/Mutex.o ./mbed-rtos/rtos/Semaphore.o

GOOD ORDER : OBJECTS = ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/SVC_Table.o ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/HAL_CM3.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Semaphore.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Event.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_List.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mutex.o ./mbed-rtos/rtx/TARGET_CORTEX_M/HAL_CM.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Task.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_System.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Time.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_MemBox.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Robin.o ./mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mailbox.o ./main.o ./mbed-rtos/rtos/Thread.o ./mbed-rtos/rtos/Semaphore.o ./mbed-rtos/rtos/Mutex.o ./mbed-rtos/rtos/RtosTimer.o

What I'm suspecting in the whole story, is probably that the first time I've imported the rtos_basic exemple, I've re-exported it for GNU toolchain without compiling it first. That can explain the order differences, although to prove it, we need to redo the exercise from scratch, which I'm tooo lazy to do, since I've other issue to trackdown.

posted by Martin Ayotte 29 Dec 2014

This may be related to https://github.com/mbedmicro/mbed/pull/812

posted by Adam Green 30 Dec 2014