Skip to content

Commit

Permalink
tools/reboottool.py added
Browse files Browse the repository at this point in the history
May define REBOOTMAGIC in Config.mk to send magic string.

DEFAULTBAUD renamed to USERBAUD.
  • Loading branch information
rsta2 committed Apr 11, 2018
1 parent 61f5a9a commit 9433c83
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ clean:
#

SERIALPORT ?= /dev/ttyUSB0
DEFAULTBAUD ?= 115200
USERBAUD ?= 115200
FLASHBAUD ?= 115200
REBOOTMAGIC ?=

$(TARGET).hex: $(TARGET).img
$(PREFIX)objcopy $(TARGET).elf -O ihex $(TARGET).hex

flash: $(TARGET).hex
ifneq ($(strip $(REBOOTMAGIC)),)
python $(CIRCLEHOME)/tools/reboottool.py $(REBOOTMAGIC) $(SERIALPORT) $(USERBAUD)
endif
python $(CIRCLEHOME)/tools/flasher.py $(TARGET).hex $(SERIALPORT) $(FLASHBAUD)

monitor:
putty -serial $(SERIALPORT) -sercfg $(DEFAULTBAUD)
putty -serial $(SERIALPORT) -sercfg $(USERBAUD)
41 changes: 41 additions & 0 deletions tools/reboottool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import serial
import sys
import time

try:
magicstring = ' '.join(sys.argv[1:2])
serialport = ' '.join(sys.argv[2:3])
serialbaud = int(' '.join(sys.argv[3:]))
except Exception:
print("Usage: python reboottool.py MAGICSTRING SERIALPORT BAUDRATE")
exit()

try:
ser = serial.Serial(
port=serialport,
baudrate=serialbaud,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
except Exception:
print("ERROR: Serial Port " + serialport + " busy or inexistent!")
exit()

print("Sending \"" + magicstring + "\" with baudrate of "+ str(serialbaud) + "...")
sys.stdout.flush()

try:
ser.write(magicstring)
except Exception:
print("ERROR: Serial port disconnected. Check connections!")
ser.close()
exit()

print("Waiting for reboot...");
sys.stdout.flush()
time.sleep(4)

print("Completed!")

ser.close()

0 comments on commit 9433c83

Please sign in to comment.