Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By Raja Sumant
#68846 Hello all. I am a newbie. I have installed esp open sdk [https://github.com/esp8266/esp8266-wiki/wiki/Toolchain]

I have written a simple code to blink an LED.

#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_config.h"

#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
LOCAL os_timer_t blink_timer;
LOCAL uint8_t led_state=0;

LOCAL void ICACHE_FLASH_ATTR blink_cb(void *arg)
{
led_state = !led_state;
GPIO_OUTPUT_SET(2, led_state);
}

static void ICACHE_FLASH_ATTR
loop(os_event_t *events)
{
os_printf("Hello\n\r");
os_delay_us(10000);
system_os_post(user_procTaskPrio, 0, 0 );
}

void ICACHE_FLASH_ATTR
user_init()
{
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
os_timer_disarm(&blink_timer);
os_timer_setfn(&blink_timer, (os_timer_func_t *)blink_cb, (void *)0);
os_timer_arm(&blink_timer, 1000, 1);
GPIO_OUTPUT_SET(2, led_state);
//Start os task
system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);

system_os_post(user_procTaskPrio, 0, 0 );
}

I have successfully generated binary files and flashed it.

raja@raja-Inspiron-N5110:/opt/Espressif/source-code-examples/blinkMe$ make ESPPORT=/dev/ttyUSB0 flash
CC user/user_main.c
AR build/app_app.a
LD build/app.out
FW firmware/
esptool.py v2.1-beta1
Creating image for ESP8266...
esptool.py --port /dev/ttyUSB0 write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
esptool.py v2.1-beta1
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0040
Compressed 29584 bytes to 20449...
Wrote 29584 bytes (20449 compressed) at 0x00000000 in 1.8 seconds (effective 130.4 kbit/s)...
Hash of data verified.
Compressed 136028 bytes to 102576...
Wrote 136028 bytes (102576 compressed) at 0x00040000 in 9.1 seconds (effective 119.7 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...

I am however not getting the desired out put. The LED is not blinking as expected.

I have then tried to flash an example of connecting to wifi. It was not getting connected.

When I use arduino, I am able to blink an LED and successfully connect to the wifi and start a web server.

[nmap -sn IP_address/24 shows output only when I flash the arduino IDE and not the gcc compiled binaries.]

I want to try debugging using ESP-GDBStub. I will update it later.

Can any one explain me where I am going wrong?
User avatar
By Raja Sumant
#68921 I have tried debugging my output.

I got :

raja@raja-Inspiron-N5110:/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin$ ./xtensa-lx106-elf-gdb -b 115200
GNU gdb (crosstool-NG 1.20.0) 7.5.1
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_unknown-linux-gnu --target=xtensa-lx106-elf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) file /opt/Espressif/source-code-examples/blinky/build/app.out
Reading symbols from /opt/Espressif/source-code-examples/blinky/build/app.out...done.
(gdb) set remote hardware-breakpoint-limit 1
(gdb) set remote hardware-watchpoint-limit 1
(gdb) set debug xtensa 4
(gdb) target remote /dev/ttyUSB0
Remote debugging using /dev/ttyUSB0
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Malformed response to offset query, timeout


Note: I have not included the gdbstub https://github.com/espressif/esp-gdbstub in my code