Flash ESP32 programmatically using Java/Android
Flash ESP32 programmatically using Java/Android
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
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
- gunar.kroeger
- Posts: 143
- Joined: Fri Jul 27, 2018 6:48 pm
Re: Flash ESP32 programmatically using Java/Android
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.
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."
Re: Flash ESP32 programmatically using Java/Android
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
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
Re: Flash ESP32 programmatically using Java/Android
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!
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
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
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
Re: Flash ESP32 programmatically using Java/Android
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
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
Re: Flash ESP32 programmatically using Java/Android
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
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
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
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
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:
running: java -jar ESP-FlashTool.jar ...
Requres JDK 21+
no poothons
Reading MCU ID + MAC + some EFUSEs:
Flashing user bootloader:
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+
no poothons
Reading MCU ID + MAC + some EFUSEs:
Flashing user bootloader:
-
powerbroker
- Posts: 35
- Joined: Sun May 19, 2024 12:58 pm
Re: Flash ESP32 programmatically using Java/Android
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"
ESP-FlashTool.jar
Who is online
Users browsing this forum: ChatGPT-User and 17 guests