cpu/esp32: use printf/puts from newlib
Initializing the stdio file descriptors in global reent structure with newlib fake stdio file descriptors led to the problem that newlib stdio functions printf and puts were not working since they can't operate on these fake stdio file descriptors. Therefore, this initialization was removed. Now, the real stdio file descriptors as created automatically by newlib are used. Specific functions `printf`, `puts`, `getchar`and `putchar` are not required any longer and are removed now.
This commit is contained in:
parent
87cd181f56
commit
bf331bd54b
@ -142,11 +142,6 @@ LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp32.rom.ld
|
||||
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp32.rom.nanofmt.ld
|
||||
LINKFLAGS += -nostdlib -lgcc -Wl,-gc-sections
|
||||
|
||||
ifneq (,$(filter stdio_uart,$(USEMODULE)))
|
||||
LINKFLAGS += -Wl,-wrap,putchar
|
||||
LINKFLAGS += -Wl,-wrap,getchar
|
||||
endif
|
||||
|
||||
# The ELFFILE is the base one used for flashing
|
||||
FLASHFILE ?= $(ELFFILE)
|
||||
|
||||
|
||||
@ -35,9 +35,6 @@ extern "C" {
|
||||
/** Necessary initializations of system call functions */
|
||||
void syscalls_init (void);
|
||||
|
||||
/** System standard printf function */
|
||||
int printf(const char* format, ...);
|
||||
|
||||
/** Determine free heap size */
|
||||
unsigned int get_free_heap_size (void);
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
#include "log.h"
|
||||
#include "syscalls.h"
|
||||
|
||||
extern char _printf_buf[PRINTF_BUFSIZ];
|
||||
char _printf_buf[PRINTF_BUFSIZ];
|
||||
bool _new_line = true;
|
||||
|
||||
void log_write(unsigned level, const char *format, ...)
|
||||
|
||||
@ -279,12 +279,6 @@ static NORETURN void IRAM system_init (void)
|
||||
/* Disable the hold flag of all RTC GPIO pins */
|
||||
RTCCNTL.hold_force.val = 0;
|
||||
|
||||
/* initialize newlib data structure */
|
||||
esp_reent_init(_GLOBAL_REENT);
|
||||
_GLOBAL_REENT->_stdin = (FILE*) &__sf_fake_stdin;
|
||||
_GLOBAL_REENT->_stdout = (FILE*) &__sf_fake_stdout;
|
||||
_GLOBAL_REENT->_stderr = (FILE*) &__sf_fake_stderr;
|
||||
|
||||
/* execute constructors */
|
||||
do_global_ctors();
|
||||
|
||||
|
||||
@ -64,61 +64,6 @@
|
||||
|
||||
#define MHZ 1000000UL
|
||||
|
||||
#ifdef MODULE_STDIO_UART
|
||||
#include "stdio_uart.h"
|
||||
|
||||
int IRAM __wrap_putchar(int c)
|
||||
{
|
||||
char tmp = c;
|
||||
if (stdio_write(&tmp, 1) > 0) {
|
||||
return c;
|
||||
}
|
||||
return -EOF;
|
||||
}
|
||||
|
||||
int IRAM __wrap_getchar(void)
|
||||
{
|
||||
char tmp;
|
||||
if (stdio_read(&tmp, 1) > 0) {
|
||||
return tmp;
|
||||
}
|
||||
return -EOF;
|
||||
}
|
||||
#endif /* MODULE_STDIO_UART */
|
||||
|
||||
int IRAM puts(const char *s)
|
||||
{
|
||||
if (!s) {
|
||||
return EOF;
|
||||
}
|
||||
int len = strlen(s);
|
||||
for (int i = 0; i < len; i++) {
|
||||
__wrap_putchar(s[i]);
|
||||
}
|
||||
__wrap_putchar('\n');
|
||||
return len;
|
||||
}
|
||||
|
||||
char _printf_buf[PRINTF_BUFSIZ];
|
||||
|
||||
int IRAM printf(const char* format, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
va_start(arglist, format);
|
||||
|
||||
int ret = vsnprintf(_printf_buf, PRINTF_BUFSIZ, format, arglist);
|
||||
|
||||
if (ret > 0) {
|
||||
for (int i = 0; i < ret; i++) {
|
||||
__wrap_putchar(_printf_buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
va_end(arglist);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef MODULE_PTHREAD
|
||||
|
||||
#define PTHREAD_CANCEL_DISABLE 1
|
||||
|
||||
28
cpu/esp32/vendor/esp-idf/esp_funcs.c
vendored
28
cpu/esp32/vendor/esp-idf/esp_funcs.c
vendored
@ -50,34 +50,6 @@
|
||||
|
||||
#include "syscalls.h"
|
||||
|
||||
/* This function is not part on newlib API, it is defined in libc/stdio/local.h
|
||||
* There is no nice way to get __cleanup member populated while avoiding __sinit,
|
||||
* so extern declaration is used here.
|
||||
*/
|
||||
extern void _cleanup_r(struct _reent* r);
|
||||
|
||||
/**
|
||||
* This is the replacement for newlib's _REENT_INIT_PTR and __sinit.
|
||||
* The problem with __sinit is that it allocates three FILE structures
|
||||
* (stdin, stdout, stderr). Having individual standard streams for each task
|
||||
* is a bit too much on a small embedded system. So we point streams
|
||||
* to the streams of the global struct _reent, which are initialized in
|
||||
* startup code.
|
||||
*/
|
||||
void IRAM_ATTR esp_reent_init(struct _reent* r)
|
||||
{
|
||||
memset(r, 0, sizeof(*r));
|
||||
r->_stdout = _GLOBAL_REENT->_stdout;
|
||||
r->_stderr = _GLOBAL_REENT->_stderr;
|
||||
r->_stdin = _GLOBAL_REENT->_stdin;
|
||||
r->__cleanup = &_cleanup_r;
|
||||
r->__sdidinit = 1;
|
||||
r->__sglue._next = NULL;
|
||||
r->__sglue._niobs = 0;
|
||||
r->__sglue._iobs = NULL;
|
||||
r->_current_locale = "C";
|
||||
}
|
||||
|
||||
/* source: /path/to/esp-idf/components/esp32/panic.c */
|
||||
void IRAM_ATTR esp_panic_wdt_stop (void)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user