ESP32 OTA空中升级步骤详细说明

ESP32 OTA空中升级步骤详细说明

 

                                                                                                                                                                          张婷婷   2019.07.22

 

目录

第1节 http本地空中升级... 2

1.1打开服务器... 2

1.2修改官方例程... 2

1.2.1 修改库文件esp_https_ota.c. 2

1.2.2 修改例程simple_ota_example.c. 3

1.2.2.1 修改OTA分区为双 OTA 分区... 4

1.2.2.2 修改下载端口 port 5

1.2.2.3 修改WiFi账号密码以及url 5

1.3 编译下载... 7

1.4 实验验证... 7

 

 

 

第1节 http本地空中升级

1.1打开服务器

官方编译链内 Python 有一个内置的 HTTP 服务器,可以直接使用它;以esp-idf-v3.1.4\examples\get-started\hello_world作为需要更新的固。

打开mingw32官方编译链,输入以下指令:

 

cd $IDF_PATH/examples/get-started/hello_world //进入 helloworld 路径make                                              //编译

cd build                                    //进入编译文件.bin 目录python -m SimpleHTTPServer 8070               //运行 http 服务器(本地)

   

ESP32 OTA空中升级步骤详细说明_第1张图片

 

服务器运行后, 构建目录的内容可以通过网址 http://localhost:8070/ 浏览到。升级期间需要保持服务器开启,升级完成后如果想要关闭服务器关闭这个编译链即可。

1.2修改官方例程

1.2.1 修改库文件esp_https_ota.c

修改库文件esp-idf-v3.1.4\components\esp_https_ota\src下的esp_https_ota.c内容:注释下图两个红框中内容,这两处是https空中升级用到的。

ESP32 OTA空中升级步骤详细说明_第2张图片

 

1.2.2 修改例程simple_ota_example.c

接下来修改例程,这里使用esp-idf-v3.1.4\examples\system\ota\simple_ota_example

修改其main文件夹下的simple_ota_example.c中内容:修改替换如下图

ESP32 OTA空中升级步骤详细说明_第3张图片

 

最后修改文件配置,另外再打开一个mingw32官方编译链修改simple_ota_example

配置,输入以下指令:

 

cd $IDF_PATH examples\system\ota\simple_ota_example //进入路径

make menuconfig                                        //进入配置

 

1.2.2.1 修改OTA分区为OTA 分区

首次进行 OTA 升级时, OTA example OTA_0 分区烧录目标 App, 并在烧录完成后, 更新 OTA data 分区数据并重启。系统重启时获取 OTA data 分区数据进行计算, 决定此后加载 OTA_0 分区的 App 执行(而不是默认的 Factory App 分区内的 App) , 从而实现升级。同理, 若某次升级后 ESP32 已经在执行 OTA_0 内的 App, 此时再升级时, OTA Demo 就会向 OTA_1 分区写入目标 App。 再次启动后, 执行 OTA_1 分区实现升级。 以此类推, 升级的目标 App 始终在 OTA_0OTA_1 两个分区之间交互烧录, 不会影响到出厂时的 Factory App 固件。

ESP32 OTA空中升级步骤详细说明_第4张图片

 

1.2.2.2 修改下载端口 port

此次的example下载是通过串口下载的,修改配置文件中下载端口为自己下载器的端口。Port会应不同电脑不同下载器而不同,写入自己实际的COM口,我的是COM6。

ESP32 OTA空中升级步骤详细说明_第5张图片

1.2.2.3 修改WiFi账号密码以及url

WiFi账号密码是ESP32启动后联网的,由于http模式是本地模式,所以WiFi账号和密码需要和第一节打开服务器的电脑在同一个局域网内。url就是ESP32 连接上服务器之后要去访问的目标地址。

ESP32 OTA空中升级步骤详细说明_第6张图片

ESP32 OTA空中升级步骤详细说明_第7张图片

WiFi SSID和WiFi Password填上你电脑连接的WiFi账号密码,如果你的电脑是网线联网这里只要保证填入的WiFi账号密码是该网关下的无线网络即可,url马赛克部分192.168.xx.xx是本机IP,可通过运行cmd输入ipconfig查看,这里填上自己本机ip 。

以上三步修改均需要单步保存,即选择 <Save> 。至此修改就全部完成了,单步全保存之后一路点击 <Exit> 推出即可,接下来就是编译下载了。

1.3 编译下载

Windows下的编译非常之慢,由于上面修改了配置文件所以编译是更加慢的。输入 make 编译,大约需要5-10min,耐心等待一会。

编译成功后输入 make erase_flash flash 全擦除并下载。

 

ESP32 OTA空中升级步骤详细说明_第8张图片

1.4 实验验证

编译下载通过之后,就可以运行了,等待ESP32 成功联网之后就开始连接服务器了,ping通服务器之后就开始下载 hello-world.bin ,这个过程需要3min左右等待日志打印结果即可。以下是日志文件:灰色部分是simple_ota_example例程的日志文件,青色部分就是hello-world例程的日志文件。

 

ets Jun  8 2016 00:22:57

 

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:2

load:0x3fff0018,len:4

load:0x3fff001c,len:5812

load:0x40078000,len:9188

ho 0 tail 12 room 4

load:0x40080000,len:6092

entry 0x4008032c

[0;32mI (30) boot: ESP-IDF v3.1.4-dirty 2nd stage bootloader[0m

[0;32mI (30) boot: compile time 15:28:57[0m

[0;32mI (31) boot: Enabling RNG early entropy source...[0m

[0;32mI (35) boot: SPI Speed      : 40MHz[0m

[0;32mI (40) boot: SPI Mode       : DIO[0m

[0;32mI (44) boot: SPI Flash Size : 4MB[0m

[0;32mI (48) boot: Partition Table:[0m

[0;32mI (51) boot: ## Label            Usage          Type ST Offset   Length[0m

[0;32mI (59) boot:  0 nvs              WiFi data        01 02 00009000 00004000[0m

[0;32mI (66) boot:  1 otadata          OTA data         01 00 0000d000 00002000[0m

[0;32mI (73) boot:  2 phy_init         RF data          01 01 0000f000 00001000[0m

[0;32mI (81) boot:  3 factory          factory app      00 00 00010000 00100000[0m

[0;32mI (88) boot:  4 ota_0            OTA app          00 10 00110000 00100000[0m

[0;32mI (96) boot:  5 ota_1            OTA app          00 11 00210000 00100000[0m

[0;32mI (103) boot: End of partition table[0m

[0;32mI (108) boot: Defaulting to factory image[0m

[0;32mI (112) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x1a420 (107552) map[0m

[0;32mI (159) esp_image: segment 1: paddr=0x0002a448 vaddr=0x3ffb0000 size=0x033fc ( 13308) load[0m

[0;32mI (164) esp_image: segment 2: paddr=0x0002d84c vaddr=0x40080000 size=0x00400 (  1024) load[0m

[0;32mI (166) esp_image: segment 3: paddr=0x0002dc54 vaddr=0x40080400 size=0x023bc (  9148) load[0m

[0;32mI (178) esp_image: segment 4: paddr=0x00030018 vaddr=0x400d0018 size=0x7f0b8 (520376) map[0m

[0;32mI (366) esp_image: segment 5: paddr=0x000af0d8 vaddr=0x400827bc size=0x0e2c8 ( 58056) load[0m

[0;32mI (400) boot: Loaded app from partition at offset 0x10000[0m

[0;32mI (400) boot: Disabling RNG early entropy source...[0m

[0;32mI (401) cpu_start: Pro cpu up.[0m

[0;32mI (404) cpu_start: Starting app cpu, entry point is 0x40080fc8[0m

[0;32mI (0) cpu_start: App cpu up.[0m

[0;32mI (415) heap_init: Initializing. RAM available for dynamic allocation:[0m

[0;32mI (422) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m

[0;32mI (428) heap_init: At 3FFB9440 len 00026BC0 (154 KiB): DRAM[0m

[0;32mI (434) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m

[0;32mI (440) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m

[0;32mI (447) heap_init: At 40090A84 len 0000F57C (61 KiB): IRAM[0m

[0;32mI (453) cpu_start: Pro cpu start user code[0m

[0;32mI (135) cpu_start: Starting scheduler on PRO CPU.[0m

[0;32mI (0) cpu_start: Starting scheduler on APP CPU.[0m

I (179) wifi: wifi driver task: 3ffc0b90, prio:23, stack:3584, core=0

I (179) wifi: wifi firmware version: ad331b4

I (179) wifi: config NVS flash: enabled

I (179) wifi: config nano formating: disabled

[0;32mI (189) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m

[0;32mI (199) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m

I (219) wifi: Init dynamic tx buffer num: 32

I (219) wifi: Init data frame dynamic rx buffer num: 32

I (219) wifi: Init management frame dynamic rx buffer num: 32

I (219) wifi: Init management short buffer num: 32

I (229) wifi: Init static rx buffer size: 1600

I (229) wifi: Init static rx buffer num: 10

I (239) wifi: Init dynamic rx buffer num: 32

[0;32mI (239) simple_ota_example: Setting WiFi configuration SSID future1324...[0m

[0;32mI (309) phy: phy_version: 4008, c9ae59f, Jan 25 2019, 16:54:06, 0, 0[0m

I (319) wifi: mode : sta (bc:dd:c2:ca:83:40)

[0;32mI (319) simple_ota_example: Starting OTA example...[0m

I (1159) wifi: n:7 2, o:1 0, ap:255 255, sta:7 2, prof:1

I (2149) wifi: state: init -> auth (b0)

I (2149) wifi: n:7 0, o:7 2, ap:255 255, sta:7 0, prof:1

I (2149) wifi: state: auth -> assoc (0)

I (2179) wifi: state: assoc -> run (10)

I (2239) wifi: connected with future1324, channel 7

I (2239) wifi: pm start, type: 1

 

I (3019) wifi: n:7 2, o:7 0, ap:255 255, sta:7 2, prof:1

[0;32mI (3179) event: sta ip: 192.168.0.184, mask: 255.255.255.0, gw: 192.168.0.1[0m

[0;32mI (3179) simple_ota_example: Connect to Wifi ! Start to Connect to Server....[0m

[0;32mI (3279) esp_https_ota: Starting OTA...[0m

[0;32mI (3279) esp_https_ota: Writing to partition subtype 16 at offset 0x110000[0m

[0;32mI (3449) esp_https_ota: esp_ota_begin succeeded[0m

[0;32mI (3449) esp_https_ota: Please Wait. This may take time[0m

[0;32mI (6139) esp_https_ota: Connection closed,all data received[0m

[0;32mI (6139) esp_image: segment 0: paddr=0x00110020 vaddr=0x3f400020 size=0x071c4 ( 29124) map[0m

[0;32mI (6169) esp_image: segment 1: paddr=0x001171ec vaddr=0x3ffb0000 size=0x022a0 (  8864) [0m

[0;32mI (6179) esp_image: segment 2: paddr=0x00119494 vaddr=0x40080000 size=0x00400 (  1024) [0m

[0;32mI (6179) esp_image: segment 3: paddr=0x0011989c vaddr=0x40080400 size=0x06774 ( 26484) [0m

[0;32mI (6209) esp_image: segment 4: paddr=0x00120018 vaddr=0x400d0018 size=0x111c8 ( 70088) map[0m

[0;32mI (6259) esp_image: segment 5: paddr=0x001311e8 vaddr=0x40086b74 size=0x02198 (  8600) [0m

[0;32mI (6269) esp_image: segment 0: paddr=0x00110020 vaddr=0x3f400020 size=0x071c4 ( 29124) map[0m

[0;32mI (6289) esp_image: segment 1: paddr=0x001171ec vaddr=0x3ffb0000 size=0x022a0 (  8864) [0m

[0;32mI (6299) esp_image: segment 2: paddr=0x00119494 vaddr=0x40080000 size=0x00400 (  1024) [0m

[0;32mI (6309) esp_image: segment 3: paddr=0x0011989c vaddr=0x40080400 size=0x06774 ( 26484) [0m

[0;32mI (6329) esp_image: segment 4: paddr=0x00120018 vaddr=0x400d0018 size=0x111c8 ( 70088) map[0m

[0;32mI (6389) esp_image: segment 5: paddr=0x001311e8 vaddr=0x40086b74 size=0x02198 (  8600) [0m

[0;32mI (6399) esp_https_ota: esp_ota_set_boot_partition succeeded[0m

I (6399) wifi: state: run -> init (0)

I (6399) wifi: pm stop, total sleep time: 2183901 us / 7148823 us

 

I (6399) wifi: n:7 0, o:7 2, ap:255 255, sta:7 2, prof:1

I (6419) wifi: flush txq

I (6419) wifi: stop sw txq

I (6419) wifi: lmac stop hw txq

ets Jun  8 2016 00:22:57

 

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:2

load:0x3fff0018,len:4

load:0x3fff001c,len:5812

load:0x40078000,len:9188

ho 0 tail 12 room 4

load:0x40080000,len:6092

entry 0x4008032c

[0;32mI (30) boot: ESP-IDF v3.1.4-dirty 2nd stage bootloader[0m

[0;32mI (31) boot: compile time 15:28:57[0m

[0;32mI (31) boot: Enabling RNG early entropy source...[0m

[0;32mI (36) boot: SPI Speed      : 40MHz[0m

[0;32mI (40) boot: SPI Mode       : DIO[0m

[0;32mI (44) boot: SPI Flash Size : 4MB[0m

[0;32mI (48) boot: Partition Table:[0m

[0;32mI (52) boot: ## Label            Usage          Type ST Offset   Length[0m

[0;32mI (59) boot:  0 nvs              WiFi data        01 02 00009000 00004000[0m

[0;32mI (66) boot:  1 otadata          OTA data         01 00 0000d000 00002000[0m

[0;32mI (74) boot:  2 phy_init         RF data          01 01 0000f000 00001000[0m

[0;32mI (81) boot:  3 factory          factory app      00 00 00010000 00100000[0m

[0;32mI (89) boot:  4 ota_0            OTA app          00 10 00110000 00100000[0m

[0;32mI (96) boot:  5 ota_1            OTA app          00 11 00210000 00100000[0m

[0;32mI (104) boot: End of partition table[0m

[0;32mI (108) esp_image: segment 0: paddr=0x00110020 vaddr=0x3f400020 size=0x071c4 ( 29124) map[0m

[0;32mI (127) esp_image: segment 1: paddr=0x001171ec vaddr=0x3ffb0000 size=0x022a0 (  8864) load[0m

[0;32mI (131) esp_image: segment 2: paddr=0x00119494 vaddr=0x40080000 size=0x00400 (  1024) load[0m

[0;32mI (135) esp_image: segment 3: paddr=0x0011989c vaddr=0x40080400 size=0x06774 ( 26484) load[0m

[0;32mI (155) esp_image: segment 4: paddr=0x00120018 vaddr=0x400d0018 size=0x111c8 ( 70088) map[0m

[0;32mI (180) esp_image: segment 5: paddr=0x001311e8 vaddr=0x40086b74 size=0x02198 (  8600) load[0m

[0;32mI (189) boot: Loaded app from partition at offset 0x110000[0m

[0;32mI (189) boot: Disabling RNG early entropy source...[0m

[0;32mI (191) cpu_start: Pro cpu up.[0m

[0;32mI (195) cpu_start: Starting app cpu, entry point is 0x40080e60[0m

[0;32mI (186) cpu_start: App cpu up.[0m

[0;32mI (206) heap_init: Initializing. RAM available for dynamic allocation:[0m

[0;32mI (212) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m

[0;32mI (218) heap_init: At 3FFB32F0 len 0002CD10 (179 KiB): DRAM[0m

[0;32mI (225) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m

[0;32mI (231) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m

[0;32mI (238) heap_init: At 40088D0C len 000172F4 (92 KiB): IRAM[0m

[0;32mI (244) cpu_start: Pro cpu start user code[0m

[0;32mI (262) cpu_start: Starting scheduler on PRO CPU.[0m

[0;32mI (0) cpu_start: Starting scheduler on APP CPU.[0m

Hello world!

This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash

Restarting in 10 seconds...

Restarting in 9 seconds...

Restarting in 8 seconds...

Restarting in 7 seconds...

Restarting in 6 seconds...

Restarting in 5 seconds...

Restarting in 4 seconds...

Restarting in 3 seconds...

Restarting in 2 seconds...

你可能感兴趣的:(ESP32 OTA空中升级步骤详细说明)