Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By yuki
#12921 Hello,

i try to use the stdio.h but i get allays compiling errors.

example code:
Code: Select all
#include <stdio.h>

void setup() {
  char wBuf[10];
  uint8_t wTest = 2;
  sprintf(wBuf, "TEST: %d", 2);
  printf("%s\n", wBuf);
}

void loop() {

}


error:
Code: Select allC:/arduino-nightly/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Temp\build7857054617614130097.tmp/sketch_mar29a.cpp.elf section `.text' will not fit in region `iram1_0_seg'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-mallocr.o):(.literal+0x2c): undefined reference to `_sbrk_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-mallocr.o): In function `malloc_extend_top':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdlib/../../../../../newlib/libc/stdlib/mallocr.c:2165: undefined reference to `_sbrk_r'
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdlib/../../../../../newlib/libc/stdlib/mallocr.c:2202: undefined reference to `_sbrk_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-freer.o): In function `_malloc_trim_r':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdlib/../../../../../newlib/libc/stdlib/mallocr.c:3325: undefined reference to `_sbrk_r'
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdlib/../../../../../newlib/libc/stdlib/mallocr.c:3332: undefined reference to `_sbrk_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-freer.o):d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdlib/../../../../../newlib/libc/stdlib/mallocr.c:3340: more undefined references to `_sbrk_r' follow
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-makebuf.o):(.literal+0x8): undefined reference to `_fstat_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-makebuf.o): In function `__smakebuf_r':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdio/../../../../../newlib/libc/stdio/makebuf.c:59: undefined reference to `_fstat_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o):(.literal+0x4): undefined reference to `_read_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o):(.literal+0x8): undefined reference to `_lseek_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o):(.literal+0xc): undefined reference to `_write_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o):(.literal+0x10): undefined reference to `_close_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o): In function `__sread':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdio/../../../../../newlib/libc/stdio/stdio.c:48: undefined reference to `_read_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o): In function `__swrite':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdio/../../../../../newlib/libc/stdio/stdio.c:89: undefined reference to `_lseek_r'
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdio/../../../../../newlib/libc/stdio/stdio.c:97: undefined reference to `_write_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o): In function `__sseek':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdio/../../../../../newlib/libc/stdio/stdio.c:117: undefined reference to `_lseek_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(lib_a-stdio.o): In function `__sclose':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\stdio/../../../../../newlib/libc/stdio/stdio.c:135: undefined reference to `_close_r'
C:/arduino-nightly/hardware/tools/esp8266/sdk//lib\libc.a(isatty.o): In function `_isatty_r':
d:\Neo\Project\ESP8266\DevKit\build\compiler\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libc\sys\xtensa/../../../../../../newlib/libc/sys/xtensa/isatty.c:13: undefined reference to `_fstat_r'
collect2.exe: error: ld returned 1 exit status


is there a way to use sprintf and printf in the ESP8266 Arduino IDE?
User avatar
By igrr
#12927 Currently this is not possible because these functions use malloc from ulibc.
ulibc-provided malloc doesn't work because it depends on _sbrk which isn't implemented.

The solution is to either use os_sprintf from the SDK, or to fix ulibc so that it would use os_malloc and os_free instead of malloc and free.
User avatar
By yuki
#12946 ok i add some defines to use the os function, now i can port some code from avr Arduino projects :)

Code: Select all#define printf(...) os_printf( __VA_ARGS__ )
#define sprintf(...) os_sprintf( __VA_ARGS__ )


for some reasons i also need to add

Code: Select allextern int os_printf_plus(const char * format, ...);
User avatar
By Mikejstb
#13143 I put your defines at the start of my sketch but I get this error on compile -

Code: Select all: 1.6.1 (Windows 8.1), Board: "Generic ESP8266 board"

Using library PubSubClient in folder: D:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\libraries\PubSubClient (legacy)

Using library ESP8266WiFi in folder: D:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\hardware\esp8266com\esp8266\libraries\ESP8266WiFi

Using library DHT in folder: D:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\libraries\DHT (legacy)



D:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1/hardware/tools/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ -D__ets__ -DICACHE_FLASH -ID:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1/hardware/tools/esp8266/sdk//include -c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD -DF_CPU=80000000L -DARDUINO=10601 -DARDUINO_ESP8266_ESP01 -DARDUINO_ARCH_ESP8266 -ID:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\hardware\esp8266com\esp8266\cores\esp8266 -ID:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\hardware\esp8266com\esp8266\variants\esp01 -ID:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\libraries\PubSubClient -ID:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\hardware\esp8266com\esp8266\libraries\ESP8266WiFi\src -ID:\ESP8266\tools-utilites\arduino-1.6.1-windows\arduino-1.6.1\libraries\DHT C:\Users\Michael\AppData\Local\Temp\build1840418149224716237.tmp\myDht11-mqtt.cpp -o C:\Users\Michael\AppData\Local\Temp\build1840418149224716237.tmp\myDht11-mqtt.cpp.o

myDht11-mqtt.ino:19:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myDht11-mqtt.ino: In function 'void setup()':

myDht11-mqtt.ino:38:46: error: 'os_sprintf' was not declared in this scope

myDht11-mqtt.ino:41:3: note: in expansion of macro 'sprintf'

Error compiling.


I'm hoping to use sprint() to merge my chip ID with my mqtt topic. I am able to get the chip ID
with the suggested addition of:

extern "C" {#include "user_interface.h"}
long chipId = system_get_chip_id();