9 years, 3 months ago.

mbed RTOS not exported correctly to KDS?

I have an mbed-rtos project for the K22F board that works fine when I compile from mbed.org and download. I exported it and compiled it locally using Kinetis Design Studio (KDS). It appears that Thread::wait() and the thread utilities are not working at all. My main loop with a 1000 msec delay is basically blasting data at 9600 baud as fast as it can.

Does anyone know if mbed rtos for Kinetis is fundamentally broken and I should restart using something different?

Thank you for any assistance!

If you post a link to the published program that exhibits this problem it will be easier to track down root cause.

posted by Sam Grove 29 Dec 2014

I did confirm that wait(1.0) works, while Thread::wait(1000) does not. :(

posted by Thor Hall 29 Dec 2014

Can you publish a program and link to it? If people are going to help you it'd be nice to give them a chance to start from the same program that you are

posted by Sam Grove 30 Dec 2014

As there are proprietary design elements in the code, I can't quite post what I have. I might be able to come up with a paired down version. However, all one needs to do is try Thread::wait() compiled in KDS and you should see the same behavior.

posted by Thor Hall 30 Dec 2014

I have demonstrated the issue in a simpler file. In this app the Thread::wait() call results in a hard fault handler call, while in the original is simply returned immediately

Example

#include "mbed.h"
#include "rtos.h"

//Map the LED outputs to the tri-color LED
DigitalOut redLed(LED1);
DigitalOut greenLed(LED2);
DigitalOut blueLed(LED3);

//Could be logic low or logic high
#define LED_ON   0
#define LED_OFF  1

//LED wait
void led_wait(void)
{
	//Works
	wait(1.0);

    //------ VVVV LOOK HERE VVVV -------
	//Returns immediately in another app
	//In this app, throws hard fault handler
	//Thread::wait(1000);
    //------ ^^^^ LOOK HERE ^^^^ -------
}

int main()
{
    redLed = LED_OFF;
    greenLed = LED_OFF;
    blueLed = LED_OFF;
    
    while(1)
    {
        redLed = LED_ON;
        led_wait();
        redLed = LED_OFF;
        led_wait();
        greenLed = LED_ON;
        led_wait();
        greenLed = LED_OFF;
        led_wait();
        blueLed = LED_ON;
        led_wait();
        blueLed = LED_OFF;
        led_wait();
    }
}
posted by Thor Hall 30 Dec 2014

Went back and discovered that somehow the build must not have included all of the right mbed-rtos libraries, though I should think the linker should have errored out. When I corrected that, the thread call simply returns immediately like it did in the original application. :(

posted by Thor Hall 30 Dec 2014

More status - I followed the call to Thread::wait() using KDS and it appears that the rtos thinks the call is being made from an interrupt routine, which it certainly is not. This same code works from the mbed compiler, so it looks like some housekeeping chores are not being handled correctly when everything is exported.

posted by Thor Hall 30 Dec 2014

Please publish a program to your account and share the link. There are dependencies, mbed, mbed-rtos and many versions of each. That is the best way to get help in the shortest time frame.

http://developer.mbed.org/handbook/Publishing-code

BTW - from your example above the RTOS doesn't appear to be used (ie no threads or RTOS components started) so I wouldnt expect Thread::wait to work.

void led_wait(void)

If it was a Thread then you would use Thread::wait

posted by Sam Grove 31 Dec 2014
Be the first to answer this question.