Flash ESP32 programmatically using Java/Android

macieljr
Posts: 5
Joined: Mon Jan 13, 2020 7:31 pm

Flash ESP32 programmatically using Java/Android

Postby macieljr » Mon Jan 13, 2020 8:22 pm

Hi guys!

I’m developing an Android app that is directly connected via USB to consume data from an ESP32 with sensors attached. I’m using https://github.com/felHR85/UsbSerial to manage the connection. Since the app will be running on an internet connected tablet, I think it’s obvious to update ESP32 code, if needed, through the app, giving the user an option do download it (.bin) and then upload it to ESP32.

But I have no idea how...

Tried searching for and Android/Java lib, but I wonder it can be done by the same lib I’m using to establish the serial communication already.

So, If you have done such thing or know how to do and/or can point some direction, please share it with me.

Kind regards,

Vicente Maciel Jr

User avatar
gunar.kroeger
Posts: 143
Joined: Fri Jul 27, 2018 6:48 pm

Re: Flash ESP32 programmatically using Java/Android

Postby gunar.kroeger » Fri Jan 17, 2020 6:55 pm

To upload the .bin to the esp you would need to control the reset and the boot pins as well. Then you can transfer the .bin through uart0 using the SLIP interface. There is the python program that does this called esptool.py that comes with esp-idf.

The second, easier option, is to use the OTA example and change it to use uart instead of http. This way you can update the esp, but the first time you will have to flash it with a PC.
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

macieljr
Posts: 5
Joined: Mon Jan 13, 2020 7:31 pm

Re: Flash ESP32 programmatically using Java/Android

Postby macieljr » Sat Jan 18, 2020 3:08 am

First, thank you so much for the reply!

I’ll look for some references regarding the tips you mentioned and try them.

I’ll post the results here. Or the questions, if I have. Thank you again!

Kind regards,

Vicente Maciel Jr

drradao
Posts: 1
Joined: Fri Jun 12, 2020 8:13 pm

Re: Flash ESP32 programmatically using Java/Android

Postby drradao » Fri Jun 12, 2020 8:18 pm

Hi!

Did you have any success?

I've tried to flash it with python via chaquopy but got stuck at a permission denied.
I'm going to try to request it from python.

Thanks!

raymondshi
Posts: 6
Joined: Fri Jul 09, 2021 2:46 am

Re: Flash ESP32 programmatically using Java/Android

Postby raymondshi » Tue Aug 10, 2021 7:07 am

Hi there,

I come across the posts here today, and am also very interested on flashing ESP32 over the serial connection in Android app.

From what I read on https://github.com/espressif/esptool/wi ... -Selection, seems like this can be achieved as follows,

1. Android app instructs ESP32 app to set GPIO0 to low, as well as reset itself
2. Android app sends the new ESP32 binary image on the serial connection

Just wondering if anyone has managed to get this (or something similar) working end-to-end, is willing to share it.

Best regards
Raymond

bdureau
Posts: 2
Joined: Mon Oct 10, 2022 2:27 pm

Re: Flash ESP32 programmatically using Java/Android

Postby bdureau » Mon Oct 10, 2022 3:27 pm

Hello
For those interested I did a quick port of the ESPtool to Java that works for the ESP32
https://github.com/bdureau/ESPLoader
I also did a port to Android using Physicaloid
https://github.com/bdureau/BearConsole2 ... sole/Flash
However it needs improvement, I have added some timers so that it worked .... but is is slow!!!!
I also have some issues with Android for entering bootloader mode and doing a reset (workaround is to use the button on the board). If someone could help to fix those that would be appreciated
Regards
Boris

bdureau
Posts: 2
Joined: Mon Oct 10, 2022 2:27 pm

Re: Flash ESP32 programmatically using Java/Android

Postby bdureau » Thu Dec 19, 2024 9:34 pm

My esptool java port is now quite stable. Working with ESP32, ESP32S3, ESP32C3 and ESP8266.

Waiting for my other board to arrive to add them

powerbroker
Posts: 35
Joined: Sun May 19, 2024 12:58 pm

Re: Flash ESP32 programmatically using Java/Android

Postby powerbroker » Wed Feb 19, 2025 7:12 am

My esptool java port is now quite stable. Working with ESP32, ESP32S3, ESP32C3 and ESP8266.

Waiting for my other board to arrive to add them

being inspired with your code now experiencing some progress with running ESP32 Stub loader #2 from java program ;)

it truly reads flash chip with 0xD2 command - where Stub loader #1 crashes :lol: :lol:

UPD:
It looks like ESP32 Stub loader #2 is surprisingly NOT SUPPORTED.
but it successfully calculates MD5 of specified flash region and allows to dump flash data, while supported one just crashes.

powerbroker
Posts: 35
Joined: Sun May 19, 2024 12:58 pm

Re: Flash ESP32 programmatically using Java/Android

Postby powerbroker » Sat May 03, 2025 5:40 am

picking all this poothon stuff generously stuffed to us by the ESP team, i come to the conclusion that this is, definitely, possible.

let me present a proof-of-concept build of Java (+ a native library "jSerialComm") Esp32 FlashTool, capable of basic ESP32 serial operations:

  • read MCU ID + EFUSE bank 0
  • upload and run ESP-IDF ESP32 Stub loader from json file
  • retrieve MD5 of a specified flash region
  • dump specified flash region to binary file(at 921600)
  • upload (specified part of) binary file to specified flash region(at 921600)
  • erase specified flash region
  • erase flash completely
ESP-FlashTool.jar

running: java -jar ESP-FlashTool.jar ...

Requres JDK 21+
no poothons :P

ESP-FlashTool Welcome.png
ESP-FlashTool Welcome.png (109.71 KiB) Viewed 1022 times

Reading MCU ID + MAC + some EFUSEs:
ESP-FlashTool MCU ID.png
ESP-FlashTool MCU ID.png (182.64 KiB) Viewed 1022 times

Flashing user bootloader:
ESP-FlashTool Bootloader.png
ESP-FlashTool Bootloader.png (201.1 KiB) Viewed 1022 times

powerbroker
Posts: 35
Joined: Sun May 19, 2024 12:58 pm

Re: Flash ESP32 programmatically using Java/Android

Postby powerbroker » Wed May 07, 2025 2:09 am

let me present a proof-of-concept build of Java (+ a native library "jSerialComm") Esp32 FlashTool, capable of basic ESP32 serial operations:

  • read MCU ID + EFUSE bank 0
  • upload and run ESP-IDF ESP32 Stub loader from json file
  • retrieve MD5 of a specified flash region
  • dump specified flash region to binary file(at 921600)
  • upload (specified part of) binary file to specified flash region(at 921600)
  • erase specified flash region
  • erase flash completely

running: java -jar ESP-FlashTool.jar ...

Requres JDK 21+

with capability of flashing (part of) binary file at specified address it's easy to go further - enable flashing of a whole ESP project at once: ALL binaries, mentioned in 'flasher_args.json' at their correct offsets.

so, totally no need in poothon to flash ESP32 - just say:

> java -jar ESP-FlashTool.jar COM1 upload "path\to\flasher_args.json" :P

ESP-FlashTool.jar

ESP-FlashTool Build.png
ESP-FlashTool Build.png (272.57 KiB) Viewed 980 times

Who is online

Users browsing this forum: ChatGPT-User and 17 guests