I'm compiling the basic example "blinky" without problem, but if I add a reference to malloc, I get several errors I don't understand.
This is my code:
/*
The obligatory blinky demo
Blink an LED on GPIO pin 2
*/
#include <ets_sys.h>
#include <osapi.h>
#include <gpio.h>
#include <stdlib.h> // <--- ADDED BY ME
// see eagle_soc.h for these definitions
#define LED_GPIO 2
#define LED_GPIO_MUX PERIPHS_IO_MUX_GPIO2_U
#define LED_GPIO_FUNC FUNC_GPIO2
#define DELAY 1000000 /* microseconds */
extern void ets_wdt_enable (void);
extern void ets_wdt_disable (void);
extern void ets_delay_us(int delay);
extern void wdt_feed (void);
void user_init(void)
{
uint8_t * pstate = (uint8_t*)malloc(sizeof(uint8_t)); // <--- ADDED BY ME
*pstate = 0; // <--- ADDED BY ME
uint8_t state=0;
ets_wdt_enable();
ets_wdt_disable();
// Configure pin as a GPIO
PIN_FUNC_SELECT(LED_GPIO_MUX, LED_GPIO_FUNC);
for(;;)
{
GPIO_OUTPUT_SET(LED_GPIO, *pstate); // <--- ADDED BY ME
//GPIO_OUTPUT_SET(LED_GPIO, state); // <--- COMMENTED BY ME
os_delay_us(DELAY);
*pstate ^=1; // <--- ADDED BY ME
//state ^=1; // <--- COMMENTED BY ME
wdt_feed();
}
}
As you can see i've ADDED a bit of code, using "malloc" (I also include stdlib.h). But I get these compiler result:
c:/espressif/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-mallocr.o):(.literal+0x24): undefined reference to `_sbrk_r'
c:/espressif/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/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:/espressif/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/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:/_workspace/minimal_multithreaded_framework/project/eclipse_windows_esp8266/espressif/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/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
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [build/app.out] Error 1
C:/Project/blinky/Makefile:216: recipe for target 'build/app.out' failed
First of all I don't really know why appears path "d:\Neo\Project\ESP8266\DevKit..." during compilation (it isn't in my computer).
I think it doesn't found library libc.a (and hence it is failing during compilation). But Makefile is the original one, I didn't change anything so I supposed I could use standard library function calls like malloc, free, etc....
Anybody can help?? Thanks.