8 years, 9 months ago.

Serial Interrupt F401RE via USB UART

I have also a Problem with the serial IRQ Board is connected to PC via USB / Virtual Comport. printf is working well.

After typing in a char in the Terminalprogramm the System hangs. The Project i exported to yVision5. While debugging the Code reaches the IRQ Routine, but hangs on pc.getc();

#include "mbed.h"
#include "SWO.h"

DigitalOut myled(LED1);
int i;

// UART
Serial pc(USBTX, USBRX);
volatile int rx_in=0;
volatile char Incomming_Char;
volatile bool ETX=false;
volatile char rx_buffer[25];
void Rx_interrupt();

SWO_Channel SWO;


  
int main() {

    pc.printf("Startingmessage SWO\r\n");
    pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
    pc.printf("PCLK1 is %d Hz\r\n", HAL_RCC_GetPCLK1Freq());
    pc.printf("PCLK2 is %d Hz\r\n", HAL_RCC_GetPCLK2Freq());
 
    pc.printf("RCC_CFGR is 0x%08X\r\n", RCC->CFGR);
    RCC->CFGR &= ~0x0000E000;  // PPRE2, Bit 15-13
    RCC->CFGR |=  0x00008000;  // PPRE2: PCLK2 = AHB / 2
    pc.printf("RCC_CFGR is 0x%08X\r\n", RCC->CFGR);
 
    pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
    pc.printf("PCLK1 is %d Hz\r\n", HAL_RCC_GetPCLK1Freq());
    pc.printf("PCLK2 is %d Hz\r\n", HAL_RCC_GetPCLK2Freq());

    //serial Interrupt
    pc.baud(9600);
    pc.attach(&Rx_interrupt, Serial::RxIrq);
 
  
      
    while(1) {
        i+=1;
        myled = !myled;
        wait(1);
      
        pc.printf("Mainloop...");
        if (ETX==true){
           pc.printf("ETX..."); 
          // pc.printf(&rx_buffer);
           rx_in=0;
          ETX=false;
          
        }
    }
}







void Rx_interrupt() {
  Incomming_Char = pc.getc();
       
  if (Incomming_Char != 10) {
    rx_buffer[rx_in] = Incomming_Char;
    rx_in++;
  }
  else {
    ETX = true;
  }
}
Be the first to answer this question.