analysis how printf rp2040 work under low level stuff
in order to know how printf works in rp2040 uart bridge, lets compile simple program, compile as debug, then run GDB
consider this very simple hello world
#include <pico/printf.h>
#include <pico/time.h>
int main() {
int n = 0;
stdio_init_all();
while (true) {
printf("Hello, world! %d\n", n);
sleep_ms(1000);
n = n + 1;
}
}
analysis
see?
=> 0x100002b4 <+12>: bl 0x10003a64 <__wrap_printf>
its call __wrap_printf
which mean, the backend call -Wl,--wrap=printf
internally, but if we reffer to /home/fadhil_riyanto/git_clone/pico-sdk/src/rp2_common/pico_stdio/stdio.c:347
the signature is different, this function has signature
int __printflike(1, 0) PRIMARY_STDIO_FUNC(printf)(const char* format, ...)
so, what exactly happen?
result
lets look at stdio.c line 289
when the macro PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS
is active, we replace the function name by WRAPPER_FUNC(x)
, not stdio_printf
after that, lets jump into https://github.com/raspberrypi/pico-sdk/blob/9a4113fbbae65ee82d8cd6537963bc3d3b14bcca/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h#L185, very clear definition
so, basically. this function
call __wrap_printf
make sense?