ESP_igrr wrote: ↑Sun Feb 16, 2020 10:27 pm
To redirect stdout, you can simply reassign stdout to a new FILE* stream. An example of this can be found in
https://esp32.com/viewtopic.php?f=13&t= ... 141#p55141. (The specific example redirects to app_trace, in your case it will be something different).
If only writing is required, you can use 'fwopen' to create such a stream, and all writes will be redirected to your provided function. Be sure to call this before other tasks are created, as new tasks inherit stdin/stdout/stderr streams.
Take note that you need to prevent your write handler from re-entering. For example, if you call something from your write handler, and that function tries to log (e.g. an error), this will result in your write handler re-entering. You need to detect that and return in such a case.
Thanks for the pointer
I tried this but seem to have run into an issue which I am unable to resolve.
Even with the simplest callback function I get a panic()
First test is simply to print the stdout, onto stderr
Code: Select all
static int app_printf(void *cookie, const char *data, int size) {
fprintf(stderr, "app_printf: %.*s", size, data);
return size;
}
in my initialization code
Code: Select all
stdout_buf = (char *)malloc(128);
fclose(stdout);
stdout = fwopen(NULL, &app_printf);
setvbuf(stdout, stdout_buf, _IOLBF, 128);
fprintf(stderr, "fwopen ret=%p\n", stdout);
but I get the following
***ERROR*** A stack overflow in task sys_evt has been detected.
abort() was called at PC 0x4009086c on core 0
0x4009086c: vApplicationStackOverflowHook at /home/moore/esp/esp-idf/components/esp32/panic.c:125
ELF file SHA256: 84fc86d812c9e768f1075fd7734acef62ed828743fb98f00d100fb1289c4b02c
Backtrace: 0x4009051d:0x3ffdf6a0 0x40090855:0x3ffdf6c0 0x4009086c:0x3ffdf6e0 0x4009433d:0x3ffdf700 0x40092e10:0x3ffdf720 0x40092dc6:0x00000000 |<-CORRUPTED
0x4009051d: invoke_abort at /home/moore/esp/esp-idf/components/esp32/panic.c:157
0x40090855: abort at /home/moore/esp/esp-idf/components/esp32/panic.c:174
0x4009086c: vApplicationStackOverflowHook at /home/moore/esp/esp-idf/components/esp32/panic.c:125
0x4009433d: vTaskSwitchContext at /home/moore/esp/esp-idf/components/freertos/tasks.c:2770
0x40092e10: _frxt_dispatch at /home/moore/esp/esp-idf/components/freertos/xtensa/portasm.S:431
0x40092dc6: _frxt_int_exit at /home/moore/esp/esp-idf/components/freertos/xtensa/portasm.S:231
Am I supposed to wrap this function with any entry exit calls ?
Thx
Lee