Skip to content

Commit

Permalink
Devel (#194)
Browse files Browse the repository at this point in the history
* Try using avrdude instead of core

* Use avrdude in path

* Add avr utils
  • Loading branch information
lbussy committed Jan 9, 2022
1 parent 32301d5 commit 3833f9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ downloads/
utils/downloads/
venv/
.gitconfig
boards.txt

# Compiled Python files
*.py[co]
Expand Down
28 changes: 7 additions & 21 deletions programController.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,12 @@ def fetchBoardSettings(boardsFile, boardType):
return boardSettings


def loadBoardsFile(arduinohome):
def loadBoardsFile():
boardsFileContent = None
try:
avrpath = "/usr/share/arduino"
boardsloc = glob.glob(avrpath + "/**/boards.txt", recursive = True)[0]
boardsFileContent = open(boardsloc, 'rb').readlines()
boardsFileContent = open(util.scriptPath() + "boards.txt", 'rb').readlines()
except IOError:
printStdErr(
"Could not read boards.txt from Arduino, probably because Arduino has not been\ninstalled. Please install it with: 'sudo apt install arduino-core'")
printStdErr("Could not read {}boards.txt.".format(util.scriptPath()))
return boardsFileContent


Expand Down Expand Up @@ -539,18 +536,11 @@ def delay_serial_open(self):
def flash_file(self, hexFile):
config, boardType = self.config, self.boardType
printStdErr("\nLoading programming settings from board.txt.")
# location of Arduino sdk
arduinohome = config.get('arduinoHome', '/usr/share/arduino/')
# location of avr tools
avrdudehome = config.get(
'avrdudeHome', arduinohome + 'hardware/tools/')
# default to empty string because avrsize is on path
avrsizehome = config.get('avrsizeHome', '')

# location of global avr conf
avrconf = config.get('avrConf', avrdudehome + 'avrdude.conf')
avrconf = config.get('avrConf', '/etc/avrdude.conf')

boardsFile = loadBoardsFile(arduinohome)
boardsFile = loadBoardsFile()
if not boardsFile:
return False
boardSettings = fetchBoardSettings(boardsFile, boardType)
Expand All @@ -568,15 +558,12 @@ def flash_file(self, hexFile):
printStdErr("\nChecking hex file size with avr-size.")

# start programming the Arduino
avrsizeCommand = avrsizehome + 'avr-size ' + "\"" + hexFile + "\""
avrsizeCommand = 'avr-size ' + "\"" + hexFile + "\""

# check program size against maximum size
p = sub.Popen(avrsizeCommand, stdout=sub.PIPE,
stderr=sub.PIPE, shell=True)
output, errors = p.communicate()
#if errors != "":
# printStdErr('\navr-size error: {0}'.format(errors))
# return False

programSize = output.split()[7]
printStdErr('\nProgram size: {0} bytes out of max {1}.'.format(programSize.decode(), boardSettings['upload.maximum_size']))
Expand All @@ -600,12 +587,11 @@ def flash_file(self, hexFile):
config['port'] = convert.get_device_from_brewpidev(config['port'])

bootLoaderPort = util.findSerialPort(bootLoader=True, my_port=config['port'])
# bootLoaderPort = util.findSerialPort(bootLoader=True)
if not bootLoaderPort:
printStdErr("\nERROR: Could not find port in bootloader.")
return False

programCommand = (avrdudehome + 'avrdude' +
programCommand = ('avrdude' +
' -F' + # override device signature check
' -e' + # erase flash and eeprom before programming. This prevents issues with corrupted EEPROM
' -p ' + boardSettings['build.mcu'] +
Expand Down
19 changes: 18 additions & 1 deletion utils/doDepends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ init() {
. "$GITROOT/inc/nettest.inc" "$@"

# Packages to be installed/checked via apt
APTPACKAGES="git python3 python3-pip python3-venv python3-setuptools arduino-core apache2 php libapache2-mod-php php-cli php-cgi php-mbstring php-xml libatlas-base-dev python3-numpy python3-scipy"
APTPACKAGES="git python3 python3-pip python3-venv python3-setuptools avrdude binutils-avr apache2 php libapache2-mod-php php-cli php-cgi php-mbstring php-xml libatlas-base-dev python3-numpy python3-scipy"
# Packages to be installed/check via pip3
PIP3PACKAGES="requirements.txt"
}
Expand Down Expand Up @@ -320,6 +320,22 @@ do_packages() {
fi
}

############
### Bring down boards.txt from Arduino-core
############

do_boards() {
local user project branch filename wgetcmd
echo -e "\nDownloading current boards configuration."
user="arduino"
project="ArduinoCore-avr"
branch="master"
filename="boards.txt"
target="$GITROOT/boards.txt"
wgetcmd="wget -q https://raw.githubusercontent.com/$user/$project/$branch/$filename -O $target"
eval "$wgetcmd"||die
}

############
### Reset BT baud rate < Pi4
############
Expand Down Expand Up @@ -429,6 +445,7 @@ main() {
rem_php5 # Remove php5 packages
check_nginx # Offer to remove nginx packages
do_packages # Check on required packages
do_boards # Get current boards.txt
do_uart # Slow down UART
do_venv # Set up venv
do_aliases # Set up BrewPi user aliases
Expand Down

0 comments on commit 3833f9f

Please sign in to comment.