This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

stm32 nucleo F401 官方例程print,wait() 函数死掉。

#include "mbed.h"

//------------------------------------

// Hyperterminal configuration

// 9600 bauds, 8-bit data, no parity

//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1);

int main() {

  int i = 1;

  pc.printf("Hello World !\n");

  while(1) {

     wait_ms(200);    改为这个函数可以正常运行。但是使用

wait(1);  程序就死在这里面。

      pc.printf("This program runs since %d seconds.\n", i++);

      myled = !myled;

  }

}

Parents
  • liliba wrote:

         wait_ms(200);    改为这个函数可以正常运行。但是使用

    wait(1);  程序就死在这里面。

    This seem to be a known issue for STM32F401 and STM32F411:

    ST Nucleo 411RE wait() issue in offline export · Issue #955

    -It is probably related to the timer's counter wrapping each second; which means it would never reach a full second.

    Here's how to fix it: First steps with my Nucleo-F401RE

    Quote:

    I found the function “wait(float sec)” seems to be broken or at least buggy, because no further messages are printed. Therefore, I replaced “wait(1)” by “wait_ms(1000)”, which seems to work as expected.

    UPDATE:

    Fix: you need to update the mbed library in the online compiler. I first hat rev 78 and after updating to the latest rev (rev 83) the wait function works as expected (http://mbed.org/forum/platform-34-ST-Nucleo-F401RE-community/post/24351/)

    Note: You might want to add this right after Serial pc( ... ); ...

        pc.baud(9600);

    ... or ...

        pc.baud(115200);

    ... so you can be sure the baud rate is what you expect it to be.

Reply
  • liliba wrote:

         wait_ms(200);    改为这个函数可以正常运行。但是使用

    wait(1);  程序就死在这里面。

    This seem to be a known issue for STM32F401 and STM32F411:

    ST Nucleo 411RE wait() issue in offline export · Issue #955

    -It is probably related to the timer's counter wrapping each second; which means it would never reach a full second.

    Here's how to fix it: First steps with my Nucleo-F401RE

    Quote:

    I found the function “wait(float sec)” seems to be broken or at least buggy, because no further messages are printed. Therefore, I replaced “wait(1)” by “wait_ms(1000)”, which seems to work as expected.

    UPDATE:

    Fix: you need to update the mbed library in the online compiler. I first hat rev 78 and after updating to the latest rev (rev 83) the wait function works as expected (http://mbed.org/forum/platform-34-ST-Nucleo-F401RE-community/post/24351/)

    Note: You might want to add this right after Serial pc( ... ); ...

        pc.baud(9600);

    ... or ...

        pc.baud(115200);

    ... so you can be sure the baud rate is what you expect it to be.

Children