Rak3172 Evo module with host Mcu

Hi ,
I am working on p2p with Rak3172-E modules. I am trying to transmit the data coming from the host MCU to the module on the opposite side with Rak3172-E and read the data coming from the host MCU there. This is my general purpose, but I have some problems, I thought maybe friends who have experienced this problem before can help.

I tested the Ardunio.serial example without making any changes in the setup and it worked. It took the data I entered through any serial program and printed it on the serial screen. However, in the same code, when I deleted the places I marked in yellow in the setup and tried to load the code, I got the message "Detecting baudrate…
I get the error “Detect baudrate fail, can’t get the baudrate” and to upload the code again, I first upload the .hex file with the stm32 programmer and then I can upload the new code again.

I get the same errors when I load a code like the one below. Is there something I missed? By the way, I use usart1 pins with the host mcu.

#define BUFFER_SIZE 128

char buffer[BUFFER_SIZE];
int bufferIndex = 0;

void setup() {

Serial1.begin(115200); 
Serial.begin(115200); 

}

void loop() {

while (Serial1.available() > 0) {
Serial.println("UART Veri Alimi Basladi");
    char receivedChar = Serial1.read(); 
    
    if (bufferIndex < BUFFER_SIZE - 1) { 
        buffer[bufferIndex++] = receivedChar; 
        buffer[bufferIndex] = '\0';
    } else {
        Serial.println("Tampon dolu, veri kaybedildi!"); 
        bufferIndex = 0; 
    }
    
    if (receivedChar == '\r') { 
        Serial.println("Gelen Veri: "); 
        Serial.println(buffer);
        bufferIndex = 0; // 
    }
}

}

Welcome to the forum @mbtas

For the first part, I am guessing that removing the setup of the Serial timeouts have something to do with it.

In the loop the code returnString = Serial1.readStringUntil('\r'); might be blocking forever until you actually receive a \r. The timeout set with Serial1.setTimeout(5000); would let this code stop reading from Serial1 after 5 seconds. Then the ArduinoIDE can jump in and start uploading the new code.

For the second part, it could be similar. Did you try to put a delay(20) into the while loop?

Hello @mbtas

Instead of UART1, use UART2 please.
Firmware update is only possible over UART2. UART1 can be only used for AT commands.

RAK3172 Documentation