39
1.4 © 2016 Espressif ଉᥠᳯ

Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

1.4

© 2016

Espressif

Page 2: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

ESP8266

1 ESP8266

2 ESP8266

3 ESP8266

4 ESP8266

5 ESP8266

6 ESP8266

7 Wi-Fi ESP8266 Wi-Fi

8 ESP8266

2016.08 V1.0

2016.09 V1.1 3 “ ESP8266 ”

2016.10 V1.2

• 1 “ FOTA eagle.irom0.text.bin ”

• 3 “ ESP8266 AP ”

2016.10 V1.3 7 “ wifi_softap_set_config()

ESP8266 SoftAP SSID ”

2016.11 V1.4

3 : • ESP8266 2 7

• ESP8266 boot

boot

Page 3: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

1. 1 ..................................................................................................................

2 BIN “user1.bin” “user2.bin” 1.....................................

“user1.bin” “user2.bin”? 1.....................................................................................................

FOTA eagle.irom0.text.bin 1.............................

1.................................................................................................................

2............................................................................................

? 2..........................................................................................

ESP8266 2..............................................................................................

SmartConfig 2................................................................................................

SmartConfig APP 3...................................................................................

ESP8266 HTTP 3........................................................................................................

AT HTTP 3...........................................................................................................

AT+ 4.......................................................

Product ID 5.....................................................................

ESP8266 AT AT 5........................

2. 6 ...............................................................................................................

6.................................................................................

3. 7 ...................................................................................................................

ESP8266 7.........................................................................................................

7...................................................................

7.................................................................................

10 7.......................................................................

Non-OS SDK memory leak debug 7........................................................................

RTOS SDK memory leak debug 8............................................................................

ESP8266 8.................................................................................................

Page 4: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

“fatal exception” 9.................................................................................................

ESP8266 timer 10............................................................................................................

timer 10.....................................................................................................

Tx Power 10........................................................................................................................

ESP8266_Non-OS_SDK “ICACHE_FLASH_ATTR” 10....................

Non-OS SDK IRAM_ATTR 11...................................................................

“irom0_0_seg” 11.................................................................................

ESP8266 main 12......................................................................................................................

12............................................................................................................

RTOS SDK Non-OS SDK 12...........................................................................................

user_init 12..............................................

Light-sleep GPIO 13..................................................................................

ESP8266 FRC1 hw_timer 13..........................................................................................

ESP8266 AP 14............................................................................................

ESP8266 2,7 14.............................................................

ESP8266 boot boot 15.........................................

4. 16 .................................................................................................................

ESP8266 16..................................................................................................................

ESP8266 16................................................................................

ESP8266 16........................................................................................

AA ESP8266 16....................................................

SPI Flash 16...............................................................................................

boot 17.................................................................................

ESP8266 RAM 17.........................................................................................

5. 19 .................................................................................................................

ADC 19...............................................................

ADC “bitmap” 19................................................................................

ADC 19.............................................................................................................................

Page 5: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

ADC 19.................................................................................................................

(u8 tx_addr, u8 tx_cmd, u8 tx_rep) 19...........................................................

ESP8266 20..................................................................

UART 20......................................................................................................................

UART1 20......................................................................................................

SDIO SD 21.....................................................................................................................

SDIO 21.........................................................................................................

LED 21........................................................................................

PWM 22........................................................................

PWM 22.............................................................................................

GPIO 5V 22.................................................................................................................

GPIO register bitmap 22.................................................................................

GPIO 22...............................................................................................................................

HSPI 23...............................................................................................

ESP8266 HSPI 23.......................................

64 23.........................................................................................................

(H)SPI 23.....................................................................................................................

API Flash 23................................................................................................................

24...................................................................................................................

Flash 24..................................................................................................

ESP8266 Flash 24..............................................................

Flash 24................................................................................................................

Flash QIO DIO 25....................................................................................

26...................................................................................................................

ESP8266 UART 26..................................................................................................................

GPIO 26................................................................................................................

27..........................................................................................................................

6. 28 .................................................................................................................

Page 6: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

TCP / UDP 28...............................................................................................................

7. Wi-Fi 29 ............................................................................................................... SoftAP + Station 192.168.4.X 29................

29......................................................

wifi_softap_set_config() ESP8266 SoftAP SSID 29...................................................................................................................................................

ESP8266 SoftAP + Station 30.............................................................

Wi-Fi 31........................................................................................

ESP8266 31.................................................................................

8. 32 .................................................................................................................

Flash 32.........................................................................................................

Page 7: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!1.

1. 2 BIN “user1.bin” “user2.bin”

user1.bin user2.bin 2 BIN user1.bin user2.bin Flash boot OTA 2 BIN user1.bin

user2.bin user2.bin user1.bin

“user1.bin” “user2.bin”? gen_misc.sh user1.bin user2.bin

1. Flash boot user1.bin

2. make clean

3. Flash boot user2.bin

FOTA eagle.irom0.text.bin Non-OS SDK RTOS SDK BIN

FOTA eagle.irom0.text.bin BIN Flash SDK/ld eagle.app.v6.ld

ESP8266 SDK eagle.irom0.text.bin ESP8266 SDK BIN Flash

!

eagle.irom0.text.bin Flash 0x10000

ESP8266 FOTA

• Flash

Espressif ! /!1 33 2016.11

Page 8: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!1.

• blank.bin

• user1.bin user2.bin

• user1.bin user2.bin Flash boot

1. HEAD BIN HTTP BIN

2. BIN ESP8266 Flash (spi_flash_erase_sector)

3. GET BIN Flash

? HTTP

API http://iot.espressif.cn/#/api-zh-cn/

ESP8266 HTTP ESP8266 HTTP

GET/your-bin-file-path.binHTTP/1.1Host:yourdomain.comConnection:keep-aliveCache-Control:max-age=0Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8User-Agent:Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/39.0.2171.95Safari/537.36Accept-Encoding:gzip,deflate,sdchAccept-Language:en-US,en;q=0.8,ja;q=0.6,zh-CN;q=0.4,zh-TW;q=0.2

HTTP “\r\n\r\n”

debug

telnet<sitename><port_number>

telnet PC telnet TeraTerm

SmartConfig

Espressif ! /!2 33 2016.11

Page 9: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!1.

1. APP SDK SmartConfig

2. 5G

3. SmartConfig API

4. AT IP smartconfig_stop

smartconfig_start debug log

SmartConfig APP smartconfig_start() “SC version: vX.X.X” ESP-TOUCH

OS SmartConfig APP

ESP8266 HTTP ESP8266 SoftAP Station

• SoftAP ESP8266 IP 192.168.4.1

• Station IP ESP8266 IP

• SDK espconn API

• AT AT+CIPSERVER

AT HTTP

1. AT SoftAP + Station AT+CWMODE=3//setsoftAP+stationmode

2. AT AT+CWJAP="SSID","password"//ESP8266stationconnecttorouter

3. TCP HTTP HTTP [(0x0d 0x0a) or (CR LF)]

sdk v1.2.0 smartconfig v2.4 app v0.3.4.x

sdk v1.3.0 smartconfig v2.5 app v0.3.4.x

sdk v1.3.0 smartconfig v2.5.1 app v0.3.4.x

sdk v1.4.0 smartconfig v2.5.2 app v0.3.4.x

sdk v1.5.0 smartconfig v2.5.3 app v0.3.4.x

sdk v1.5.4 smartconfig v2.5.4 app v0.3.4.x

Espressif ! /!3 33 2016.11

Page 10: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!1.

!

4. HTTP

!

AT+ Non-OS SDK AT \ESP8266_NONOS_SDK\examples\at\user\user_main.c

AT “AT+TEST”

at_funcationType “AT+TEST”

• at_testCmd AT+TEST=? AT at_testCmdTest NULL

• at_queryCmd AT+TEST? AT at_queryCmdTest NULL

• at_setupCmd AT+TEST=parameter1,parameter2,......AT at_setupCmdTest NULL

• at_exeCmd AT+TEST AT at_exeCmdTest NULL

Espressif ! /!4 33 2016.11

Page 11: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!1.

Product ID device ID ID = 1234

curl-q“https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx0f74f861897f84b5&secret=your_WeChatname_32characters_please”

// access token “your_WeChatname_32characters_please” API 32

{"access_token":"L2_2V1E98Vk-jTXenXDZjDT0GaudUn_VGTRa7O98hdfT0lTZa2B7nj6YvXN01gssQa3ZraRgjALuCvxd-

SamuPR885KJabaw1EYLA0kns-Yglr4ryolEhHb-QcnWMaNqSEDjACANZY","expires_in":7200}

curl-d'{"device_num":"1","device_list":[{"id":"1234","mac":"18fe3497d500","connect_protocol":"4","auth_key":"00000000000000000000000000000000","close_strategy":"1","conn_strategy":"1","crypt_method":"0","auth_ver":"0","manu_mac_pos":"-2","ser_mac_pos":"-2"}],"op_type":"0","product_id":5157}'"https://api.weixin.qq.com/device/authorize_device?access_token=L2_2V1E98Vk-jTXenXDZjDT0GaudUn_VGTRa7O98hdfT0lTZa2B7nj6YvXN01gssQa3ZraRgjALuCvxd-SamuPR885KJabaw1EYLA0kns-Yglr4ryolEhHb-QcnWMaNqSEDjACANZY"

// ID = 1234

AT AT+CWSTARTDISCOVER=“gh_9e2cff3dfa51","1234",1 “gh_9e2cff3dfa51”

ESP8266 AT AT

ESP8266_NONOS_SDK\examples\at ESP8266 AT AT

AT SDK AT 128 “\r\n”

AT+CMDTEST=param1,param2,param3,….paramN\r\n

strlen(“AT+CMDTEST=param1,param2,param3,....paramN\r\n”)<=128 bytes

SDK ESP8266 SDK Demo

Espressif ! /!5 33 2016.11

Page 12: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!2.

2.

1. master-device-key

2. Airkiss/ESP_TOUCH token App /v1/device/activate token

3. App /v1/device/authorize token owner owner key

4. device key device key

5. /v1/user/devices device key device key

6. owner /v1/device/share /v1/device/authorize

Espressif ! /!6 33 2016.11

Page 13: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

3. ESP8266

ESP8266 2 2

0.8*2048 ms 1638.4 ms 0.8*8192 ms 6553.6

ms

6553.6 ms 8192 ms

MAC timer 1600 ms 1600 ms + 1600 ms

3200 ms

SDK

1. system_soft_wdt_stop() system_soft_wdt_restart()

2. system_soft_wdt_feed()

10

callback timer API

timer API callback

Non-OS SDK memory leak debug MEMLEAK_DEBUG memory leak debug os_malloc

os_zalloc os_calloc os_realloc os_free

Espressif ! /!7 33 2016.11

Page 14: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

system_print_meminfo() heap

1. MakeFile CONFIGURATION_DEFINES

-DMEMLEAK_DEBUG

CONFIGURATION_DEFINES=-DMEMLEAK_DEBUG

2. user_main.c

#include“mem.h"

boolICACHE_FLASH_ATTRcheck_memleak_debug_enable(void)

{

returnMEMLEAK_DEBUG_ENABLE;

}

3. system_print_meminfo() debug

RTOS SDK memory leak debug FreeRTOS debug

ESP8266 ESP8266

1. Flash

• Flash HTML

define

#definetest_string  "helloworld"

staticconstchartest_string[]ICACHE_RODATA_ATTR="helloworld";

• ICACHE_RODATA_ATTR

Flash

#defineGET_ALIGN_STRING_LEN(str)  ((strlen(str)+3)&~3)

Flash os_memcpy API

unsignedintstr_len= GET_ALIGN_STRING_LEN(test_string);

char*tmp_string=(char*)os_malloc(str_len);

os_memcpy(tmp_string,test_string,str_len);

Espressif ! /!8 33 2016.11

Page 15: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

• tmp_string test_string RAM Flash

exception

…….

os_free(tmp_string);

API

2. const Flash

• uint32 Flash

constuint32array[4]ICACHE_RODATA_ATTR={0x11111111,0x22222222,0x33333333,0x44444444};

array[0]

• uint8 uint16

constuint8array[7]ICACHE_RODATA_ATTR={0x01,0x02,0x03,0x04,0x05,0x06,0x07};

• char array[0] crash

• Flash 1

3. Flash

printf RAM os_printf

Flash RAM

4.

API os_malloc os_free

“fatal exception” *.S

Fatalexception(28):epc1=0x4025bfa6,epc2=0x00000000,epc3=0x00000000,excvaddr=0x0000000f,depc=0x00000000

Espressif ! /!9 33 2016.11

Page 16: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

user1.bin user1.S 0x4025bfa6

flash.bin irom0text.bin eagle.S

ESP8266 timer ESP8266 2 timer timer timer

API os_timer DSR

timer

timer SDK API ESP8266 Non-OS SDK API ESP8266 RTOS SDK API

Non-OS SDK ICACHE_FLASH_ATTR CPU

Tx Power “system_phy_set_max_tpw” RF Tx Power 0.25 dBm

Flash download tool esp_init_data_default.bin Tx power

• LowPowerEn Tx Power.

• BackOffEn TX Power

• PowerLimitEn Tx Power

• GenInitBin esp_init_data_default.bin

!

ESP8266_Non-OS_SDK “ICACHE_FLASH_ATTR” ESP8266_Non-OS_SDK

Espressif ! /!10 33 2016.11

Page 17: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

“ICACHE_FLASH_ATTR” IROM CPU cache “ICACHE_FLASH_ATTR”

IRAM IRAM “ICACHE_FLASH_ATTR” IROM

“ICACHE_FLASH_ATTR” Flash

ESP8266_RTOS_SDK

IROM “ICACHE_FLASH_ATTR” IROM IRAM “IRAM_ATTR”

Non-OS SDK IRAM_ATTR IRAM “ICACHE_FLASH_ATTR” IRAM

“irom0_0_seg” IROM

SDK_v0.9.5 :

1. eagle.flash.bin eagle.irom0text.bin

(1) sizeofeagle.flash.bin+sizeofeagle.irom0text.bin>=236KBytes

Flash

(2) sizeofeagle.flash.bin+sizeofeagle.irom0text.bin<236KBytes

2

2. SDK/ld “eagle.app.v6.new.512.app1.ld”

irom0_0_seg:org=0x40201010,len=0x2B000

1 “eagle.irom0text.bin” len

“eagle.irom0text.bin” 179 KB

irom0_0_seg:org=0x40201010,len=0x2D000

3. user1.bin boot_v1.2+

• ICACHE_FLASH_ATTR IRAM 32 KB

• ICACHE_FLASH_ATTR IROM

RAM

Espressif ! /!11 33 2016.11

Page 18: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

• IRAM RAM

• IROM Flash cache

ESP8266 main ESP8266 main user_init

4 4

floattemp=*((float*)data) os_memcpy(memcpy)

RTOS SDK Non-OS SDK

Non-OS SDK

Non-OS SDK Non-OS SDK espconn espconn

RTOS SDK

1. RTOS SDK freeRTOS OS freeRTOS

freeRTOS USING THE FREERTOS REAL TIME KERNEL - A Practical Guide

2. RTOS SDK lwIP API BSD Socket API socket API

Socket

3. RTOS SDK cJSON JSON

4. RTOS Non-OS SDK Wi-Fi SmartConfig Sniffer FOTA AT

user_init 1. wifi_set_ip_info wifi_set_macaddr user_init

2. system_timer_reinit user_init arm timer

3. wifi_station_set_config user_init wifi_station_connect wifi_station_connect

Espressif ! /!12 33 2016.11

Page 19: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

4. wifi_station_set_auto_connect user_init

Light-sleep GPIO Light-sleep CPU

GPIO ESP8266 3 ms wifi_station_disconnect();

wifi_set_opmode(NULL_MODE);//setWiFimodetonullmode

wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);

wifi_fpm_open(); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U,FUNC_GPIO13);

gpio_pin_wakeup_enable(13,GPIO_PIN_INTR_LOLEVEL);//建 低 平 醒

wifi_fpm_set_wakeup_cb(ssc_fpm_wakup_call);

wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);

ESP8266 FRC1 hw_timer 1.

!

(1) FRC1 80M 1 16 256 tick

(2) FRC1 timer COUNT_VALUE 0 tickCOUNT_VALUE 1

(3) FRC1

COUNT_VALUE FRC1_LOAD_VALUE

COUNT_VALUE 0x7fffff

(4) FRC1 FRC1 NMI

Espressif ! /!13 33 2016.11

Page 20: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

NMI CPU NMI ESP8266 LEVEL3 LEVEL1 NMI

2. SDKHW_TIMER

SDK hw_timer 16 tick 0.2 μs hw_timer_arm

μs 1677000 μs

ESP8266 AP ESP8266 AP AP RTC memory

• ESP8266 ESP8266 Deep-sleep ESP8266 RTC memory AP AP

• ESP8266 RTC memory ESP8266

ESP8266 AP ESP8266 AP ESP8266

1. ESP8266 AP wifi_get_channel AP SPI Flash AP

2. ESP8266 Flash WRITE_PERI_REG(0x600011f4,1<<16|channel) AP RTC

memory RTC memory ESP8266 AP

3. ESP8266 RTC memory AP AP

RTC memory wifi_station_set_config SSID Flash

ESP8266 RTC memory Flash Flash

ESP8266 2,7 ESP8266 strapping strapping

ESP8266

strapping strapping /

Espressif ! /!14 33 2016.11

Page 21: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!3.

ESP8266 boot boot ESP8266 boot strapping boot ESP8266

boot

etsJan82013,rstcause:1,bootmode:(3,2)

boot mode 3 boot

Boot strapping 3 [GPIO15 GPIO0 GPIO2]

Strapping 3 /

[GPIO15 GPIO0 GPIO2]Boot

7 / [1 1 1] SDIO HighSpeed V2 IO

6 / [1 1 0] SDIO LowSpeed V1 IO

5 / [1 0 1] SDIO HighSpeed V1 IO

4 / [1 0 0] SDIO LowSpeed V2 IO

3 / [0 1 1] Flash Boot

2 / [0 1 0] Jump Boot

1 / [0 0 1] UART Boot

0 / [0 0 0] Remapping

Espressif ! /!15 33 2016.11

Page 22: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!4.

4. ESP8266

ESP8266 1.8V ~ 3.3V

3.0V ~ 3.6V 2.7V

350 mA

200 mA

SPI Flash GPIO

CHIP_EN 3.0 ~ 3.6V 1.8V GPIO

ESP8266

1. LDO

2. ESP8266

3. ESP8266 5V

4. DC-DC ESP8266 LC

ESP8266 ESP8266 RF RF

500 mA 200 mA 100 mA

ESP8266 500 mA

AA ESP8266 AA ESP8266 ESP8266 ESP8266 RF ESP8266

DC-DC LDO ESP8266

SPI Flash SPI Flash SPI Flash GPIO

Espressif ! /!16 33 2016.11

Page 23: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!4.

boot CHIP_EN CHIP_EN CHIP_EN

3.3V CH_EN RC μs CHIP_EN 60 ms boot mode {GPIO15, GPIO0, GPIO2} UART

EXT_RSTB EXT_RSTB ESP8266EX reset 0.25 VIO 100 μs

!

ESP8266 RAM ESP8266 RAM 160 KB

IRAM 64 KB

32 KB IRAM ICACHE_FLASH_ATTR .text ROM code boot SPI Flash BIN IRAM

t1 VDD33 10 2000 μs

t2 EXT_RTSB 0 2 ms

t3EXT_RTSB VDD33

0.1 - ms

t4 CHIP_EN 0 2 ms

t5CHIP_EN EXT_RTSB

0.1 - -

Espressif ! /!17 33 2016.11

Page 24: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!4.

32 KB iCache SPI Flash ICACHE_FLASH_ATTR SPI Flash iCache

DRAM 96 KB

Non-OS_SDK 80 KB .data/.bss/.rodata/heap heap .data/.bss/.rodata 16 KB ROM code

RTOS_SDK 96 KB .data/.bss/.rodata/heap heap .data/.bss/.rodata

Espressif ! /!18 33 2016.11

Page 25: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

5. ADC

1

Wi-Fi 100000

Wi-Fi 1000

ADC 12

system_adc_read()//API 10

ADC “bitmap” ADC RF bitmap

ADC ESP8266 STA modem-sleep

ADC

system_adc_fast_read RF Wi-Fi 1 2 Wi-Fi non-sleep

wifi_set_sleep_type(NONE_SLEEP_T);

sleep

ADC ADC ADC

(u8 tx_addr, u8 tx_cmd, u8 tx_rep) tx_addr

u8tx_cmd

u8tx_rep

Espressif ! /!19 33 2016.11

Page 26: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

ESP8266 26 MHz ESP8266 UART0 74880

user_main.c UART

voidICACHE_FLASH_ATTRuart_init(UartBautRateuart0_br,UartBautRateuart1_br){  //romuse74880baut_rate,herereinitialize  UartDev.baut_rate=uart0_br;  uart_config(UART0);  UartDev.baut_rate=uart1_br;  uart_config(UART1);}

UART 1. UART UART SDK/driver_lib/driver/

uart.c

2. UART

(1) uart.h 1

#defineUART_HW_RTS  1//set1:enableuarthwflowcontrolRTS,PINMTDO,FOR UART0#defineUART_HW_CTS 1   //set1:enableuarthwflowcontrlCTS,PINMTCK,FOR UART0

(2)

RXFIFO 110 RTS

!

UART1 UART1 Tx UART0 log

voidICACHE_FLASH_ATTR

uart_init_new(void)

Espressif ! /!20 33 2016.11

Page 27: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

{

//WaitforFIFOstobeemptied

  UART_WaitTxFifoEmpty(UART0);

  UART_WaitTxFifoEmpty(UART1);

//ConfigureUARTsettings

  UART_ConfigTypeDefuart_config;

  uart_config.baud_rate  =BIT_RATE_74880;

  uart_config.data_bits   =UART_WordLength_8b;

  uart_config.parity     =USART_Parity_None;

  uart_config.stop_bits   =USART_StopBits_1;

  uart_config.flow_ctrl   =USART_HardwareFlowControl_None;

  uart_config.UART_RxFlowThresh=120;

  uart_config.UART_InverseMask=UART_None_Inverse;

  UART_ParamConfig(UART0,&uart_config);

  UART_IntrConfTypeDefuart_intr;

  uart_intr.UART_IntrEnMask=UART_RXFIFO_TOUT_INT_ENA|UART_FRM_ERR_INT_ENA|UART_RXFIFO_FULL_INT_ENA;

  uart_intr.UART_RX_FifoFullIntrThresh=100;

  uart_intr.UART_RX_TimeOutIntrThresh=2;

  uart_intr.UART_TX_FifoEmptyIntrThresh=20;

  UART_IntrConfig(UART0,&uart_intr);

//SetUART1forprinting

  UART_SetPrintPort(UART1);

//Registerinterrupthandler  UART_intr_handler_register(uart0_rx_intr_handler);

  ETS_UART_INTR_ENABLE();

}

SDIO SD ESP8266 SDIO Slave SD

SDIO SDIO 50 MHz 200 Mbps

LED IO

Flash IO GPIO4 GPIO5 IO

Espressif ! /!21 33 2016.11

Page 28: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

1. user_init

2. boot.bin BIN RAM IO user_init

PWM

PWM PWM 22222 PWM Duty 100%

PWM SDK example/IOT_demo API light_set_aim light_set_aim_r

API

PWM Duty pwm_set_duty pwm_set_duty pwm_start

GPIO 5V GPIO 3.6V GPIO

GPIO register bitmap ESP8266

GPIO Non-OS SDK MTDO

voidICACHE_FLASH_ATTRgpio_init(void) 

{

 //GPIOAlternateFunction   PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U,FUNC_GPIO15);  GPIO_DIS_OUTPUT(GPIO_ID_PIN(15));                 //Configureitininputmode.  ETS_GPIO_INTR_DISABLE();                     //ClosetheGPIOinterrupt//Registertheinterruptfunction  ETS_GPIO_INTR_ATTACH(GPIO_INTERRUPT,NULL);            

  gpio_pin_intr_state_set(GPIO_ID_PIN(15),GPIO_PIN_INTR_NEGEDGE);  //Fallingedgetrigger  ETS_GPIO_INTR_ENABLE();                     //EnabletheGPIOinterrupt}

RTOS SDK

  GPIO_ConfigTypeDefgpio_in_cfg;                  //DefineGPIOInitStructure  gpio_in_cfg.GPIO_IntrType=GPIO_PIN_INTR_NEGEDGE;        //Fallingedgetrigger  gpio_in_cfg.GPIO_Mode=GPIO_Mode_Input;             //Inputmode  gpio_in_cfg.GPIO_Pin =GPIO_Pin_15;               //EnableGPIO  gpio_config(&gpio_in_cfg);                    //Initializationfunction

Espressif ! /!22 33 2016.11

Page 29: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

  GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS,BIT(GPIO_UART_IN_NUM));   gpio_intr_handler_register(interrupt_GPIO_UART);         //Registertheinterruptfunction  _xt_isr_unmask(1<<ETS_GPIO_INUM);                //EnabletheGPIOinterrupt

}

Non-OS SDK RTOS SDK

HSPI 64 memory map

LSB MSB buffer 90%

ESP8266 HSPI I2C HSPI HSPI HSPI_CS0 LCD CS

64

CLEAR_PERI_REG_MASK(SPI_USER(spiNum),SPI_USR_MISO_HIGHPART);

MISO

(H)SPI Non-OS SDK example/peripheral_test

API Flash wifi_station_set_auto_connect

wifi_station_ap_number_set

wifi_set_phy_mode

wifi_softap_set_config

wifi_station_set_config

wifi_set_opmode

system_restart_enhance

system_restore

system_upgrade_reboot

Espressif ! /!23 33 2016.11

Page 30: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

SPI Flash

flag

Flash block

ESP8266 Flash Flash Flash map Flash map

8 Mbit Flash 0x100000

Flash uint32 sector sector uint 32 cnt sector

#defineFLASH_WRITE_LEN_BYTE(1024*4)

#defineFLASH_WRITE_CONTENT(0X10)

voidflash_sector_rw_test(uint32sector,uint32cnt)

{

  char*w_data=(char*)os_malloc(FLASH_WRITE_LEN_BYTE);

  uint32flash_operate=0;

  uint32i=0;

  uint8status=0;

  os_printf("TestSectoris0x%x\n",sector);

  if(NULL==w_data){

    os_printf("Memorylittle\n");

    return;

  }

  os_memset(w_data,FLASH_WRITE_CONTENT,FLASH_WRITE_LEN_BYTE);

  for(i=0;i<cnt;i++){

    if(spi_flash_erase_sector(sector+i)==0)

    {

      os_printf("erasesector0x%xok\n",sector+i);

    }

    else{

      os_printf("Err:erasesector0x%xerr\n",sector+i);

    }

  }

  for(i=0;i<cnt;i++){

Espressif ! /!24 33 2016.11

Page 31: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

    if(spi_flash_write((sector+i)*(FLASH_WRITE_LEN_BYTE),(uint32*)w_data,FLASH_WRITE_LEN_BYTE)==0)

    {

      os_printf("writesector0x%xok\n",sector+i);

    }

    else{

      os_printf("Err:writesector0x%xerr\n",sector+i);

    }

  }

  for(i=0;i<cnt;i++){

      os_memset(w_data,0x00,FLASH_WRITE_LEN_BYTE);

    if(spi_flash_read((sector+i)*(FLASH_WRITE_LEN_BYTE),(uint32*)w_data,FLASH_WRITE_LEN_BYTE)==0)

    {

      uint32j=0;

      for(j=0;j<FLASH_WRITE_LEN_BYTE;j++){

       if(*(w_data+j)!=FLASH_WRITE_CONTENT){

         os_printf("ErrFlashreadw_data[%d]=0x%x\n",j,w_data[j]);

         //status=1;

      }

     if(*(w_data+j)==FLASH_WRITE_CONTENT&&j==FLASH_WRITE_LEN_BYTE-1)

     {

        os_printf("Sector0x%xTestOk\n",sector+i);

      }

  }

    }

    else{

      os_printf("Err:readsector0x%xerr\n",sector+i);

    } 

  }

  os_free(w_data);

  w_data=NULL;

}

Flash QIO DIO Flash

1. QE BIT(9)

2. 01H+StatusReg1+StatusReg2

3. Flash :

• QIO EBh

Espressif ! /!25 33 2016.11

Page 32: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

• QOUT 6 Bh

Flash

Flash :

• DIO BBh

• DOUT 3 Bh

Flash ISSI Flash QIO

TCP

1460 buffer 20 ms

ESP8266 UART ESP8266 UART UART0 TX RX UART1 RX SPI-Flash

TX

GPIO XPD_DCDC GPIO GPIO IO SDIO 6

GPIO4 GPIO5 GPIO16 IO GPIO

GPIO 5V GPIO4/5 1M 100K

!

Espressif ! /!26 33 2016.11

Page 33: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!5.

U0TXD UART

system_uart_swap U0TXD U0RXD U0RTS MTDO/GPIO15 U0CTSMTCK/GPIO13

U0TXD + U0RXD MTDO MCU RXD MTCK MCU TXD

Espressif ! /!27 33 2016.11

Page 34: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!6.

6. TCP / UDP

TCP 1460 UDP 1472

Espressif ! /!28 33 2016.11

Page 35: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!

7. Wi-Fi

7. Wi-Fi SoftAP + Station 192.168.4.X

ESP8266 SoftAP IP 192.168.4.1

ESP8266 192.168.4.X SoftAp

SSID 2

1.

2. bssid_set MAC stationConf.bssid_set=0

wifi_softap_set_config() ESP8266 SoftAP SSID

wifi_softap_set_config() API ESP8266 SoftAP SoftAP SoftAP

Station

wifi_softap_set_config() system_os_task() API SoftAP SoftAP API ESP8266 SoftAP

LOCALvoidICACHE_FLASH_ATTRsome_callback_function(void){unsignedcharres;os_event_t*testQueue;res=wifi_set_opmode_current(0x02);// 保ESP8266 于SoftAP模式。os_printf("\r\nSetopmodereturned:%d",res);testQueue=(os_event_t*)os_malloc(sizeof(os_event_t)*4);system_os_task(set_ap_config,USER_TASK_PRIO_1,testQueue,4);ap_server_setup(AP_PORT);// 置服 器等。}

voidset_ap_config(os_event_t*e){structsoftap_configap;wifi_softap_get_config(&ap);//先 得之前的 置。

Espressif ! /!29 33 2016.11

Page 36: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!

7. Wi-Fi

os_memset(ap.ssid,0,32);os_memset(ap.password,0,64);os_memcpy(ap.ssid,"SSIDhere",8);os_memcpy(ap.password,"PASSWDhere",10);ap.authmode=AUTH_WPA2_PSK;ap.ssid_len=0;//或者SSID的 度。ap.max_connection=1;//允 接入Station的最大数量。wifi_softap_set_config(&ap);//更新ESP8266SoftAP 置。

}

ESP8266 SoftAP + Station ESP8266 SoftAP + Station ESP8266

ESP8266 Station SoftAP SoftAP + Station ESP8266 SoftAP ESP8266 Station ESP8266 SoftAP + Station

1. ESP8266 Station 6

2. wifi_softap_set_config ESP8266 SoftAP

3. API true ESP8266 Station 6

1. wifi_softap_set_config ESP8266 SoftAP 5

2. Station ESP8266 SoftAP

3. ESP8266 Station 6

4. ESP8266 SoftAP ESP8266 Station 6 ;

5. ESP8266 SoftAP Station Wi-Fi

1. Station ESP8266 SoftAP

2. ESP8266 Station ESP8266 SoftAP UDP ping

ESP8266 Station ESP8266 ESP8266 SoftAP ESP8266 SoftAP

UDP ping

wifi_station_disconnect ESP8266 Station wifi_station_set_reconnect_policy wifi_station_set_auto_connect ESP8266 Station

Espressif ! /!30 33 2016.11

Page 37: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!

7. Wi-Fi

Wi-Fi Wi-Fi

ESP8266 Wi-Fi

ESP8266

1. smartconfig sniffer

2. SoftAP SoftAP TCP/UDP SSID

3. WPS SoftAP WPS

Espressif ! /!31 33 2016.11

Page 38: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

!8.

8. Flash

UART USB Flash ESP8266 SDK

http://espressif.com/zh-hans/support/download/other-tools

http://espressif.com/zh-hans/support/download/documents

UART Flash Flash BIN Flash

Flash

Flash mode Flash speed Flash size combine combine target.bin

Espressif ! /!32 33 2016.11

Page 39: Espressif FAQ CN - AiThinkerwiki.ai-thinker.com/_media/esp8266/faq/espressif_faq_cn.pdf · 2017-04-26 · I - \ Y \ È U h ' ESP8266 1 ` ï Ì f J t ¼ 6 \ Y n å N ò Ô ½ Ì V;

URL

“ ”

Wi-Fi Wi-Fi Bluetooth SIG

© 2016

IOT www.espressif.com