Mbed uart read crash

Hi forum,
Im trying to develop an embeded code with mbed. I want to use the serial port to send and receice string. I have no probleme sending via uart but when it comes to receiving i cant do it. First what happen is i use an arduino serial.write function to send a continue hello world string in order to test. when i connect the arduino to the chip max32630fthr it reset in loop and i cant read the string. I use the Serial Uart(tx,rx) where tx is P3_1 and rx is P3_0. I use the attach function. for exemple my code is something like this simplified.

volatile char c = ‘\0’;
void charReceive(void){
c = Uart.getc();
}

int main(){
Uart.baud(9600);
Uart.attach(&charReceive);
while(1){
debug.printf(“%c”, c);
}
}

what happen is the code run no probleme its when i plug the uart that everything just crash.

Hello,

what matters is what version of MbedOs you use and what serial API you use and also the content of Mbed crash report.

For UART with interrupts are recommended these APIS

BR, Jan

Even with RawSerial there is a crash which alway occurs into the interrupt initialization. I dont know how to get a crash report

The report is printed to default STDIO console, usually via VCP provided by ST-link/Daplink.

BR, Jan

Only print i see is from the main debug, so i see it reset i loop.

Well, ive found the source of the crash not its now crashing anymore but i still cant receive any uart data. any idea? im still using the same code as in the first post

Check for another COM port provided by your DAP-link. Mbed OS debug console where are crash reports printed is on UART1 -current settings.

Can you share? For another one who will need to solve something similar.

  • variable c should be int instead of char
  • printf is slow function and this use case is not optimal , you can lose chars eazy
  • printf do not like unfinished strings - like here

You can try it without printf

void charReceive(void){
    debug.putc(Uart.getc());
}

or

#include "mbed.h"

RawSerial Uart(USBTX,USBRX);
char buffer[20];
int counter = 0;
volatile bool flag = false;

void charReceive(void){
    if(!flag){
        int c;
        do{
            c = Uart.getc();
            buffer[counter++] = c;
        }while(c != '\n');
        flag = true;
        buffer[counter] = '\0';
        counter = 0;
    }
}

int main(){
    printf("Test\n");
    Uart.baud(9600);
    Uart.attach(&charReceive);
    while(1){
        if(flag){
            printf("Output: %s\n", buffer);
            flag = false;
        }   
    } 
}

BR, Jan

I actually already use the uart1 for the standard debug print, but there is not any more print somewhere for crash report. i use another uart port, uart2 for my project.

For the crash, i just commented some intterupt initialisation of the max30001 chip but i havent yet investigated further.

I still cant receive any uart data from my first code and with your code. I just tried to do the simple blocking code
while(1){
debug.putc(uart.getc());}
what happened is when i connect the uart form the arduino to the max32630fthr, i get 1 or 2 character and then nothing after. if i unplug the uart it crashed and reset.

thats what i get so far, the led which is supposed to be ON, start blinking when uart is connected which i guess is not normal.

When you use it in loop it is good to do it like this

while(1){
   if(uart.readable()) debug.putc(uart.getc());
}

I do not know what impact have the MI’s library but do you have it in your project?
max32630fthr - Board library for MAX32630FTHR platform | Mbed

Then MI examples usually start like this

#include "mbed.h"
#include "max32630fthr.h"
 
MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);

Without this is your board in default 1v8, I think.

And I do not know what Arduino board you use, but Arduino UNO is 5V logic but MAX32630FTHR not and I do not know if is 5V tolerant.

BR, Jan

You were absolutely right about the arduino outputting 5v and the max taking 3.3v. i used a voltage divider and now its working well!! thank you very much!