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?