OS2 scanf no longer works and blocks the program

Using OS2 on Nucleo-F042K6 and scanf no longer works and blocks the program. It did not before.
I cannot use OS5 as the board does not look like its properly supported.

Hello,

Mbed2 is not developed or maintained for years, so I do not believe it is Mbed library issue.
Please be so kind and describe some steps how to reproduce this issue in its simplest form and also your environment (IDE/Toolchain).

BR, Jan

Hi,
I am using Keil Studio Cloud

Created an empty program with:

#include "mbed.h"
#include"Serial.h"
DigitalOut myled(LED1);
Serial pc(USBTX,USBRX);

int main() {
  int i;
  while(1) {
    printf("before scanf");
    scanf("%d", i);
    myled = 1;
    wait(0.2);
    myled = 0;
    wait(0.2);
  }
}

I can see the printf but the LED never lights up…
This code worked few years back in the MBED studio days.

USBRX is defined as PA_15, this maybe wrong. Try Serial pc(PA_2, PA_3);
in the board page overview and in the schematics it is PA_3 for RX, this seems to be wrong for F031 as well.
But if I’m right, then it was wrong in Mbed2 already.

edit:
ok, PA_15 is correct. I got confused with the STLink on board, there it is PA_3. For the target MCU, PA_15 is correct.

Yeah it has to be correct as I can see the printf in teraterm.
Still cant get the scanf to not block the rest of the program

scanf is a blocking function, that is no bug.
It is reading chars until CR.

I do not remember the scanf was non-blocking anytime and also in pre-Mbed Studio time.

You can try also in simulator https://cplusplus.com/reference/cstdio/scanf/

Edit: Yeah, how Jojo wrote, there is a while loop what is waiting for CR.

BR, Jan