Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
cfe5b23b
Commit
cfe5b23b
authored
Jul 02, 2015
by
Vowstar
Browse files
Merge pull request #523 from DiUS/dio-fix
Workaround write-protected flash when using esptool.py to flash in DIO mode
parents
125d2173
9eda352e
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/esptool.py
View file @
cfe5b23b
...
...
@@ -128,38 +128,32 @@ class ESPROM:
def
connect
(
self
):
print
'Connecting...'
# RTS = CH_PD (i.e reset)
# DTR = GPIO0
# self._port.setRTS(True)
# self._port.setDTR(True)
# self._port.setRTS(False)
# time.sleep(0.1)
# self._port.setDTR(False)
# NodeMCU devkit
self
.
_port
.
setRTS
(
True
)
self
.
_port
.
setDTR
(
True
)
time
.
sleep
(
0.1
)
self
.
_port
.
setRTS
(
False
)
self
.
_port
.
setDTR
(
False
)
time
.
sleep
(
0.1
)
self
.
_port
.
setRTS
(
True
)
time
.
sleep
(
0.1
)
self
.
_port
.
setDTR
(
True
)
self
.
_port
.
setRTS
(
False
)
time
.
sleep
(
0.3
)
self
.
_port
.
setDTR
(
True
)
self
.
_port
.
timeout
=
0.5
for
i
in
xrange
(
10
):
try
:
self
.
_port
.
flushInput
()
self
.
_port
.
flushOutput
()
self
.
sync
()
self
.
_port
.
timeout
=
5
return
except
:
time
.
sleep
(
0.1
)
for
_
in
xrange
(
4
):
# issue reset-to-bootloader:
# RTS = either CH_PD or nRESET (both active low = chip in reset)
# DTR = GPIO0 (active low = boot to flasher)
self
.
_port
.
setDTR
(
False
)
self
.
_port
.
setRTS
(
True
)
time
.
sleep
(
0.05
)
self
.
_port
.
setDTR
(
True
)
self
.
_port
.
setRTS
(
False
)
time
.
sleep
(
0.05
)
self
.
_port
.
setDTR
(
False
)
self
.
_port
.
timeout
=
0.3
# worst-case latency timer should be 255ms (probably <20ms)
for
_
in
xrange
(
4
):
try
:
self
.
_port
.
flushInput
()
self
.
_port
.
flushOutput
()
self
.
sync
()
self
.
_port
.
timeout
=
5
return
except
:
time
.
sleep
(
0.05
)
# this is a workaround for the CH340 serial driver on current versions of Linux,
# which seems to sometimes set the serial port up with wrong parameters
self
.
_port
.
close
()
self
.
_port
.
open
()
raise
Exception
(
'Failed to connect'
)
""" Read memory address in target """
...
...
@@ -268,6 +262,15 @@ class ESPROM:
return
data
""" Abuse the loader protocol to force flash to be left in write mode """
def
flash_unlock_dio
(
self
):
# Enable flash write mode
self
.
flash_begin
(
0
,
0
)
# Reset the chip rather than call flash_finish(), which would have
# write protected the chip again (why oh why does it do that?!)
self
.
mem_begin
(
0
,
0
,
0
,
0x40100000
)
self
.
mem_finish
(
0x40000080
)
""" Perform a chip erase of SPI flash """
def
flash_erase
(
self
):
# Trick ROM to initialize SFlash
...
...
@@ -566,7 +569,10 @@ if __name__ == '__main__':
seq
+=
1
print
print
'
\n
Leaving...'
esp
.
flash_finish
(
False
)
if
args
.
flash_mode
==
'dio'
:
esp
.
flash_unlock_dio
()
else
:
esp
.
flash_finish
(
False
)
elif
args
.
operation
==
'run'
:
esp
.
run
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment