Report
2 weeks, 5 days ago.

conflicts between serial ports & Interrupt (or Thread)

  1. include "mbed.h"
  2. include "rtos.h"

the code is designed to initial a thread which blink with delay. And the button will change the delay time. It works well without the serial ports.But once I add the serial Ports and print "helloworld" even in the main function, the interrupt just doesnt work, once i press the button the light just stop blinking and remain the state it was,either on or off.

So my speculate is that the Interrupt just break the thread?

the code is listed below

example for serial ports conflicts

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

InterruptIn mybutton(USER_BUTTON);
DigitalOut led1(LED1);
Serial pc(USBTX,USBRX);    
 
float delay = 1.0; // 1 sec
 
void pressed()
{   
    if (delay == 1.0)
        delay = 0.2; // 200 ms
    else
        delay = 1.0; // 1 sec
}

void blink_thread(void const *args){
    while(1){
    led1 =! led1;
    wait(delay);
    }
 }
 
int main()
{   
    pc.baud(115200);
    printf("helloworldhelloworldhelloworld\n");
    mybutton.fall(&pressed);
    Thread thread(blink_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
    while (1){}
}

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F401RET6 microcontroller.

I have a similar issue on the NUCLEO-F429ZI, I have a ticker interrupt controlling a DAC which worked great until I added a serial port to the code and then the DAC output is just a square wave rather than the audio waveform.

Any fix would be greatly appreciated as my project deadline is Sunday :((((

posted by Harry Willis 09 May 2017

Can you please post the code with proper formatting with <<code>> tags. You can see how to do this with "editing tips" when editing your post.

posted by Sarah Marsh 09 May 2017

You could try putting a wait call inside the main loop, say Thread::wait(1); In os 5, main is a thread, it's probably better to specifically release it to the scheduler.

posted by Graham S. 13 May 2017
Comment on this question
Be the first to answer this question.

To post an answer, please log in.