Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Why does printf work in the while loop, but not before on a raspberry pi pico?

$
0
0

I have installed the C/C++ SDK for the Raspberry PI Pico on a Raspberry pi 4. Then I have compiled and executed the hello world example via USB successfully. I monitor the output using minicom and so far everything works fine.

However, when I add a printf before the while loop, it has no effect.

Here is the SDK Example with my 1 line addition:

#include <stdio.h>#include "pico/stdlib.h"int main() {    stdio_init_all();    printf( "Let's start\n" ); // <-- This is my addition    while (true) {        printf("Hello, world!\n");        sleep_ms(1000);    }    return 0;}

I do see Hello World! in minicom once a second as desired, but no Let's start. What could be the reason and how can I overcome this?

UPDATE: Answers to some questions in the comments:

  • I have also tried to add fflush(stdout); after the first printf. It didn't help
  • Usually, I connect minicom before I start the application. I restart the application several times with or without the debugger and it makes no difference. Minicom does not 'drop' between restarts. It seems the connection to the USB port is stable whatever I do. It shows the "hello world" part even if I launch minicom after the application on the pico has started
  • Adding a numeric identifier to see if some of the 'hello world' drops: I did this in a more complicated app with timers and various interrupts. They work just fine and they all get called after the while loop starts
  • I have also added a sleep_ms(1000) before the printf. This didn't help either

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>