I wrote the following code using SDK 3.1 to setup ESP8266 E12 to act an access point. It starts normally, but once I try to connect to it from Windows 10, it crashes. I captured the attached output from the serial port.
I erased the 4MB using esp_tool erase_flash and even writing 1MB blank bin to the start of eack 1MB flash.
just to make sure that I have a clean start.
I write the blank and init (v08) to:
c:/Espressif/utils/ESP8266/esptool.exe -p COM3 write_flash -ff 40m -fm qio -fs 32m 0x3fc000 c:/Espressif/ESP8266_SDK/bin/esp_init_data_default.bin 0x3fd000 c:/Espressif/ESP8266_SDK/bin/blank.bin
I write the programs to:
c:/Espressif/utils/ESP8266/esptool.exe -p COM3 -b 230400 write_flash -ff 40m -fm qio -fs 32m 0x00000 firmware/eagle.flash.bin 0x10000 firmware/eagle.irom0text.bin
Output of RealTerm serial monitor. These are are extracts, not in specific order:
In baudrate 74880
rf cal sector: 1019
freq trace enable 0
In baudrate 9600
Fatal exception 28Fatal exception 28(LoadProhibitedCause):
epc1=0x4000debe, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000001c, depc=0x0
0000000
Fatal exception 0(IllegalInstructionCause):
epc1=0x402211e0, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000001c, depc=0x0
0000000
I tried several power supplies with 100uf and 100nf decoupling caps near Vcc and GND.
Following is my code:
/*
setup ESP8266 as a softAP. Still crashes when trying to connect to the softAP
*/
#include <ets_sys.h>
#include "user_interface.h"
#include <osapi.h>
#include <gpio.h>
#include <mem.h>
#include "driver/uart.h"
#define SPI_FLASH_SIZE_MAP 4 // ESP8266-12E 4MB Flash !!
#define SYSTEM_PARTITION_OTA_SIZE 0x6A000
#define SYSTEM_PARTITION_OTA_2_ADDR 0x81000
#define SYSTEM_PARTITION_RF_CAL_ADDR 0x3fb000
#define SYSTEM_PARTITION_PHY_DATA_ADDR 0x3fc000
#define SYSTEM_PARTITION_SYSTEM_PARAMETER_ADDR 0x3fd000
static const partition_item_t at_partition_table[] = {
{ SYSTEM_PARTITION_BOOTLOADER, 0x0, 0x1000},
{ SYSTEM_PARTITION_OTA_1, 0x1000, SYSTEM_PARTITION_OTA_SIZE},
{ SYSTEM_PARTITION_OTA_2, SYSTEM_PARTITION_OTA_2_ADDR, SYSTEM_PARTITION_OTA_SIZE},
{ SYSTEM_PARTITION_RF_CAL, SYSTEM_PARTITION_RF_CAL_ADDR, 0x1000},
{ SYSTEM_PARTITION_PHY_DATA, SYSTEM_PARTITION_PHY_DATA_ADDR, 0x1000},
{ SYSTEM_PARTITION_SYSTEM_PARAMETER, SYSTEM_PARTITION_SYSTEM_PARAMETER_ADDR, 0x3000},
};
/******************************************************************************
* FunctionName : user_rf_cal_sector_set
* Description : SDK just reversed 4 sectors, used for rf init data and paramters.
* We add this function to force users to set rf cal sector, since
* we don't know which sector is free in user's application.
* sector map for last several sectors : ABBBCDDD
* A : rf cal
* B : at parameters
* C : rf init data
* D : sdk parameters
* Parameters : none
* Returns : rf cal sector
*******************************************************************************/
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 8;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
void ICACHE_FLASH_ATTR user_rf_pre_init(void) {
}
void ICACHE_FLASH_ATTR user_pre_init(void) {
if(!system_partition_table_regist(at_partition_table, sizeof(at_partition_table)/sizeof(at_partition_table[0]),SPI_FLASH_SIZE_MAP)) {
os_printf("system_partition_table_regist fail\r\n");
while(1);
}
}
LOCAL void ICACHE_FLASH_ATTR set_ap_config (os_event_t *e){
struct softap_config ap;
os_printf ("\r\nIn OS Task\r\n");
wifi_softap_get_config(&ap); // Get config first.
os_memset(ap.ssid, 0, 32);
os_memset(ap.password, 0, 64);
os_memcpy(ap.ssid, "softAP", 6);
os_memcpy(ap.password, "", 10);
// ap.authmode = AUTH_WPA2_PSK;
ap.authmode = AUTH_OPEN;
ap.ssid_len = 0; // or its actual length
ap.max_connection = 1; // Max no. of stations permissible?
wifi_softap_set_config (&ap); // Update ESP8266 softap config!
}
LOCAL void ICACHE_FLASH_ATTR sdk_init_done_cb (void){
unsigned char res;
os_event_t *testQueue;
res = wifi_set_opmode_current (SOFTAP_MODE); // Make sure ESP8266 is in SoftAP mode!
os_printf ("\r\nSet op mode returned: %d\r\n", res);
testQueue = (os_event_t *)os_malloc(sizeof(os_event_t)*4);
system_os_task (set_ap_config, USER_TASK_PRIO_1, testQueue, 4);
system_os_post(USER_TASK_PRIO_1, 0, 0);
// ap_server_setup (AP_PORT); // Continue with server setup, etc
}
void ICACHE_FLASH_ATTR user_init(void) {
uart_init(BIT_RATE_9600, BIT_RATE_9600); // uart0_br, uart1_br
system_init_done_cb(sdk_init_done_cb);
}
Any idea what I could be doing wrong?