So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Matei
#66250 Hello, I am trying to program an ESP8266-12F using the gcc toolchain documented here: https://github.com/esp8266/esp8266-wiki/wiki/Toolchain

I started up with a blink led example:
Code: Select all#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_config.h"
static volatile os_timer_t blink_timer;
static uint8_t led_state = 0;
static uint8_t need_print = 0;

LOCAL void ICACHE_FLASH_ATTR
blink_cb(void *arg)
{
   led_state = !led_state;
   //need_print = 1;
   GPIO_OUTPUT_SET(4, led_state);
}

void ICACHE_FLASH_ATTR
user_init()
{
   gpio_init();
   PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
   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);
//   need_print = 1;
/*   int i = 0;
   while(1) {
      if(need_print) {
         need_print = 0;
         os_printf("Hello world %d\n\r", i);
      }
   }
*/}


With the code as listed above, everything works as a charm. But the moment I uncomment all the commented lines, the command "make" gives the following output (I should mention that the same error is triggered if I uncomment only line 14: need_print = 1;):
Code: Select allmkdir -p build/driver
mkdir -p build/user
mkdir -p firmware
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -Idriver -Iuser -Idriver/include -Iuser/include -Iinclude -I/opt/Espressif/ESP8266_SDK/include -I/opt/Espressif/ESP8266_SDK/include/json -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -c user/user_main.c -o build/user/user_main.o
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru build/app_app.a build/user/user_main.o
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -L/opt/Espressif/ESP8266_SDK/lib -T/opt/Espressif/ESP8266_SDK/ld/eagle.app.v6.ld -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--start-group -lc -lgcc -lhal -lpp -lphy -lnet80211 -llwip -lwpa -lmain build/app_app.a -Wl,--end-group -o build/app.out
esptool.py elf2image -o firmware/ build/app.out
esptool.py v2.0-beta2
WARNING: Unexpected ELF section header length 8305 is not mod-28
Traceback (most recent call last):
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 2301, in <module>
    _main()
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 2294, in _main
    main()
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 2096, in main
    operation_func(args)
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 1713, in elf2image
    e = ELFFile(args.input)
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 1326, in __init__
    self._read_elf_file(f)
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 1349, in _read_elf_file
    self._read_sections(f, shoff, shstrndx)
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 1366, in _read_sections
    all_sections = [read_section_header(offs) for offs in section_header_offsets]
  File "/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py", line 1364, in read_section_header
    name_offs,sec_type,_flags,lma,sec_offs,size = struct.unpack_from("<LLLLLL", section_header[offs:])
struct.error: unpack_from requires a buffer of at least 24 bytes
Makefile:112: recipe for target 'firmware/0x00000.bin' failed
make: *** [firmware/0x00000.bin] Error 1

I traced the problem down in esptool.py code, but I have no idea how to fix it. In esptool.py's belly, there's some variable holding binary data (might be the ELF, not sure) and is being operated by a function unpack_from which throws this error. But I have no idea how to fix this or even if it's a bug in esptool.py or I'm just writing bad code. However, I have no idea why assigning a variable in some random callback would be bad.

Any help is appreciated.