esp32 serial, Bluetooth and other ways OTA

Preface

esp32 official routine routines provided by OTA via wifi network connection. Although convenient routine may not be applicable in all situations, sometimes we want to OTA operate via Bluetooth, serial, or otherwise. Developers will have the following OTA-related functions to parse, yes OTA can continue in different ways.

 

OTA principle

Simply put : OTA basic process is as follows:

1, the receiving program

2, written in Flash

3, modify the boot, so that the next boot time to start writing the new program.

esp32 specific implementation of the two regions will be generally used to write a program. The figure is a case where a burn, OTA function program in the flash. For details, see: https://blog.csdn.net/qq_24550925/article/details/85857351

figure 1

In summary, as long as the data is received, it can be OTA upgrade from the principle point of view. The specific data source can be varied.

Required configuration

1, ota need to function properly divide the partition table, you can divide themselves can also use the typical division officials have provided a good way. Using the official partition table setting is as follows:

输入make menuconfig 中:Partition Table -> Partition Table 选择 Factory app, two OTA definitions。

 

2, the need to ensure sufficient flash space and is properly configured, choose according to their own circumstances chip. Official typical chip 4M, the following is a typical configuration:

Enter the make menuconfig in: Serial flasher config -> Flash size selection 4 MB

 

OTA correlation function and program flow

Analysis of the correlation function at OTA upgrade wifi function used, in particular, it is esp-idf / components / esp_https_ota / src / esp_https_ota.c file, OTA function esp_https_ota (const esp_http_client_config_t * config) function used. Specific procedures are as follows. Wherein after finishing work can be done by receiving the return value of the function 2 can be determined whether the upgrade was successful.

#include " esp_ota_ops.h " 

// Preparations 
esp_err_t ERR = ESP_OK; 
esp_ota_handle_t update_handle = 0 ;
 const esp_partition_t * update_partition = NULL; 
update_partition = esp_ota_get_next_update_partition (NULL); 
ERR = esp_ota_begin (update_partition, OTA_SIZE_UNKNOWN, & update_handle); 


// data receiving 
the while (received data) 
{ 
    ERR   = esp_ota_write (update_handle, ( const  void * ) data, len); 
} 


// after receiving the finishing touches 
err = esp_ota_end(update_handle);
err = esp_ota_set_boot_partition(update_partition);

//软件复位
esp_restart();

 

 

Guess you like

Origin www.cnblogs.com/zornlink/p/11412232.html