Using QEI library with printf problem

Hello,
Im using Mbed studio OS 6 with Nucleo F303K8 MCU
I have a gear motor with encoder, im using the QEI library with x2 encoding.
I want to count the number of pulses the motor does. I use the getpulses function in QEI library.
I have noticed when i combine a printf inside the code, the counting doesnt rising or rising very slowly.

another thing, when i disconnect the encoder its looks like the counter is rising again as it suppose to be.
This things doesnt happend when im not using printf function.

#include "mbed.h"
#include "Motor.h" 
#include "QEI.h"
QEI wheel(PA_6, PA_2, NC, 1900);
Motor Wheel(PA_7, PA_5); // Make the motor object

int counter = 0;
int main() {
    Wheel.speed(0.5);
    while(1){
        thread_sleep_for(100);
        counter = wheel.getPulses();
        printf("Number of Pulses%d\r\n",counter);
        


    }
}

In the QEI library using interup in on the digital input of the encoder. any time a pulse coming the counter suppose to rise.
but when using printf it doesnt.
If its important i add to mbed_app.json the code lines that allow you using printf in MBED OS 6.

            "platform.stdio-baud-rate": 115200,
            "platform.stdio-buffered-serial": 1

Thank you
Noam

Hello Noam,

By default in Mbed on STM targets the PA_2 pin is configured as UART2_TX which is used for global printf (aka CONSOLE or stdout) output. This is indicated also in the board pinout (PA_2 has a dark blue background and according to the legend such pins are connected to other components). You can check it also in the PeripheralPins.c file (a link is provided on the board’s home page just below the “Pins Legend”.

However, you use the same pin in your program for the QEI too:

QEI wheel(PA_6, PA_2, NC, 1900);

Try to use a different pin either for the QEI or for the CONSOLE (stdout) printf. The former option is more advantageous because you can keep using the USB cable for the printf output to the PC.

Hello Zoltan,
It worked.
Thank you