This is intended to allow flashing 8051 based OBS38S003 microcontrollers as a target.
An external ESP8266/ESP32 module or similar serves as the flasher.
Note that the reset function on the reset pin of the stock Sonoff RF Bridge is probably disabled.
In other words, the pin is configured as GPIO by fuse and thus the target cannot be held in reset.
Handshaking is apparently performed at microcontroller power up or restart.
Therefore, the flasher is independently powered while a second power source is used to the target.
Once setfuse is changed (see below) the ESP8285 on the Sonoff itself could be used to reflash the microcontroller.
However, this would require soldering a wire to the reset pad.
Additionally, the serial pins communicating with the Arduino serial monitor mighty be interferred with by microcontroller activity.
The original Sonoff black case with EFM8BB1 allowed microcontroller reset by a long pulse on an C2D pin but that is not available here.
It is probably easiest to just use an external flasher.
For manual programming each HEX line must be pasted into the serial monitor individually.
A script has been contributed that would make file upload automatic.
The sketch has successfully flashed a simple blink program.
For example, the ESP8285 present in the Sonoff RF Bridge R2 v2.2 serves as the source flasher.
The USBRXD pin is bridged to SCL, while the USBTXD pin is bridged to SDA.
The reset pad would need to be soldered with a wire, though the datasheet is unclear if reset is active low or active high.
It is probably easiest to just use an external programmer unfortunately.
Board | Status | Note |
---|---|---|
ESP8265 (e.g. in Sonoff) | WORKING | none |
ESP8266 (e.g. Wemos D1 Mini) | WORKING | none |
ESP-WROOM-32 | WORKING | none |
ESP32S3 | WORKING | none |
Arduino Mega 2560 board | WORKING | 5V to 3.3V level translation recommended |
Item | Status | Note |
---|---|---|
Write flash memory | DONE | Manually one byte or one hex line at a time |
Read flash memory | DONE | Manually one byte at a time |
Reading/writing configuration bits | PARTIAL | Need read-modify-write scheme |
Verify flash memory | TODO | none |
- Connect Arduino I2C/GPIO pins to the microcontroller while unpowered.
- Target microcontroller can be powered by an independent supply, or from 3.3V output regulator on Arduino board.
- Using output regulators on Arduino boards seems to lead to power up glitches (e.g., serial monitor disconnects, handshake fails).
- Target should remain unpowered until handshake is started.
- Specify software or hardware I2C in project - see projectDefs.h.
- Upload the sketch to ESP8265/ESP8266/ESP32.
- Copy the desired hex file from GitHub Releases to the script directory.
- Run
flashScript.py
and follow the instructions in the console. - For
blink.ihx
, the red LED on the Sonoff target should begin blinking with a one-second period. - For
RF-Bridge-OB38S003_PassthroughMode.hex
, the red LED on Sonoff should light up once at startup.
- Set serial monitor to "Both NL & CR" at 115200 baud.
- Type "handshake" into the serial monitor.
- Power on the target microcontroller with 3.3V.
- If chip is protected, chip read will appear to fail due to NACK but chip type reported should be (0xA). Proceed to 'erase' step to unprotect chip.
- If chip is unprotected, serial monitor should display 'Handshake succeeded' along with chip type as (0xA). If not, follow instructions to retry.
- Type 'erase' command since the microcontroller is likely protected (this erases flash, cannot be recovered!).
- Type "setfuse 18 249" (sets reset pin as reset functionality rather than GPIO).
- Copy-paste hex lines starting with ':' into the serial monitor and hit the enter key.
- Successful or failed writes should be displayed in the serial monitor.
- If all successful, type "mcureset" to reset the microcontroller.
- For
blink.ihx
, the red LED on the Sonoff target should begin blinking with a one-second period. - For
RF-Bridge-OB38S003_PassthroughMode.hex
, the red LED on Sonoff should light up once at startup.
Not included at this time.