165
ESP8266 Non-OS SDK API 参考 版本 2.2.1 版权 © 2018

ESP8266 Non-OS SDK API 参考 - Espressif Systems - Wi ...第 5 章 应相关接 举 AT 指令相关,JSON 相关软件接。第 6 章 参数结构体和宏定义 软件结构体,宏定义的说明。第

  • Upload
    hahanh

  • View
    365

  • Download
    12

Embed Size (px)

Citation preview

  • ESP8266 Non-OS SDK API

    2.2.1

    2018

  • ESP8266_NONOS_SDK API

    1 ESP8266EX

    2 ESP8266_NONOS_SDK

    3 (API) Wi-Fi

    4 TCP/UDP TCP/UDP

    5 AT JSON

    6

    7

    A ESP8266_NONOS_SDK

    2016.03 V1.5.2 3.2A.5 3.3.37

    2016.04 V1.5.3 3.5.11 3.5.12

    3.5.67 3.7.9

    2016.05 V1.5.4 3.3.83.3.463.3.473.3.48 3.7.8

    3.7

    2016.07 V2.0.0 3.8.6 3.5.65

    3.93.143.3.483.5.72 3.5.73

    2016.11 V2.0.1 3.5.30 wifi_station_get_hostname wifi_station_set_hostname

    2017.01 V2.0.2 2

    2017.05 V2.1.0 3.3.493.3.504.3.6 8.2.4

    2017.05 V2.1.1 2

    2017.06 V2.1.2 3.3.9

  • 2018.02 V2.2 6.2.16.2.36.2.43.3.49

    3.4.83.4.93.5.743.5.75

    2018.05 V2.2.1 2.43.5.543.7

    http://www.espressif.com/zh-hans/subscribe

  • 1. 1 .........................................................................................................................................

    2. Non-OS SDK 2 .......................................................................................................................2.1. Non-OS SDK 2......................................................................................................................

    2.2. 2.....................................................................................................................................

    2.3. (timer) 3..................................................................................................................

    2.4. 4.....................................................................................................................................

    2.5. 4.....................................................................................................................................

    3. (API) 5 ...............................................................................................................

    3.1. 5.................................................................................................................................3.1.1. os_timer_arm 5................................................................................................................3.1.2. os_timer_disarm 5...........................................................................................................3.1.3. os_timer_setfn 6..............................................................................................................

    3.1.4. system_timer_reinit 6.......................................................................................................3.1.5. os_timer_arm_us 6..........................................................................................................

    3.2. 6..........................................................................................................................3.2.1. hw_timer_init 7.................................................................................................................3.2.2. hw_timer_arm 7...............................................................................................................

    3.2.3. hw_timer_set_func 8........................................................................................................

    3.2.4. 8.............................................................................................................

    3.3. 8.....................................................................................................................................3.3.1. system_get_sdk_version 8..............................................................................................3.3.2. system_restore 9.............................................................................................................3.3.3. system_restart 9..............................................................................................................

    3.3.4. system_init_done_cb 9....................................................................................................3.3.5. system_get_chip_id 9......................................................................................................3.3.6. system_get_vdd33 10.....................................................................................................3.3.7. system_adc_read 10........................................................................................................3.3.8. system_adc_read_fast 11................................................................................................3.3.9. system_deep_sleep 12....................................................................................................

  • 3.3.10. system_deep_sleep_set_option 13.................................................................................

    3.3.11. system_phy_set_rfoption 13............................................................................................3.3.12. system_phy_set_powerup_option 14..............................................................................3.3.13. system_phy_set_max_tpw 14.........................................................................................3.3.14. system_phy_set_tpw_via_vdd33 14................................................................................3.3.15. system_set_os_print 15...................................................................................................3.3.16. system_print_meminfo 15...............................................................................................

    3.3.17. system_get_free_heap_size 15........................................................................................3.3.18. system_os_task 15..........................................................................................................3.3.19. system_os_post 16..........................................................................................................3.3.20. system_get_time 16.........................................................................................................3.3.21. system_get_rtc_time 17...................................................................................................3.3.22. system_rtc_clock_cali_proc 17........................................................................................

    3.3.23. system_rtc_mem_write 17...............................................................................................3.3.24. system_rtc_mem_read 18...............................................................................................3.3.25. system_uart_swap 18......................................................................................................3.3.26. system_uart_de_swap 18................................................................................................3.3.27. system_get_boot_version 19...........................................................................................3.3.28. system_get_userbin_addr 19...........................................................................................

    3.3.29. system_get_boot_mode 19.............................................................................................3.3.30. system_restart_enhance 19.............................................................................................3.3.31. system_update_cpu_req 20............................................................................................3.3.32. system_get_cpu_freq 20.................................................................................................3.3.33. system_get_flash_size_map 20.......................................................................................3.3.34. system_get_rst_info 21....................................................................................................

    3.3.35. system_soft_wdt_stop 21................................................................................................3.3.36. system_soft_wdt_restart 21.............................................................................................3.3.37. system_soft_wdt_feed 22................................................................................................3.3.38. system_show_malloc 22..................................................................................................3.3.39. os_memset 22.................................................................................................................3.3.40. os_memcpy 23................................................................................................................

    3.3.41. os_strlen 23.....................................................................................................................3.3.42. os_printf 23......................................................................................................................3.3.43. os_bzero 23.....................................................................................................................

  • 3.3.44. os_delay_us 24................................................................................................................

    3.3.45. os_install_putc1 24..........................................................................................................3.3.46. os_random 24..................................................................................................................3.3.47. os_get_random 24...........................................................................................................3.3.48. user_rf_cal_sector_set 24................................................................................................3.3.49. system_phy_freq_trace_enable 26..................................................................................3.3.50. system_deep_sleep_instant 26.......................................................................................

    3.4. SPI Flash 26..........................................................................................................................

    3.4.1. spi_flash_get_id 26..........................................................................................................3.4.2. spi_flash_erase_sector 27...............................................................................................3.4.3. spi_flash_write 27............................................................................................................3.4.4. spi_flash_read 27.............................................................................................................

    3.4.5. system_param_save_with_protect 28.............................................................................3.4.6. system_param_load 28...................................................................................................3.4.7. spi_flash_set_read_func 29.............................................................................................3.4.8. spi_flash_erase_protect_enable 29.................................................................................3.4.9. spi_flash_erase_protect_disable 29.................................................................................

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

    3.5.1. wifi_get_opmode 31........................................................................................................3.5.2. wifi_get_opmode_default 31............................................................................................3.5.3. wifi_set_opmode 31.........................................................................................................3.5.4. wifi_set_opmode_current 32...........................................................................................3.5.5. wifi_station_get_config 32...............................................................................................

    3.5.6. wifi_station_get_config_default 32..................................................................................3.5.7. wifi_station_set_config 33...............................................................................................3.5.8. wifi_station_set_config_current 33..................................................................................3.5.9. wifi_station_set_cert_key 34............................................................................................3.5.10. wifi_station_clear_cert_key 35.........................................................................................3.5.11. wifi_station_set_username 35.........................................................................................

    3.5.12. wifi_station_clear_username 35......................................................................................3.5.13. wifi_station_connect 35...................................................................................................3.5.14. wifi_station_disconnect 36..............................................................................................3.5.15. wifi_station_get_connect_status 36................................................................................3.5.16. wifi_station_scan 36........................................................................................................

  • 3.5.17. scan_done_cb_t 37.........................................................................................................

    3.5.18. wifi_station_ap_number_set 37.......................................................................................3.5.19. wifi_station_get_ap_info 37.............................................................................................3.5.20. wifi_station_ap_change 38..............................................................................................3.5.21. wifi_station_get_current_ap_id 38...................................................................................3.5.22. wifi_station_get_auto_connect 38...................................................................................3.5.23. wifi_station_set_auto_connect 38...................................................................................

    3.5.24. wifi_station_dhcpc_start 39.............................................................................................3.5.25. wifi_station_dhcpc_stop 39.............................................................................................3.5.26. wifi_station_dhcpc_status 39..........................................................................................3.5.27. wifi_station_dhcpc_set_maxtry 39..................................................................................3.5.28. wifi_station_set_reconnect_policy 40..............................................................................3.5.29. wifi_station_get_rssi 40...................................................................................................

    3.5.30. wifi_station_set_hostname 40.........................................................................................3.5.31. wifi_station_get_hostname 40.........................................................................................3.5.32. wifi_softap_get_config 40................................................................................................3.5.33. wifi_softap_get_config_default 41...................................................................................3.5.34. wifi_softap_set_config 41................................................................................................3.5.35. wifi_softap_set_config_current 41...................................................................................

    3.5.36. wifi_softap_get_station_num 41......................................................................................3.5.37. wifi_softap_get_station_info 42.......................................................................................3.5.38. wifi_softap_free_station_info 42......................................................................................3.5.39. wifi_softap_dhcps_start 42..............................................................................................3.5.40. wifi_softap_dhcps_stop 43..............................................................................................3.5.41. wifi_softap_set_dhcps_lease 43......................................................................................

    3.5.42. wifi_softap_get_dhcps_lease 44......................................................................................3.5.43. wifi_softap_set_dhcps_lease_time 44.............................................................................3.5.44. wifi_softap_get_dhcps_lease_time 45.............................................................................3.5.45. wifi_softap_reset_dhcps_lease_time 45..........................................................................3.5.46. wifi_softap_dhcps_status 45...........................................................................................3.5.47. wifi_softap_set_dhcps_offer_option 45...........................................................................

    3.5.48. wifi_set_phy_mode 46.....................................................................................................3.5.49. wifi_get_phy_mode 46.....................................................................................................3.5.50. wifi_get_ip_info 46...........................................................................................................

  • 3.5.51. wifi_set_ip_info 47...........................................................................................................

    3.5.52. wifi_set_macaddr 47........................................................................................................3.5.53. wifi_get_macaddr 48.......................................................................................................3.5.54. wifi_set_sleep_type 48.....................................................................................................3.5.55. wifi_get_sleep_type 48....................................................................................................3.5.56. wifi_status_led_install 49.................................................................................................3.5.57. wifi_status_led_uninstall 49.............................................................................................

    3.5.58. wifi_set_broadcast_if 49..................................................................................................3.5.59. wifi_get_broadcast_if 50..................................................................................................3.5.60. wifi_set_event_handler_cb 50..........................................................................................3.5.61. wifi_wps_enable 51.........................................................................................................3.5.62. wifi_wps_disable 52.........................................................................................................3.5.63. wifi_wps_start 52.............................................................................................................

    3.5.64. wifi_set_wps_cb 52.........................................................................................................3.5.65. wifi_register_send_pkt_freedom_cb 53...........................................................................3.5.66. wifi_unregister_send_pkt_freedom_cb 53.......................................................................3.5.67. wifi_send_pkt_freedom 54...............................................................................................3.5.68. wifi_rfid_locp_recv_open 54............................................................................................3.5.69. wifi_rfid_locp_recv_close 54............................................................................................

    3.5.70. wifi_register_rfid_locp_recv_cb 55..................................................................................3.5.71. wifi_unregister_rfid_locp_recv_cb 55..............................................................................3.5.72. wifi_enable_gpio_wakeup 55...........................................................................................3.5.73. wifi_disable_gpio_wakeup 55..........................................................................................3.5.74. wifi_set_country 56..........................................................................................................3.5.75. wifi_get_country 56..........................................................................................................

    3.6. Rate Control 57.....................................................................................................................

    3.6.1. wifi_set_user_fixed_rate 57.............................................................................................3.6.2. wifi_get_user_fixed_rate 57.............................................................................................3.6.3. wifi_set_user_sup_rate 58...............................................................................................3.6.4. wifi_set_user_rate_limit 59...............................................................................................

    3.6.5. wifi_set_user_limit_rate_mask 60....................................................................................3.6.6. wifi_get_user_limit_rate_mask 60....................................................................................

    3.7. 61............................................................................................................................3.7.1. wifi_fpm_open 61............................................................................................................

  • 3.7.2. wifi_fpm_close 61............................................................................................................

    3.7.3. wifi_fpm_do_wakeup 61..................................................................................................3.7.4. wifi_fpm_set_wakeup_cb 62...........................................................................................3.7.5. wifi_fpm_do_sleep 62......................................................................................................3.7.6. wifi_fpm_set_sleep_type 62.............................................................................................3.7.7. wifi_fpm_get_sleep_type 63............................................................................................3.7.8. wifi_fpm_auto_sleep_set_in_null_mode 63.....................................................................

    3.7.9. 63.....................................................................................................................

    3.8. ESP-NOW 66........................................................................................................................

    3.8.1. 66.........................................................................................................................

    3.8.2. esp_now_init 66...............................................................................................................3.8.3. esp_now_deinit 67...........................................................................................................3.8.4. esp_now_register_recv_cb 67.........................................................................................3.8.5. esp_now_unregister_recv_cb 67.....................................................................................3.8.6. esp_now_register_send_cb 68........................................................................................

    3.8.7. esp_now_unregister_send_cb 68....................................................................................3.8.8. esp_now_send 69............................................................................................................3.8.9. esp_now_add_peer 69....................................................................................................3.8.10. esp_now_del_peer 69......................................................................................................3.8.11. esp_now_set_self_role 69................................................................................................3.8.12. esp_now_get_self_role 70...............................................................................................

    3.8.13. esp_now_set_peer_role 70..............................................................................................3.8.14. esp_now_get_peer_role 70..............................................................................................3.8.15. esp_now_set_peer_key 70..............................................................................................3.8.16. esp_now_get_peer_key 70..............................................................................................3.8.17. esp_now_set_peer_channel 71.......................................................................................3.8.18. esp_now_get_peer_channel 71.......................................................................................

    3.8.19. esp_now_is_peer_exist 71...............................................................................................3.8.20. esp_now_fetch_peer 72...................................................................................................3.8.21. esp_now_get_cnt_info 72................................................................................................3.8.22. esp_now_set_kok 72.......................................................................................................

    3.9. Simple-Pair 73......................................................................................................................

    3.9.1. 73.........................................................................................................................

  • 3.9.2. register_simple_pair_status_cb 73..................................................................................

    3.9.3. unregister_simple_pair_status_cb 73..............................................................................3.9.4. simple_pair_init 74...........................................................................................................3.9.5. simple_pair_deinit 74.......................................................................................................3.9.6. simple_pair_state_reset 74..............................................................................................3.9.7. simple_pair_ap_enter_announce_mode 74.....................................................................3.9.8. simple_pair_sta_enter_scan_mode 74............................................................................

    3.9.9. simple_pair_sta_start_negotiate 75.................................................................................3.9.10. simple_pair_ap_start_negotiate 75..................................................................................3.9.11. simple_pair_ap_refuse_negotiate 75...............................................................................3.9.12. simple_pair_set_peer_ref 75............................................................................................3.9.13. simple_pair_get_peer_ref 76............................................................................................

    3.10. (FOTA) 77...............................................................................................................

    3.10.1. system_upgrade_userbin_check 77................................................................................3.10.2. system_upgrade_flag_set 77...........................................................................................3.10.3. system_upgrade_flag_check 77......................................................................................3.10.4. system_upgrade_start 77................................................................................................3.10.5. system_upgrade_reboot 78.............................................................................................

    3.11. Sniffer 79.......................................................................................................................

    3.11.1. wifi_promiscuous_enable 79...........................................................................................3.11.2. wifi_promiscuous_set_mac 79........................................................................................3.11.3. wifi_set_promiscuous_rx_cb 79......................................................................................3.11.4. wifi_get_channel 80.........................................................................................................

    3.11.5. wifi_set_channel 80.........................................................................................................

    3.12. SmartConfig 81.....................................................................................................................3.12.1. smartconfig_start 81........................................................................................................3.12.2. smartconfig_stop 82........................................................................................................3.12.3. smartconfig_set_type 82.................................................................................................

    3.12.4. airkiss_version 83............................................................................................................3.12.5. airkiss_lan_recv 83..........................................................................................................3.12.6. airkiss_lan_pack 84.........................................................................................................

    3.13. SNTP 85................................................................................................................................3.13.1. sntp_setserver 85............................................................................................................3.13.2. sntp_getserver 85............................................................................................................

  • 3.13.3. sntp_setservername 85...................................................................................................

    3.13.4. sntp_getservername 85...................................................................................................3.13.5. sntp_init 85......................................................................................................................3.13.6. sntp_stop 86....................................................................................................................3.13.7. sntp_get_current_timestamp 86......................................................................................3.13.8. sntp_get_real_time 86.....................................................................................................3.13.9. sntp_set_timezone 86......................................................................................................

    3.13.10.sntp_get_timezone 87.....................................................................................................

    3.13.11.SNTP 87..................................................................................................................

    3.14. WPA2-Enterprise 88..............................................................................................................3.14.1. wifi_station_set_wpa2_enterprise_auth 88......................................................................3.14.2. wifi_station_set_enterprise_cert_key 88..........................................................................3.14.3. wifi_station_clear_enterprise_cert_key 89.......................................................................3.14.4. wifi_station_set_enterprise_ca_cert 89............................................................................

    3.14.5. wifi_station_clear_enterprise_ca_cert 89.........................................................................3.14.6. wifi_station_set_enterprise_username 89........................................................................3.14.7. wifi_station_clear_enterprise_username 90.....................................................................3.14.8. wifi_station_set_enterprise_password 90........................................................................3.14.9. wifi_station_clear_enterprise_password 90.....................................................................3.14.10.wifi_station_set_enterprise_new_password 90...............................................................

    3.14.11.wifi_station_clear_enterprise_new_password 91............................................................3.14.12.wifi_station_set_enterprise_disable_time_check 91.......................................................3.14.13.wifi_station_get_enterprise_disable_time_check 91.......................................................3.14.14.wpa2_enterprise_set_user_get_time 91..........................................................................

    3.14.15. 92.....................................................................................................................

    4. TCP/UDP 93 ..................................................................................................................

    4.1. 93...................................................................................................................................

    4.1.1. espconn_delete 93..........................................................................................................4.1.2. espconn_gethostbyname 93...........................................................................................4.1.3. espconn_port 94..............................................................................................................4.1.4. espconn_regist_sentcb 94...............................................................................................

    4.1.5. espconn_regist_recvcb 95...............................................................................................4.1.6. espconn_sent_callback 95..............................................................................................

  • 4.1.7. espconn_recv_callback 95..............................................................................................

    4.1.8. espconn_get_connection_info 95....................................................................................4.1.9. espconn_send 96............................................................................................................4.1.10. espconn_sent 97.............................................................................................................

    4.2. TCP 98..................................................................................................................................4.2.1. espconn_accept 98.........................................................................................................

    4.2.2. espconn_regist_time 98...................................................................................................4.2.3. espconn_connect 98.......................................................................................................4.2.4. espconn_regist_connectcb 99........................................................................................4.2.5. espconn_connect_callback 99........................................................................................4.2.6. espconn_set_opt 99........................................................................................................4.2.7. espconn_clear_opt 100...................................................................................................

    4.2.8. espconn_set_keepalive 100............................................................................................4.2.9. espconn_get_keepalive 101............................................................................................4.2.10. espconn_reconnect_callback 101...................................................................................4.2.11. espconn_regist_reconcb 102..........................................................................................4.2.12. espconn_disconnect 102................................................................................................4.2.13. espconn_regist_disconcb 103.........................................................................................

    4.2.14. espconn_abort 103..........................................................................................................4.2.15. espconn_regist_write_finish 103.....................................................................................4.2.16. espconn_tcp_get_max_con 104......................................................................................4.2.17. espconn_tcp_set_max_con 104......................................................................................4.2.18. espconn_tcp_get_max_con_allow 104...........................................................................4.2.19. espconn_tcp_set_max_con_allow 104............................................................................

    4.2.20. espconn_recv_hold 104...................................................................................................4.2.21. espconn_recv_unhold 105...............................................................................................4.2.22. espconn_secure_accept 105...........................................................................................4.2.23. espconn_secure_delete 105............................................................................................4.2.24. espconn_secure_set_size 106.........................................................................................4.2.25. espconn_secure_get_size 106........................................................................................

    4.2.26. espconn_secure_connect 107.........................................................................................4.2.27. espconn_secure_send 107..............................................................................................4.2.28. espconn_secure_sent 108...............................................................................................4.2.29. espconn_secure_disconnect 108....................................................................................

  • 4.2.30. espconn_secure_ca_enable 108.....................................................................................

    4.2.31. espconn_secure_ca_disable 109....................................................................................4.2.32. espconn_secure_cert_req_enable 109............................................................................4.2.33. espconn_secure_cert_req_disable 109...........................................................................4.2.34. espconn_secure_set_default_certificate 110..................................................................4.2.35. espconn_secure_set_default_private_key 110................................................................

    4.3. UDP 111................................................................................................................................

    4.3.1. espconn_create 111........................................................................................................4.3.2. espconn_sendto 111.......................................................................................................4.3.3. espconn_igmp_join 111...................................................................................................4.3.4. espconn_igmp_leave 112................................................................................................4.3.5. espconn_dns_setserver 112............................................................................................

    4.3.6. espconn_dns_getserver 112...........................................................................................

    4.4. mDNS 113............................................................................................................................4.4.1. espconn_mdns_init 113...................................................................................................4.4.2. espconn_mdns_close 113...............................................................................................4.4.3. espconn_mdns_server_register 113................................................................................

    4.4.4. espconn_mdns_server_unregister 113............................................................................4.4.5. espconn_mdns_get_servername 114..............................................................................4.4.6. espconn_mdns_set_servername 114..............................................................................4.4.7. espconn_mdns_set_hostname 114.................................................................................4.4.8. espconn_mdns_get_hostname 114................................................................................4.4.9. espconn_mdns_disable 114............................................................................................

    4.4.10. espconn_mdns_enable 115.............................................................................................

    4.4.11. mDNS 115...............................................................................................................

    5. 116 ...................................................................................................................

    5.1. AT 116...................................................................................................................................5.1.1. at_response_ok 116........................................................................................................5.1.2. at_response_error 116.....................................................................................................

    5.1.3. at_cmd_array_regist 116.................................................................................................5.1.4. at_get_next_int_dec 116..................................................................................................5.1.5. at_data_str_copy 117......................................................................................................5.1.6. at_init 117........................................................................................................................

  • 5.1.7. at_port_print 117.............................................................................................................

    5.1.8. at_set_custom_info 118...................................................................................................5.1.9. at_enter_special_state 118..............................................................................................5.1.10. at_leave_special_state 118..............................................................................................5.1.11. at_get_version 118..........................................................................................................5.1.12. at_register_uart_rx_intr 118.............................................................................................5.1.13. at_response 119..............................................................................................................

    5.1.14. at_register_response_func 119........................................................................................5.1.15. at_fake_uart_enable 119..................................................................................................5.1.16. at_fake_uart_rx 120.........................................................................................................5.1.17. at_set_escape_character 120..........................................................................................

    5.2. JSON 121.............................................................................................................................

    5.2.1. jsonparse_setup 121.......................................................................................................5.2.2. jsonparse_next 121.........................................................................................................5.2.3. jsonparse_copy_value 121..............................................................................................5.2.4. jsonparse_get_value_as_int 121......................................................................................5.2.5. jsonparse_get_value_as_long 122...................................................................................5.2.6. jsonparse_get_len 122.....................................................................................................

    5.2.7. jsonparse_get_value_as_type 122...................................................................................5.2.8. jsonparse_strcmp_value 122...........................................................................................5.2.9. jsontree_set_up 122........................................................................................................5.2.10. jsontree_reset 123...........................................................................................................5.2.11. jsontree_path_name 123.................................................................................................5.2.12. jsontree_write_int 123......................................................................................................

    5.2.13. jsontree_write_int_array 123............................................................................................5.2.14. jsontree_write_string 124.................................................................................................5.2.15. jsontree_print_next 124...................................................................................................5.2.16. jsontree_find_next 124....................................................................................................

    6. 125 ........................................................................................................

    6.1. 125....................................................................................................................................

    6.2. Wi-Fi 125...............................................................................................................................

    6.2.1. Station 125..............................................................................................................

    6.2.2. SoftAP 125..............................................................................................................

  • 6.2.3. Scan 126.................................................................................................................

    6.2.4. Wi-Fi Event 127....................................................................................................

    6.2.5. SmartConfig 129..................................................................................................

    6.3. JSON 129...................................................................................................................

    6.3.1. JSON 129............................................................................................................

    6.3.2. JSON 130............................................................................................................

    6.4. espconn 131.........................................................................................................................

    6.4.1. 131...................................................................................................................

    6.4.2. espconn 131....................................................................................................................

    6.5. 132......................................................................................................................

    7. 134 ...................................................................................................................

    7.1. GPIO 134..............................................................................................................................

    7.1.1. PIN 134.........................................................................................................

    7.1.2. gpio_output_set 134........................................................................................................

    7.1.3. GPIO 135...............................................................................................

    7.1.4. GPIO 135.................................................................................................................

    7.1.5. gpio_pin_intr_state_set 135.............................................................................................

    7.1.6. GPIO 135...................................................................................................

    7.2. UART 136..............................................................................................................................

    7.2.1. uart_init 136.....................................................................................................................7.2.2. uart0_tx_buffer 136..........................................................................................................7.2.3. uart0_rx_intr_handler 136................................................................................................7.2.4. uart_div_modify 137........................................................................................................

    7.3. I2C Master 137.....................................................................................................................

    7.3.1. i2c_master_gpio_init 137.................................................................................................7.3.2. i2c_master_init 137..........................................................................................................7.3.3. i2c_master_start 138.......................................................................................................7.3.4. i2c_master_stop 138.......................................................................................................7.3.5. i2c_master_send_ack 138...............................................................................................

    7.3.6. i2c_master_send_nack 138.............................................................................................

  • 7.3.7. i2c_master_checkAck 138...............................................................................................

    7.3.8. i2c_master_readByte 139................................................................................................7.3.9. i2c_master_writeByte 139...............................................................................................

    7.4. PWM 139..............................................................................................................................7.4.1. pwm_init 139...................................................................................................................7.4.2. pwm_start 140.................................................................................................................

    7.4.3. pwm_set_duty 140..........................................................................................................7.4.4. pwm_get_duty 140..........................................................................................................7.4.5. pwm_set_period 140.......................................................................................................7.4.6. pwm_get_period 141.......................................................................................................7.4.7. get_pwm_version 141......................................................................................................

    7.5. SDIO 141..............................................................................................................................

    7.5.1. sdio_slave_init 141..........................................................................................................7.5.2. sdio_load_data 141.........................................................................................................7.5.3. sdio_register_recv_cb 142...............................................................................................

    A. 143 .................................................................................................................................

    A.1. ESPCONN 143......................................................................................................................

    A.1.1. TCP Client 143........................................................................................................

    A.1.2. TCP Server 143.......................................................................................................

    A.1.3. espconn Callback 144.....................................................................................................

    A.2. RTC API 144..................................................................................................................

    A.3. Sniffer 146.............................................................................................................................

    A.4. ESP8266 SoftAP Station 146....................................................................................

    A.5. ESP8266 147..........................................................................................................

  • ! 1.

    1. ESP8266EX Wi-Fi SoC

    ESP8266EX Wi-Fi MCU ESP8266EX Flash ESP8266EX SPI/SDIO I2C/UART Wi-Fi

    ESP8266EX balun PCB

    ESP8266EX Tensilicas L106 32-bit SRAMESP8266EX GPIO (SDK)

    (ESCP-Espressif Systems Smart Connectivity Platform) ///DDR/LVDS/LCD

    ESP8266EX SDK SDK API ESP8266

    Espressif ! /! 2018.051 149

  • ! 2. Non-OS SDK

    2. Non-OS SDK 2.1. Non-OS SDK

    Non-OS SDK (API) ESP8266 /TCP/IP Wi-FiTCP/IP

    ESP8266 user_main.c

    voiduser_init(void)

    ESP8266_NONOS_SDK_v1.5.2 user_main.c voiduser_rf_pre_init(void) uint32user_rf_cal_sector_set(void) IOT_Demo user_main.c user_rf_pre_init RF RF system_phy_set_rfoption Deep-sleep system_deep_sleep_set_option RF ESP8266 Station SoftAP Wi-Fi RF Wi-Fi API

    ESP8266_NONOS_SDK_v2.1.0 DIO-To-QIO flash user_main.c voiduser_spi_flash_dio_to_qio_pre_init(void) iRAM

    SDK JSON API

    2.2. Non-OS SDK non-OS SDK

    Non-OS SDK non-OS SDK

    RTOS SDK RTOS SDK ESP8266 SDK

    Non-OS SDK

    Espressif ! /! 2018.052 149

    http://espressif.com/sites/default/files/documentation/2a-esp8266-sdk_getting_started_guide_cn.pdf

  • ! 2. Non-OS SDK

    Non-OS SDK RTOS Non-OS SDK

    - - - - (Interrupt Service Routines, ISR)

    C C ICACHE_FLASH_ATTR flash cache IRAM_ATTR iRAM

    non-OS SDK RTOS

    register_cb API

    (ISR) ISR IRAM_ATTR

    012 2 > 1 > 0 Non-OS SDK 3 012

    system_os_task() API espconn_disconnect()API espconn espconn espconn_disconnect

    non-OS SDK CPUESP8266

    500 ms system_soft_wdt_feed()API

    esp_init_data.bin blank.bin user_rf_cal_sector_set RF

    2.3. (timer)

    Espressif ! /! 2018.053 149

  • ! 2. Non-OS SDK

    - while for CPU

    - os_delay_us while for CPU 15 ms

    5 ms 100 s os_timer_arm() API

    500 s (driver_lib) PWM API

    ISR

    2.4. ESP8266 80 MHz160 MHz CPU

    ICACHE_FLASH_ATTR IRAM_ATTR ESP8266 iRAM ICACHE_FLASH_ATTR IRAM_ATTR

    Flash flash QIO

    2.5. ESP8266 128 Mbits QSPI flash

    ESP8266 ESP8285 ESP8266 flash ESP8285

    ESP8266 160 KB RAM 64 KB iRAM96 KB dRAMiRAM 32 KB iRAM IRAM_ATTR 32 KB cache ICACHE_FLASH_ATTR

    RAM flash 4 os_memcpy API

    Espressif ! /! 2018.054 149

    http://espressif.com/sites/default/files/documentation/0a-esp8285_datasheet_cn.pdf

  • ! 3. (API)

    3. (API) 3.1.

    /ESP8266_NONOS_SDK/include/osapi.h

    os_timer

    GPIO hw_timer.c

    timeros_timer_arm os_timer_arm_us os_timer_disarm

    os_timer_setfn timer os_timer_arm os_timer_arm_us os_timer_disarm

    3.1.1. os_timer_arm

    3.1.2. os_timer_disarm

    voidos_timer_arm(os_timer_t*ptimer,uint32_tmilliseconds,boolrepeat_flag)

    os_timer_t*ptimer

    uint32_tmillisecondsms

    - system_timer_reinit 5 ~ 0x68D7A3 - system_timer_reinit 100 ~ 0x689D0

    boolrepeat_flag

    voidos_timer_disarm(os_timer_t*ptimer)

    os_timer_t*ptimer

    Espressif ! /! 2018.055 149

  • ! 3. (API)

    3.1.3. os_timer_setfn

    3.1.4. system_timer_reinit

    3.1.5. os_timer_arm_us

    3.2. /ESP8266_NONOS_SDK/examples/driver_lib/hw_timer.c driver_lib readme.txt

    voidos_timer_setfn(os_timer_t*ptimer,os_timer_func_t*pfunction,void*parg)

    os_timer_t*ptimer

    os_timer_func_t*pfunction

    void*parg

    USE_US_TIMER

    system_timer_reinit user_init

    voidsystem_timer_reinit(void)

    USE_US_TIMER user_init system_timer_reinit

    500 s

    voidos_timer_arm_us(os_timer_t*ptimer,uint32_tmicroseconds,boolrepeat_flag)

    os_timer_t*ptimer

    uint32_tmicrosecondss 0x64 0xFFFFFFF

    boolrepeat_flag

    Espressif ! /! 2018.056 149

  • ! 3. (API)

    NMI hw_timer_arm val 100

    NMI ISR

    FRC1 ISR

    hw_timer.c PWM

    ICACHE_FLASH_ATTR

    hw_timer.c wifi_set_sleep_type(LIGHT_SLEEP); Light-sleep Light-sleep CPU CPU NMI

    3.2.1. hw_timer_init

    3.2.2. hw_timer_arm

    ISR

    voidhw_timer_init(FRC1_TIMER_SOURCE_TYPEsource_type,u8req)

    FRC1_TIMER_SOURCE_TYPEsource_type ISR

    - FRC1_SOURCE FRC1 - NMI_SOURCE NMI

    u8req

    - 0 - 1

    voidhw_timer_arm(uint32val)

    uint32val

    - FRC1 FRC1_SOURCE50~0x199999 s - NMI NMI_SOURCE : 100~0x199999 s

    10~0x199999 s

    Espressif ! /! 2018.057 149

  • ! 3. (API)

    3.2.3. hw_timer_set_func

    3.2.4.

    #defineREG_READ(_r)(*(volatileuint32*)(_r))

    #defineWDEV_NOW()REG_READ(0x3ff20c00)

    uint32tick_now2=0;

    voidhw_test_timer_cb(void)

    {

    staticuint16j=0;

    j++;

    if((WDEV_NOW()-tick_now2)>=1000000)

    {

    staticu32idx=1;

    tick_now2=WDEV_NOW();

    os_printf("b%u:%d\n",idx++,j);

    j=0;

    }

    }

    voidICACHE_FLASH_ATTRuser_init(void)

    {

    hw_timer_init(FRC1_SOURCE,1);

    hw_timer_set_func(hw_test_timer_cb);

    hw_timer_arm(100);

    }

    3.3. /ESP8266_NONOS_SDK/include/user_interface.h

    os_XXX /ESP8266_NONOS_SDK/include/osapi.h

    3.3.1. system_get_sdk_version

    ICACHE_FLASH_ATTR Flash

    voidhw_timer_set_func(void(*user_hw_timer_cb_set)(void))

    void(*user_hw_timer_cb_set)(void) ICACHE_FLASH_ATTR

    SDK

    constchar*system_get_sdk_version(void)

    Espressif ! /! 2018.058 149

  • ! 3. (API)

    3.3.2. system_restore

    3.3.3. system_restart

    3.3.4. system_init_done_cb

    3.3.5. system_get_chip_id

    SDK

    printf(SDK version: %s \n, system_get_sdk_version());

    wifi_station_set_auto_connectwifi_set_phy_modewifi_softap_set_config wifi_station_set_config wifi_set_opmode #defineAP_CACHE AP

    system_restart

    voidsystem_restore(void)

    ESP8266

    voidsystem_restart(void)

    user_init

    wifi_station_scan Station

    voidsystem_init_done_cb(init_done_cb_tcb)

    init_done_cb_tcb

    voidto_scan(void){wifi_station_scan(NULL,scan_done);}voiduser_init(void){wifi_set_opmode(STATION_MODE);system_init_done_cb(to_scan);}

    ID

    uint32system_get_chip_id(void)

    Espressif ! /! 2018.059 149

  • ! 3. (API)

    3.3.6. system_get_vdd33

    3.3.7. system_adc_read

    ID

    VDD3P3 3 4 1/1024V

    system_get_vdd33 TOUT

    TOUT esp_init_data_default.bin(0 ~ 127 byte) 107 byte vdd33_const 0xFF 255

    Wi-Fi Modem-sleep Wi-Fi VDD33

    uint16system_get_vdd33(void)

    VDD33 1/1024V

    TOUT 6 1/1024V

    system_adc_read TOUT TOUT 0 ~ 1.0V

    TOUT esp_init_data_default.bin(0 ~ 127 byte) 107 byte vdd33_const VDD3P3 3 4 0xFF

    107 byte vdd33_const 0.1V [18, 36] vdd33_const [0, 18) (36, 255) 3.3V RF

    Wi-Fi Modem-sleep Wi-Fi ADC

    ADC system_adc_read_fast

    uint16system_adc_read(void)

    TOUT 6 1/1024V

    Espressif ! /! 2018.0510 149

  • ! 3. (API)

    3.3.8. system_adc_read_fast

    ADC

    Wi-Fi ADC system_adc_read_fast PWM NMI

    TOUT TOUT 0 ~ 1.0V

    TOUT ADC esp_init_data_default.bin(0 ~ 127 byte) [107] byte vdd33_const 0xFF

    [107] byte vdd33_const

    - [107] byte = 0XFF VDD33TOUT ADC

    - [107] byte [18, 36] 0.1V VDD33 RF TOUT ADC

    - [107] byte [0, 18) (36, 255) 3.3V RF TOUT ADC

    voidsystem_adc_read_fast(uint16*adc_addr,uint16adc_num,uint8adc_clk_div)

    uint16*adc_addrADC

    uint16adc_numADC [1, 65535]

    uint8adc_clk_divADC = 80M/adc_clk_div [8, 32] 8

    Espressif ! /! 2018.0511 149

  • ! 3. (API)

    3.3.9. system_deep_sleep

    externvoidsystem_adc_read_fast(uint16*adc_addr,uint16adc_num,uint8adc_clk_div);

    os_timer_ttimer;

    voidICACHE_FLASH_ATTRADC_TEST(void*p)

    {

    wifi_set_opmode(NULL_MODE);

    ets_intr_lock(); //closeinterrupt

    uint16adc_addr[10];

    uint16adc_num=10;

    uint8adc_clk_div=8;

    uint32i;

    system_adc_read_fast(adc_addr,adc_num,adc_clk_div);

    for(i=0;i

  • ! 3. (API)

    3.3.10. system_deep_sleep_set_option

    3.3.11. system_phy_set_rfoption

    Deep-sleep API system_deep_sleep option 1

    boolsystem_deep_sleep_set_option(uint8option)

    uint8option Deep-sleep

    0 esp_init_data_default.bin (0~127 byte) byte 108 Deep-sleep deep_sleep_number 0 Deep-sleep (byte 108 + 1) Deep-sleep

    - deep_sleep_number

  • ! 3. (API)

    3.3.12. system_phy_set_powerup_option

    3.3.13. system_phy_set_max_tpw

    3.3.14. system_phy_set_tpw_via_vdd33

    uint8option Deep-sleep

    0 esp_init_data_default.bin (0~127 byte) byte 108 Deep-sleep deep_sleep_number 0 Deep-sleep (byte 108 + 1) Deep-sleep

    - deep_sleep_number

  • ! 3. (API)

    3.3.15. system_set_os_print

    3.3.16. system_print_meminfo

    3.3.17. system_get_free_heap_size

    3.3.18. system_os_task

    voidsystem_phy_set_tpw_via_vdd33(uint16vdd33)

    uint16vdd33 VDD33 1/1024V[1900, 3300]

    log

    voidsystem_set_os_print(uint8onoff)

    uint8onoff

    0 1

    data/rodata/bss/heap

    voidsystem_print_meminfo(void)

    heap

    uint32system_get_free_heap_size(void)

    uint32 heap

    3 0/1/2

    boolsystem_os_task(os_task_ttask,uint8prio,os_event_t*queue,uint8qlen)

    os_task_ttask

    uint8prio 0/1/20 3

    os_event_t*queue

    uint8qlen

    Espressif ! /! 2018.0515 149

  • ! 3. (API)

    3.3.19. system_os_post

    3.3.20. system_get_time

    true

    false

    #defineSIG_RX 0#defineTEST_QUEUE_LEN4os_event_t*testQueue;

    voidtest_task(os_event_t*e){switch(e->sig){caseSIG_RX:os_printf(sig_rx%c/n,(char)e->par);break;default:break;}}

    voidtask_init(void){testQueue=(os_event_t*)os_malloc(sizeof(os_event_t)*TEST_QUEUE_LEN);system_os_task(test_task,USER_TASK_PRIO_0,testQueue,TEST_QUEUE_LEN);}

    boolsystem_os_post(uint8prio,os_signal_tsig,os_param_tpar)

    uint8prio

    os_signal_tsig

    os_param_tpar

    true

    false

    voidtask_post(void){system_os_post(USER_TASK_PRIO_0,SIG_RX,a);}

    sig_rxa

    s

    uint32system_get_time(void)

    s

    Espressif ! /! 2018.0516 149

  • ! 3. (API)

    3.3.21. system_get_rtc_time

    3.3.22. system_rtc_clock_cali_proc

    3.3.23. system_rtc_mem_write

    RTC RTC

    system_get_rtc_time 10 10 RTC system_rtc_clock_cali_proc 5.75 1 RTC 5.75 s 10 x 5.75 = 57.5 s

    system_restart RTC EXT_RST CHIP_EN Deep-sleep RTC

    EXT_RSTRTC memory RTC timer

    RTC memory RTC timer

    system_restartRTC memory RTC timer

    RTC memory RTC timer

    CHIP_EN RTC memory RTC timer

    uint32system_get_rtc_time(void)

    RTC

    RTC

    RTC

    RTC RTC

    uint32system_rtc_clock_cali_proc(void)

    RTC sbit11 ~ bit0

    os_printf(clkcal:%d\r\n,system_rtc_clock_cali_proc()>>12);

    RTC

    Deep-sleep RTC RTC memory user data 512 bytes

    ||||256bytes|512bytes|

    RTC memory 4 des_addr block number block 4 user data des_addr 256/4 = 64save_size

    Espressif ! /! 2018.0517 149

  • ! 3. (API)

    3.3.24. system_rtc_mem_read

    3.3.25. system_uart_swap

    3.3.26. system_uart_de_swap

    boolsystem_rtc_mem_write(uint32des_addr,void*src_addr,uint32save_size)

    uint32des_addr rtc memory des_addr >=64

    void*src_addr

    uint32save_size

    true

    false

    RTC memory user data 512 bytes

    ||||256bytes|512bytes|

    RTC memory 4 des_addr block number block 4 user data des_addr 256/4 = 64save_size

    boolsystem_rtc_mem_read(uint32src_addr,void*des_addr,uint32save_size)

    uint32des_addr rtc memory des_addr >=64

    void*src_addr

    uint32save_size

    true

    false

    UART0 MTCK UART0 RXMTDO UART0 TX MTDO (U0RTS) MTCK (U0CTS) UART0 UART0 ROM log

    voidsystem_uart_swap(void)

    UART0 UART0 MTCKMTDO UART0

    voidsystem_uart_de_swap(void)

    Espressif ! /! 2018.0518 149

  • ! 3. (API)

    3.3.27. system_get_boot_version

    3.3.28. system_get_userbin_addr

    3.3.29. system_get_boot_mode

    3.3.30. system_restart_enhance

    boot

    uint8system_get_boot_version(void)

    boot

    boot >= 3 boot system_restart_enhance

    user binuser1.bin user2.bin

    uint32system_get_userbin_addr(void)

    user bin

    boot

    uint8system_get_boot_mode(void)

    #defineSYS_BOOT_ENHANCE_MODE0#defineSYS_BOOT_NORMAL_MODE1

    boot

    boot user1.bin user2.bin

    boot

    boolsystem_restart_enhance(uint8bin_type,uint32bin_addr)

    uint8bin_typebin

    - #defineSYS_BOOT_NORMAL_BIN0//user1.binuser2.bin

    - #defineSYS_BOOT_TEST_BIN1//testbin

    uint32bin_addrbin

    true

    false

    Espressif ! /! 2018.0519 149

  • ! 3. (API)

    3.3.31. system_update_cpu_req

    3.3.32. system_get_cpu_freq

    3.3.33. system_get_flash_size_map

    SYS_BOOT_TEST_BIN

    CPU 80 MHz

    80 MHz CPU UARTSPI CPU

    boolsystem_update_cpu_freq(uint8freq)

    uint8freqCPU

    #defineSYS_CPU_80MHz80

    #defineSYS_CPU_160MHz160

    true

    false

    CPU

    uint8system_get_cpu_freq(void)

    CPU MHz

    Flash size Flash map

    Flash map ESP8266 SDK

    enumflash_size_map{

    FLASH_SIZE_4M_MAP_256_256=0,

    FLASH_SIZE_2M,

    FLASH_SIZE_8M_MAP_512_512,

    FLASH_SIZE_16M_MAP_512_512,

    FLASH_SIZE_32M_MAP_512_512,

    FLASH_SIZE_16M_MAP_1024_1024,

    FLASH_SIZE_32M_MAP_1024_1024,

    FLASH_SIZE_64M_MAP_1024_1024,

    FLASH_SIZE_128M_MAP_1024_1024,

    };

    enumflash_size_mapsystem_get_flash_size_map(void)

    flash map

    Espressif ! /! 2018.0520 149

    http://www.espressif.com/sites/default/files/documentation/2a-esp8266-sdk_getting_started_guide_cn.pdf

  • ! 3. (API)

    3.3.34. system_get_rst_info

    3.3.35. system_soft_wdt_stop

    3.3.36. system_soft_wdt_restart

    enumrst_reason{

    REANSON_DEFAULT_RST =0, //normalstartupbypoweron

    REANSON_WDT_RST =1, //hardwarewatchdogreset

    //exceptionreset,GPIOstatuswontchange

    REANSON_EXCEPTION_RST =2,

    //softwarewatchdogreset,GPIOstatuswontchange

    REANSON_SOFT_WDT_RST =3,

    //softwarerestart,system_restart,GPIOstatuswontchange

    REANSON_SOFT_RESTART =4,

    REANSON_DEEP_SLEEP_AWAKE =5, //wakeupfromdeep-sleep

    REANSON_EXT_SYS_RST =6, //externalsystemreset

    };

    structrst_info{

    uint32reason;//enumrst_reason

    uint32exccause;

    uint32epc1;//theaddressthaterroroccurred

    uint32epc2;

    uint32epc3;

    uint32excvaddr;

    uint32depc;

    };

    structrst_info*system_get_rst_info(void)

    5s

    voidsystem_soft_wdt_stop(void)

    system_soft_wdt_stop

    Espressif ! /! 2018.0521 149

  • ! 3. (API)

    3.3.37. system_soft_wdt_feed

    3.3.38. system_show_malloc

    3.3.39. os_memset

    voidsystem_soft_wdt_restart(void)

    voidsystem_soft_wdt_feed(void)

    user_config.h #defineMEMLEAK_DEBUG ESP8266_NONOS_SDK\included\mem.h

    voidsystem_show_malloc(void)

    C

    os_memset(void*s,intch,size_tn)

    void*s

    intch

    size_tn

    uint8buffer[32];

    os_memset(buffer,0,sizeof(buffer));

    Espressif ! /! 2018.0522 149

  • ! 3. (API)

    3.3.40. os_memcpy

    3.3.41. os_strlen

    3.3.42. os_printf

    3.3.43. os_bzero

    C

    os_memcpy(void*des,void*src,size_tn)

    void*des

    void*src

    size_tn

    uint8buffer[4]={0};

    os_memcpy(buffer,abcd,4);

    C

    os_strlen(char*s)

    char*s

    char*ssid=ESP8266;

    os_memcpy(softAP_config.ssid,ssid,os_strlen(ssid));

    UART 0 IOT_Demo uart_init os_printf UART 1 os_install_putc1((void*)uart1_write_char);

    125

    voidos_printf(constchar*s)

    const char*s

    os_printf(SDKversion:%s\n,system_get_sdk_version());

    p n \0

    voidos_bzero(void*p,size_tn)

    void*p

    size_tn

    Espressif ! /! 2018.0523 149

  • ! 3. (API)

    3.3.44. os_delay_us

    3.3.45. os_install_putc1

    3.3.46. os_random

    3.3.47. os_get_random

    3.3.48. user_rf_cal_sector_set

    65535 s

    voidos_delay_us(uint16us)

    uint16us

    voidos_install_putc1(void(*p)(charc))

    void(*p)(charc)

    UART.cuart_init os_install_putc1((void*)uart1_write_char) os_printf UART 1 os_printf UART 0

    unsignedlongos_random(void)

    intos_get_random(unsignedchar*buf,size_tlen)

    unsignedchar*buf

    size_tlen

    true

    false

    intret=os_get_random((unsignedchar*)temp,7);os_printf("ret%d,value0x%08x%08x\n\r",ret,temp[1],temp[0]);

    RF_CAL Flash

    Espressif ! /! 2018.0524 149

  • ! 3. (API)

    SDK RF_CAL Flash

    SDK 4 RF_CAL SDK

    RF_CAL blank.bin RF_CAL esp_init_data.binesp_init_data.bin

    uint32user_rf_cal_sector_set(void)

    RF_CAL Flash

    RF Flash 5

    uint32user_rf_cal_sector_set(void)

    {

    enumflash_size_mapsize_map=system_get_flash_size_map();

    uint32rf_cal_sec=0;

    switch(size_map){

    caseFLASH_SIZE_4M_MAP_256_256:

    rf_cal_sec=128-5;

    break;

    caseFLASH_SIZE_8M_MAP_512_512:

    rf_cal_sec=256-5;

    break;

    caseFLASH_SIZE_16M_MAP_512_512:

    caseFLASH_SIZE_16M_MAP_1024_1024:

    rf_cal_sec=512-5;

    break;

    caseFLASH_SIZE_32M_MAP_512_512:

    caseFLASH_SIZE_32M_MAP_1024_1024:

    rf_cal_sec=512-5;

    break;

    caseFLASH_SIZE_64M_MAP_1024_1024:

    rf_cal_sec=2048-5;

    break;

    caseFLASH_SIZE_128M_MAP_1024_1024:

    rf_cal_sec=4096-5;

    break;

    default:

    rf_cal_sec=0;

    break;

    }

    returnrf_cal_sec;

    }

    Espressif ! /! 2018.0525 149

  • ! 3. (API)

    3.3.49. system_phy_freq_trace_enable

    3.3.50. system_deep_sleep_instant

    3.4. SPI Flash SPI Flash /ESP8266_NONOS_SDK/include/spi_flash.h

    system_param_xxx /ESP8266_NONOS_SDK/include/user_interface.h

    SPI Flash ESP8266 Flash

    3.4.1. spi_flash_get_id

    RF

    voidsystem_phy_freq_trace_enable(boolenable)

    boolenable01

    RF

    user_rf_pre_init system_phy_freq_trace_enable(1);

    Deep-sleep user_init

    XPD_DCDC 0 EXT_RSTB Deep-sleep

    system_deep_sleep_instant(0) GPIO RST

    Deep-sleep Wi-Fi Wi-Fi system_deep_sleep

    boolsystem_deep_sleep_instant(uint64time_in_us)

    uint64time_in_uss

    time_in_us (time_in_us/cali)

  • ! 3. (API)

    3.4.2. spi_flash_erase_sector

    3.4.3. spi_flash_write

    3.4.4. spi_flash_read

    uint32spi_flash_get_id(void)

    spiflashid

    Flash

    SpiFlashOpResultspi_flash_erase_sector(uint16sec)

    uint16sec 0 4 KB

    typedefenum{SPI_FLASH_RESULT_OK,SPI_FLASH_RESULT_ERR,SPI_FLASH_RESULT_TIMEOUT}SpiFlashOpResult;

    FlashFlash 4

    SpiFlashOpResultspi_flash_write(uint32des_addr,uint32*src_addr,uint32size)

    uint32des_addr Flash

    uint32*src_addr

    uint32size byte 4

    typedefenum{SPI_FLASH_RESULT_OK,SPI_FLASH_RESULT_ERR,SPI_FLASH_RESULT_TIMEOUT}SpiFlashOpResult;

    Flash Flash 4

    SpiFlashOpResultspi_flash_read(uint32src_addr,uint32*des_addr,uint32size)

    uint32des_addr Flash

    uint32*des_addr

    uint32size byte 4

    Espressif ! /! 2018.0527 149

  • ! 3. (API)

    3.4.5. system_param_save_with_protect

    3.4.6. system_param_load

    typedefenum{SPI_FLASH_RESULT_OK,SPI_FLASH_RESULT_ERR,SPI_FLASH_RESULT_TIMEOUT}SpiFlashOpResult;

    uint32value;

    uint8*addr=(uint8*)&value;

    spi_flash_read(0x3E*SPI_FLASH_SEC_SIZE,(uint32*)addr,4);

    os_printf("0x3Esec:%02x%02x%02x%02x\r\n",addr[0],addr[1],addr[2],addr[3]);

    FlashFlash 4

    Flash 3 sector4 KB sector 1 sector sector 0 sector 1 sector 2 flag sector sector 0 sector 1

    SPI Flash ESP8266 Flash

    boolsystem_param_save_with_protect(uint16start_sec,void*param,uint16len)

    uint16start_sec 3 sector sector 0 IOT_Demo 0x3D000 3 sector34 KB start_sec 0x3D

    void*param

    uint16len 1 sector 41024

    true

    false

    FlashFlash 4

    Flash 3 sector4 KB sector 1 sector sector 0 sector 1 sector 2 flag sector sector 0 sector 1

    SPI Flash ESP8266 Flash

    Espressif ! /! 2018.0528 149

    http://www.espressif.com/zh-hans/support/download/documents?keys=ESP8266+Flash+%E8%AF%BB%E5%86%99%E8%AF%B4%E6%98%8Ehttp://www.espressif.com/zh-hans/support/download/documents?keys=ESP8266+Flash+%E8%AF%BB%E5%86%99%E8%AF%B4%E6%98%8E

  • ! 3. (API)

    3.4.7. spi_flash_set_read_func

    3.4.8. spi_flash_erase_protect_enable

    3.4.9. spi_flash_erase_protect_disable

    boolsystem_param_load(

    uint16start_sec,

    uint16offset,

    void*param,

    uint16len)

    uint16start_sec 3 sector sector 0 IOT_Demo 0x3D000 3 sector34 KB start_sec 0x3D 0x3E 0x3F

    uint16offset sector

    void*param

    uint16len 1 sector offset+len 4*1024

    true

    false

    SPI Flash

    SPI overlap ESP8266_NONOS_SDK\driver_lib\driver\spi_overlap.c

    voidspi_flash_set_read_func(user_spi_flash_readread)

    typedefSpiFlashOpResult(*user_spi_flash_read)(

    SpiFlashChip*spi,uint32src_addr,uint32*des_addr,uint32size)

    flash flash

    boolspi_flash_erase_protect_enable(void)

    True:

    False:

    flash

    Espressif ! /! 2018.0529 149

  • ! 3. (API)

    boolspi_flash_erase_protect_disable(void)

    True:

    False:

    Espressif ! /! 2018.0530 149

  • ! 3. (API)

    3.5. Wi-Fi Wi-Fi /ESP8266_NONOS_SDK/include/user_interface.h

    wifi_station_xxx ESP8266 Station ESP8266 Station

    wifi_softap_xxx ESP8266 SoftAP ESP8266 SoftAP

    ESP8266 station OPENWEPWPAPSKWPA2PSKAUTOTKIPAESWEP

    ESP8266 softAP OPENWPAPSKWPA2PSKAUTOTKIPAES group key TKIP AES

    Flash Flash 16 KB

    3.5.1. wifi_get_opmode

    3.5.2. wifi_get_opmode_default

    3.5.3. wifi_set_opmode

    Wi-Fi

    uint8wifi_get_opmode(void)

    Wi-Fi

    0x01Station 0x02SoftAP 0x03Station+SoftAP

    Flash Wi-Fi

    uint8wifi_get_opmode_default(void)

    Wi-Fi

    0x01Station 0x02SoftAP 0x03Station+SoftAP

    Wi-Fi StationSoftAP Station+SoftAP Flash

    SoftAP

    Espressif ! /! 2018.0531 149

  • ! 3. (API)

    3.5.4. wifi_set_opmode_current

    3.5.5. wifi_station_get_config

    3.5.6. wifi_station_get_config_default

    ESP8266_NONOS_SDK_V0.9.2 system_restart()

    ESP8266_NONOS_SDK_V0.9.2

    Flash

    boolwifi_set_opmode(uint8opmode)

    uint8opmodeWi-Fi

    0x01Station 0x02SoftAP 0x03Station+SoftAP

    true

    false

    Wi-Fi StationSoftAP Station + SoftAP Flash

    boolwifi_set_opmode_current(uint8opmode)

    uint8opmodeWi-Fi

    0x01Station 0x02SoftAP 0x03Station+SoftAP

    true

    false

    Wi-Fi Station

    boolwifi_station_get_config(structstation_config*config)

    structstation_config*configWi-Fi Station

    true

    false

    Wi-Fi Station Flash

    boolwifi_station_get_config_default(structstation_config*config)

    structstation_config*configWi-Fi Station

    true

    false

    Espressif ! /! 2018.0532 149

  • ! 3. (API)

    3.5.7. wifi_station_set_config

    3.5.8. wifi_station_set_config_current

    Wi-Fi Station Flash

    ESP8266 Station

    wifi_station_set_config user_init ESP8266 Station AP wifi_station_connect

    wifi_station_connect AP

    station_config.bssid_set 0 AP MAC AP 1

    Flash

    boolwifi_station_set_config(structstation_config*config)

    structstation_config*configWi-Fi Station

    true

    false

    voidICACHE_FLASH_ATTRuser_set_station_config(void){charssid[32]=SSID;charpassword[64]=PASSWORD;structstation_configstationConf;

    stationConf.bssid_set=0;//neednotcheckMACaddressofAP

    os_memcpy(&stationConf.ssid,ssid,32);os_memcpy(&stationConf.password,password,64);wifi_station_set_config(&stationConf);

    }

    voiduser_init(void){wifi_set_opmode(STATIONAP_MODE);//SetsoftAP+stationmode

    user_set_station_config();

    }

    Wi-Fi Station Flash

    Espressif ! /! 2018.0533 149

  • ! 3. (API)

    3.5.9. wifi_station_set_cert_key

    ESP8266 Station

    wifi_station_set_config user_init ESP8266 Station AP wifi_station_connect

    wifi_station_connect AP

    station_config.bssid_set 0 AP MAC AP 1

    Flash

    boolwifi_station_set_config_current(structstation_config*config)

    structstation_config*configWi-Fi Station

    true

    false

    wifi_station_set_enterprise_ce