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.
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
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
command, v1.2 uses
(there is an additional
s!). 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 to
1and I had no problems with a
- After sending the first block of 4096 bytes, which contains the file header, the screen will not return the usual
0x05response but indicate at what address the download shall continue. The response begins with
0x08followed 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 00means f.ex. you shall continue at offset
0x110000. Note that the offset is relative to the beginning of the file, not the current position.
I guess future devices could also return the
0x08answer at other points during the upload so I wouldn’t hardcode it as an expected first block reply (see below).
- v1.2 is only supported by devices that report a firmware version of 126 and higher (see
connectcommand). 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
0x08after the first block, the upload loop itself can be made compatible with both versions. Handle the return value conditionally. If Nextion returns
0x05continue, else if Nextion returns
0x08skip 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 handle
0x08replies 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.
0x08response 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
connectprocedure never works (for me at least). Doesn’t matter if I send a
FF FF FFfirst or not, whatever is the next command it will fail (returns
1A 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.