Browse Source

Change default baudrate

* Closes #51
* implements auto-baudrate detection as mentioned by @matgoebl
* updates usage
kmpm 7 years ago
parent
commit
c834cc31b6
4 changed files with 19 additions and 9 deletions
  1. 13 6
      doc/USAGE.md
  2. 4 1
      nodemcu_uploader/uploader.py
  3. 1 1
      nodemcu_uploader/version.py
  4. 1 1
      tests/misc.py

+ 13 - 6
doc/USAGE.md

@@ -1,22 +1,29 @@
- Usage 
+ Usage
 ===================
 ===================
 This document is by no means complete.
 This document is by no means complete.
 
 
 
 
 ## Common options
 ## Common options
 * --help will show some help
 * --help will show some help
-* --start_baud set at a default of 9600 (the speed of the nodemcu at boot)
+* --start_baud set at a default of 115200 (the speed of the nodemcu at boot in later
+  versions of the firmware)
 * --baud are set at a default of 115200
 * --baud are set at a default of 115200
 * --port is by default __/dev/ttyUSB0__,
 * --port is by default __/dev/ttyUSB0__,
   __/dev/tty.SLAB_USBtoUART__ if on Mac and __COM1__ on Windows
   __/dev/tty.SLAB_USBtoUART__ if on Mac and __COM1__ on Windows
 * the environment variable __SERIALPORT__ will override any default port
 * the environment variable __SERIALPORT__ will override any default port
 
 
-Since v0.2.1 the program works with 2 speeds. It connects at a default
-(--start_baud) of 9600 baud which is what the default firmware uses. Immediately after
-first established communication it changes to a higher (--baud) speed which defaults
+Since v0.2.1 the program works with 2 possible speeds. It connects at a default
+(--start_baud) of 115200 baud which is what the default firmware uses. Earlier
+versions of the firmware and this tool used 9600 as start baudrate.
+Immediately after first established communication it changes
+to a higher (--baud) speed, if neccesary, which defaults
 to 115200. This allows all communication to happen much faster without having to
 to 115200. This allows all communication to happen much faster without having to
 recompile the firmware or do any manual changes to the speed.
 recompile the firmware or do any manual changes to the speed.
-When done and before it closes the port it changes the speed back to normal.
+When done and before it closes the port it changes the speed back to normal
+if it was changed.
+Since v0.4.0 of nodemcu-uploader it tries to use the auto-baudrate feature
+build in to the firmware by sending a character repetedly when initiating
+communication.
 
 
 ## Commands
 ## Commands
 ### Upload
 ### Upload

+ 4 - 1
nodemcu_uploader/uploader.py

@@ -33,7 +33,7 @@ class Uploader(object):
     that will allow various tasks like uploading files, formating the filesystem etc.
     that will allow various tasks like uploading files, formating the filesystem etc.
     """
     """
     BAUD = 115200
     BAUD = 115200
-    START_BAUD = 9600
+    START_BAUD = 115200
     TIMEOUT = 5
     TIMEOUT = 5
     PORT = default_port()
     PORT = default_port()
 
 
@@ -59,6 +59,9 @@ class Uploader(object):
             log.debug('getting in sync with LUA')
             log.debug('getting in sync with LUA')
             self.__clear_buffers()
             self.__clear_buffers()
             try:
             try:
+                self.__writeln('UUUUUUUUUUUU') # Send enough characters for auto-baud
+                self.__clear_buffers()
+                time.sleep(0.15) # Wait for autobaud timer to expire
                 self.__exchange(';') # Get a defined state
                 self.__exchange(';') # Get a defined state
                 self.__writeln('print("%sync%");')
                 self.__writeln('print("%sync%");')
                 self.__expect('%sync%\r\n> ')
                 self.__expect('%sync%\r\n> ')

+ 1 - 1
nodemcu_uploader/version.py

@@ -3,4 +3,4 @@
 """just keeper of current version"""
 """just keeper of current version"""
 
 
 #TODO: remember to update tests when version changes
 #TODO: remember to update tests when version changes
-__version__ = '0.3.2'
+__version__ = '0.4.0'

+ 1 - 1
tests/misc.py

@@ -8,7 +8,7 @@ import os
 class MiscTestCase(unittest.TestCase):
 class MiscTestCase(unittest.TestCase):
 
 
     def test_version(self):
     def test_version(self):
-        self.assertEqual(__version__, '0.3.2')
+        self.assertEqual(__version__, '0.4.0')
 
 
     def test_default_port(self):
     def test_default_port(self):
         if os.environ.get('SERIALPORT', 'none') != 'none':
         if os.environ.get('SERIALPORT', 'none') != 'none':