在使用调试串口的发送和接收功能的时候:参考例程
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); Serial pc(USBTX, USBRX); void callback_ex() { // Note: you need to actually read from the serial to clear the RX interrupt printf("%c\n", pc.getc()); led2 = !led2; } int main() { pc.attach(&callback_ex); while (1) { led1 = !led1; wait(0.5); } }在仅仅导入mbed库的时候可以正常运行,输入字符并回传。由于希望尝试在程序中使用线程,因此添加mbed-rtos库。编译以后提示下面信息:Warning: #warning directive: toolchain.h has been replaced by mbed_toolchain.h, please update to mbed_toolchain.h [since mbed-os-5.3] in "extras/mbed_675da3299148/platform/toolchain.h", Line: 23, Col: 3在不改动之前的代码的情况下,系统无法进入接收中断,并导致LED停止闪烁。希望上面问题可以得到解决。希望可以给出在串口功能实现过程中,需要注意的事项,谢谢大家!
mbed-os本身應該已經含rtos了,直接用就好。 https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/tasks/rtos/可能要看一下,我記得Nucleo上只有一個LED,而led1和led2有可能是指向同一個ping.