ESP32 Arduino not working if Serial.print() is not called

Good morning to all, I’m new on this community as i’m beginning to develop with ESP32 and Arduino framework under platformio.
The issue i’m facing is that my software works properly only if i call at least once Serial.print(“something”) in the only function called in the loop as showed in the pseudo-code below.
In case the Serial.print is not called inside MyFunction() it will not run: i checked turning on and off a led.
I do not need the Serial.print, do you have any explaination for this behavior ?

void setup() {

void loop() {

void MyFunction(void)
    static uint8_t counter = 0;
          if(counter = 0)


Thanks for the support in advance.

You mean to do a comparison here don’t you?

Sorry, It was only a typo error during the copy.
Anyway i understood the mistake, the Serial.print() has nothing to do with my issue.
My mistake was in adding an infinite cycle inside the loop function: in my infinite loop i was not properly initializing my variables.