How to make partition scheme in ESP32 industrial PLC
Learn how to split a large code into multiple parts to load it on the PLC controller
8 April, 2021 by
How to make partition scheme in ESP32 industrial PLC
Boot & Work Corp. S.L., Quesada Dani Salvans


Odoo image and text block

 Introduction

An ESP32 flash can contain more than one app, and various types of information (file systems, parameter storage, calibration data, etc.). Because of this reason, there is a partition table that is flashed to 0x8000 in the flash (considering the default offset). The lenght of the partition table is 0xC00 bytes, with a maxium of 95 entries. There is also a MD5 checksum to check the integrity of the partition table, appended after the table data. Each one of the partition table entries has a name (also called label), a type (app, data, etc.), a subtype and the offset in flash where the partition is loaded. One of the main purposes of partitioning schemes is, for example, to split a large code in multiple parts so it can be uploaded to the device. You will see how to do it in this post. 


Requirements

The key points you should consider are as follows: 

  • Industrial ESP32 based PLC (10 I/Os PLC Family or ESP32 PLC Family)

  • Industrial Shields Boards   Read >>

 Related links


Read >>

Basics of SPIFFS File system and Industrial PLC (ESP32).

Read >>

How to control an ESP32 industrial controller via Bluetooth

Read >>

How to program the 10 I/Os ESP32 industrial PLC via Wi-Fi

Read >>

How to find your perfect industrial PLC

Read >>

10 I/Os PLC family products

Read >>

ESP32 PLC family products

 Explanation

First of all, open the Boards document located at the following path in Windows (and the equivalent on Linux, always considering that there may be some differences depending on the location of the path): 

C:\Users\User_Name\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.0.8


This is the Industrial Shields ESP32 configuration file. Although it has a lot of configuration parameters, let's focus on this part: 

############################################
###### ESP32 PLC ###########################
############################################

esp32plc.name=ESP32 PLC Family
esp32plc.upload.tool=esptool_py
esp32plc.upload.maximum_size=1310720
esp32plc.upload.maximum_data_size=327680
esp32plc.upload.wait_for_upload_port=true
esp32plc.upload.speed=460800
esp32plc.serial.disableDTR=true
esp32plc.serial.disableRTS=true
esp32plc.build.mcu=esp32
esp32plc.build.core=industrialshields
esp32plc.build.board=ESP32_DEV
esp32plc.build.f_cpu=240000000L
esp32plc.build.flash_mode=dio
esp32plc.build.flash_size=4MB
esp32plc.build.boot=dio
esp32plc.build.partitions=default
esp32plc.build.defines=
esp32plc.build.flash_freq=80m
esp32plc.build.code_debug=0


The other document to consider is the one found in this path in Windows: 

C:\Users\User_Name\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4


It is also called Boards, but this is the default configuration file for ESP32. From here, let's focus on the different Partition Scheme options: 

esp32.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
esp32.menu.PartitionScheme.default.build.partitions=default
esp32.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
esp32.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
esp32.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT)
esp32.menu.PartitionScheme.default_8MB.build.partitions=default_8MB
esp32.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336
esp32.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS)
esp32.menu.PartitionScheme.minimal.build.partitions=minimal
esp32.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS)
esp32.menu.PartitionScheme.no_ota.build.partitions=no_ota
esp32.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
esp32.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS)
esp32.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
esp32.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
esp32.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS)
esp32.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat
esp32.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152
esp32.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS)
esp32.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat
esp32.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576
esp32.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
esp32.menu.PartitionScheme.huge_app.build.partitions=huge_app
esp32.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
esp32.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
esp32.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
esp32.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
esp32.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT)
esp32.menu.PartitionScheme.fatflash.build.partitions=ffat
esp32.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
esp32.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS)
esp32.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
esp32.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728


In the second file, we can see all the available Partition Scheme options, which can also be consulted in csv format in this other path in Windows: 

C:\Users\User_Name\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.0.8\tools\partitions


Once you have selected the Partition Scheme configuration that you are going to use, you have to put its name in the partitions parameter of the first file. Apart from that, you also have to open the csv document of the configuration that we have chosen to consult the app size (the bold one. In this case we are going to take huge_app as an example). 

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x300000,
eeprom,   data, 0x99,    0x310000,0x1000,
spiffs,   data, spiffs,  0x311000,0xEF000,

Once the size of the application has been queried, you have to convert this value from hex to dec and put in the first Boards file this number in the maximum_size parameter. Finally, the first Boards file (the part from the document) should look like this (with these two bold lines updated): 


############################################
###### ESP32 PLC ###########################
############################################

esp32plc.name=ESP32 PLC Family
esp32plc.upload.tool=esptool_py
esp32plc.upload.maximum_size=3145728
esp32plc.upload.maximum_data_size=327680
esp32plc.upload.wait_for_upload_port=true
esp32plc.upload.speed=460800
esp32plc.serial.disableDTR=true
esp32plc.serial.disableRTS=true
esp32plc.build.mcu=esp32
esp32plc.build.core=industrialshields
esp32plc.build.board=ESP32_DEV
esp32plc.build.f_cpu=240000000L
esp32plc.build.flash_mode=dio
esp32plc.build.flash_size=4MB
esp32plc.build.boot=dio
esp32plc.build.partitions=huge_app
esp32plc.build.defines=
esp32plc.build.flash_freq=80m
esp32plc.build.code_debug=0


And that is all, now you only have to compile and upload the code with Arduino IDE by selecting the right device and port. 

How to make partition scheme in ESP32 industrial PLC
Boot & Work Corp. S.L., Quesada Dani Salvans
8 April, 2021
Share this post
Archive

Looking for your ideal PLC?

Take a look at this product comparison with other industrial controllers Arduino-based.

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>

Do you want more information?

Just fill the form!

Tell me more!