mbed-rtos didn't work with stm32f407

21 Apr 2015

I tried a simple mbed test ):

a simple mbed test:

#include "mbed.h"

Serial pc(PA_9, PA_10);
 
DigitalOut myled(PF_8);
DigitalOut myled2(PF_7);
 
int main() {
  int i = 1;
  pc.baud(115200);
  pc.printf("Hello World !\n\r");
  while(1) {
      wait(1);
      pc.printf("This program runs since [%d] seconds.\n\r", i++);
      myled = !myled;
      myled2 = !myled2;
  }
}

I download the hello.bin into a stm32f407 board and reboot the board, it's work fine, two leds blink regularly and messages output the serial port.

I tried to build and run a simple mbed-rtos test, it's built successful and runs failed, the leds is turned on but didn't blink at all.

):

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

/*
 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
 */
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
#define STACK_SIZE DEFAULT_STACK_SIZE/4
#else
#define STACK_SIZE DEFAULT_STACK_SIZE
#endif

void print_char(char c = '*')
{
//    printf("%c", c);
//    fflush(stdout);
}

DigitalOut myled(PF_8);
DigitalOut myled2(PF_7);

void led2_thread(void const *argument) {
    while (true) {
        myled = !myled;
        Thread::wait(1000);
        print_char();
    }
}

int main() {
    Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE);

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

Any advice would be appreciated!

07 Jan 2015

I searched the forum and found a related issue ( https://github.com/mbedmicro/mbed/issues/775 ). The difference is, the compiler I'm using is keil 5 ( armcc ), not gcc.

So I rebuild all the mbed , rtos and my test apps with GCC (GNU Tools ARM Embedded 4.8 2014q3), it's turned out working! However, the time delay (Thread::wait()) function is obviously not work rightly. I replaced it with the mbed function wait().

(C:\mbed-master\libraries\tests\rtos\mbed\basic\main.cpp):

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

/*
 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
 */
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
#define STACK_SIZE DEFAULT_STACK_SIZE/4
#else
#define STACK_SIZE DEFAULT_STACK_SIZE
#endif

void print_char(char c = '*')
{
//    printf("%c", c);
//    fflush(stdout);
}

DigitalOut myled(PF_8);
DigitalOut myled2(PF_7);

void led2_thread(void const *argument) {
    while (true) {
        myled = !myled;
        //Thread::wait(1000);
        wait(1);
        print_char();
    }
}

int main() {
    Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE);

    while (true) {
        myled2 = !myled2;
        //Thread::wait(500);
	wait(0.5);
    }
}

In the end, I still got the question: why it didn't work with keil (armcc)??