Trying to build mavlink image for esp8266

Hi,
I’m using an ESP01 for mavlink/Wi-Fi connection to QGC. I can install (and run) the binary on off-the-shelf ESP01, but for some reason can’t get the image to run when I install it on a small custom ESP01-like board I built. Other Arduino Wi-Fi applications run just fine, the only problem I have is when I install the mavlink image (from ESP8266 WiFi Module · PX4 v1.9.0 User Guide).
So, to get to know the ESP8266/Mavlink code, I figured it would be wise to attempt to build it from scratch. The instructions on the GitHub site say to install platformio, but on the platformio site, they recommend using VSCode and the platformio extension so that’s what I did.
Unfortunately I have not been able to get it to build successfully. Has anyone done this lately?
Thanks,

Ok in case anyone is interested… I was able to get things to build (note this is on Windows-10 host) by modifying the build_flags variable in platformio.ini. My system was getting confused by the embedded commands that are used to create the macros…
!echo “-DPIO_SRC_REV="$(git rev-parse HEAD) "-DPIO_BUILD_DATE="$(date +%%Y-%%m-%%d) "-DPIO_BUILD_TIME=”$(date +%%H:%%M:%%S) ${version_env.version_flags}
so I just hard-coded them for now…
!echo -DPIO_SRC_REV=3c8c130ce2f0865de3469b1648453a695af2c948 -DPIO_BUILD_DATE=2022-05-28 -DPIO_BUILD_TIME=12-13-56 ${version_env.version_flags}

This allowed the build to complete successfully

hello, I’m interested in your project. do you have a blog or a post where I can read more or follow along. I have been learning all this arduino stuff and am interested as it relates to robotics and projects people are working on

platformio works great on linux, i haven’t tried windows yet. I recently added ESP32 support if anyone is interested.

I’ve designed and built a few boards which use either module and they work very well albeit there are a few tricks to make them work reliably and at range - clean power and external antenna should be your focus there.

have fun!

@jfd I assume you’ve installed and run the mavlink binary onto your custom boards?
My board (essentially an ESP01, but my own form-factor) runs -every- app I’ve built
for it (just using Examples from Arduino) EXCEPT the mavlink binary. When I install
it, and reset my board all I get is:

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0xef
csum 0xef
csum err
ets_main.c

I assume this is coming from the ESP8266’s bootloader true?
Any idea what I might be doing wrong (keeping in mind that other Arduino apps install and run just fine)?
Thanks,
Ed

@local_ad I don’t have a blog or post anywhere, I’m just taking a deep-dive into PX4 using a Teensy4.1 and ESP01 for WiFi.

Oh yeah, Either the ESP-01 pinheader version or the ESP 32SMT, The latter which I pre-program with the “Amazon” SMT breakout board Before I surface mount it to my boards.

in the link I sent there is a couple different breakout boards you can use to program the ESP01 over USB. The bootstrapping options and sequencing is wonky On these chips as a power up sucks a lot of juice. I’d like 100 µF capacitor to the power rail just to be sure. there is a jumper to program the flash and of course you need to make sure your flash size is correct And then yeah if you get corrupted data via upload your checksum will fail as you’ve shown.

So start with the stable breakout board

So let’s check your serial connection is correct in the right speed that you have a stable power supply and you have the correct flash size. For your power supply run it on the bench and check to see what kind of current you’re pulling.

go take a picture of the SPI flash chip and look it up and see how many megabits the device capacity you have - And look at how the command line options change for the ESP-01 and 4 Meg version to platformio

It was a while since I did this last but if I remember correctly that was my line of debug. Get some fresh cheap five dollar Amazon board and start with that first

@jfd Thanks for responding… My board has the ESP8266 soldered directly to a PCB. That PCB also “carries” a Teensy4.1. The ESP8266 was not programmed before mounting it to my PCB. Prior to my custom PCB, I just wired up a Teensy4.1 and an ESP01 pinheader module using a modified version of the esptool-ck code on the Teensy to directly program the ESP01. That has worked fine for several months. Then I had a small ESP8266/Teensy4.1 board built and now I have the problem mentioned above (everything BUT the mavlink binary seems to work). I can take the exact same binary and install it with the exact same code on a “wired-up” Teensy4.1/ESP01 setup and that works just fine. Plus I’ve installed and run several other Arduino example applications (some of which produce .bin files that are larger than the mavlink .bin) on the PCB version of my system and they also run just fine.

It doesn’t make sense to me. Any suggestions would sure be appreciated.
Ed

It sounds to me like a reset issue and/or some interaction with the boot loader. Test that theory by removing the Teensy from your board And scope the reset line of the ESP module at boot up. I will have to go and check my designs but you need to have a cap and one of the pin shorted to go into boot loader mode.

Remember that if you can program it with the Arduino IDE that means you have an Arduino boot loader installed Which is probably causing a problem when you flash it with the ESP tool.

But check your strapping for program mode I believe you need to have GPI 001 shorted to ground. If the Teensy Is connected it could be conflicting with those pins hence you’re unable to go in the boot loader mode.

I always use the default ESP boot loader and never trieded to flash a platform IO binary with an Arduino boot-loader. But the Arduino boot loader is synchronous with the Arduino SDK and probably you can run the Arduino SDK with debyg enabled to see how you are flashing.

If I remember correctly the default mavlink binary for esp01 is set up for a one megabyte flash

@jfd I realize I really didn’t reply to your suggestions, so here is a follow-up…

I don’t use any breakout board for programming at this stage. My small Teensy-ESP01 configuration is my primary platform. In general it works just fine. Its simply a UART connection and a few GPIO pins tied between ESP8266EX and the Teensy. I can download at 74880, 115200 and 926100. I’ve been using 74880 just so that I can see the initial bootloader response upon completion of the download. In all cases, except for the Mavlink binary, it programs (and runs) successfully.
Also note that if I just use my wired configuration (which is just a messy equivalent to my PCB) that also works just fine. The only difference there (that I am aware of) is that the ESP8266 was preprogrammed with the default firmware that the ESP01 ships with.

@jfd Note, I’m not using the Arduino IDE to program it, I only use the IDE to build the final binary, then I load that binary using my “Teensy-version” of the esptool-ck. So whether I am programming the mavlink binary or an Arduino example, I am using the ESP8266’s internal rom-bootloader to actually burn the code to the SPI flash.
Also, note I am using 4M flash, which is what the newer ESP01 modules use.

BTW… I -really- appreciate your thoughts here!! Sorry if I’m dragging this out a bit.

OK so that is one big difference - You were doing in-circuit programming using teensy as the esptool host, which I am not doing. Do you have contention on your UART? is ESP and Teensy talking at the same time?

There could be a number of issues there - the timeout values may not be working in your port, uart driver changes, etc.

get back to a simple recipe …

Have you tried using esptool on a Linux machine with an FTDI serial cable? ESP is 3.3v level so an RPI serial (no flow control) is your best bet.

First put the ESP in program mode with the teensy and use a uart connection to a PC with an FTDI cable. Any luck? If not, then debug your reset circuit.

things to check:

UART baud rate mismatch between ESP boot loader and Teenay

Program mode not entered correctly

UART connection issues

External cable can help yourself some of those problems or at least a check. I’ll go look at my circuits and some of my notes this weekend and get back to you on this

You were doing in-circuit programming using teensy as the esptool host, which I am not doing.

Exactly!

Do you have contention on your UART? is ESP and Teensy talking at the same time?
There could be a number of issues there - the timeout values may not be working in your port, uart driver changes, etc.

All good questions, but keep in mind that literally everything that I’ve tried to do works except for the mavlink image. I’ve verified that the GPIOs are correctly toggling to put the ESP8266 into program mode, and I know that the UART connection is solid because I can pump other images into the spi flash and they work.

NOTE: I am not implying that the problem is caused by your code, its just so strange that only that image fails; and on top of that, it does not fail if I use the exact same pin configuration between Teensy and ESP01. There must be something different between the ESP01 and my “ESP01-look-alike”; but then I think: “It works for every other application I’ve loaded onto the ESP8266’s SPI flash”.

Nothing makes sense here. Is there any OTP (one-time-programmable) memory in the ESP8266 itself that may be required by your application?
Tx

Ok, I took a shot in the dark and I may have figured out my problem…
Apparently the base of the .bin file that is loaded into the SPI flash is some kind of header (if you know of documentation on this, please send me a pointer). I see that if I change the size of the flash in the Arduino IDE, it changes the 4th byte of the image, so that gave me a clue.

Anyway, my ESP01-look-alike uses a 4M flash device, which is what is on most of the newer ESP01 modules that I have used. So, until now I wasn’t suspicious of that. then it occurred to me that maybe the device I’m using has a slightly different device ID than the bootloader is expecting, and that may be causing some confusion.
To test this theory I hacked the first 4 bytes of the mavlink binary to match those of an image that worked on my board. Voila! PixRacer appears! Now I just have to understand what the initial bytes of the .bin file represent.

Thanks much for the dialog! Hopefully this is resolved and I’ll stop bothering you. :slight_smile:

that actually would make a lot of sense, I’ve seen variations in the different modules based on the boot letter that’s programmed in them from the factory. I once got modules from a reputable supplier and they never went into the bootloader.
I finally found out that power and baudrate was the issue. Let me know what you find regardless…

Find out the boot loader that you have programmed in these boards. save the contents of the spi flash and try to identify the image origin
You can use a bus pirate or aardvark to do that

Well I looked closer at the esptool-ck source and found that the first few bytes of the .bin file are significant. Referring to esptool-ck/esptool_binimage.h at master · igrr/esptool-ck · GitHub , when I changed the third byte (flash_mode) in your file from 00 (QIO) to 03 (DOUT) things worked just fine. I don’t really understand why that makes it work. I have to read more about the flash_mode field.

The only bootloader that I use is the ROM bootloader in the ESP8266. There is no other bootloader involved AFAIK. I use it to install the entire application which the rom-bootloader jumps into at reset. That applies whether its your firmware-1.2.2.bin (modified) or an Arduino application.

Oh right! You should check and see if an older version of esptool works - that is a great find!

If the structure of the header changed from an older version of firmware than an older version of ESP tool would work. Look at the version that was used originally.

I’ve only used esptool-ck, whether it be from the host or using my modified version that runs on the Teensy4. That’s where I found the structure of the header of the .bin file. Anyway, I did more testing with the modification above and it seems to be working well.

The only open question in my mind now is why did the Arduino-built image run on both systems (ESP01 & my ESP01-look-alike) but your mavlink image did not… I’ll have to read more about the differences between QIO and DOUT modes; then, hopefully things will make more sense.

Bottom line though… it works!
Thanks much for the interaction.