Introduction
Have you ever wondered why the Nextion Editor can upload TFT files faster than any other tool? Simple. It uses a newer version of the Nextion Upload Protocol that allows to skip parts of the TFT file if they haven’t been modified. In practice this means that all of your pictures, fonts, etc (<= ressource section of the TFT file) will be skipped if you did not touch anyone of them. Only the stuff you coded/designed in the editor will be uploaded in that case.
As a lot of other useful information Nextion does not share any details about this improved protocol. However, it is not more complicated than the well-known protocol v1.1; the differences are minor. You should know and understand how that protocol works before continuing.
Ready-to-use Tool
I wrote a Python script called Nexus that implements this improved upload protocol. It can easily be used via command line. The script can be found here: Nexus - Nextion Upload Script
How it works
The faster protocol (let‘s call it v1.2) is essentially the same as v1.1 except for the following differences:
- While v1.1 initiates the upload by sending the
whmi-wri FILE_SIZE,BAUD_RATE,DONT_CARE
command, v1.2 uses
whmi-wris FILE_SIZE,BAUD_RATE,1
(there is an additionals
!). The meaning of the third argument is not clear. It’s probably a “don’t care” as with v1.1. The Nextion editor seems to always set it to1
and I had no problems with a1
so far. - After sending the first block of 4096 bytes, which contains the file header, the screen will not return the usual
0x05
response but indicate at what address the download shall continue. The response begins with0x08
followed by a 4-byte integer (little endian/lowest byte first). If that integer equals 0 the upload continues without skipping anything. Otherwise it continues at the specified offset.
08 00 00 11 00
means f.ex. you shall continue at offset0x110000
. Note that the offset is relative to the beginning of the file, not the current position.
I guess future devices could also return the0x08
answer at other points during the upload so I wouldn’t hardcode it as an expected first block reply (see below).
Implementation and backward compatibility
- v1.2 is only supported by devices that report a firmware version of 126 and higher (see
connect
command). For devices with older firmware (corresponding to editor v0.54 and earlier) you need to initiate the upload with the v1.1 command. Note: the v1.2 command won’t give you an error; apparently it was used for another, incompatible upload protocol in those firmware versions. - By not waiting explicitly for a
0x08
after the first block, the upload loop itself can be made compatible with both versions. Handle the return value conditionally. If Nextion returns0x05
continue, else if Nextion returns0x08
skip to the following offset, else throw an error. This is not only the easiest way to do it, but also the most flexible way. It can handle0x08
replies at any point during the upload and doesn’t break compatibility with v1.1. That’s how I did it in my script linked above.
Hints
- The
0x08
response takes longer than 0.5s on my device. More like ~1s. Therefore I set the serial timeout to 2s. - For some reason the first command after the
connect
procedure never works (for me at least). Doesn’t matter if I send aFF FF FF
first or not, whatever is the next command it will fail (returns1A FF FF FF
). My solution is to send a dummy command and then continue normally. - The TFT file size is actually included in the TFT file at offset
0x3c-0x3f
(little endian/lowest byte first). Could be easier/faster to read than to get the file size with other methods.
Happy uploading!
Max