-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathavr-upload.py
61 lines (42 loc) · 1.57 KB
/
avr-upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# Copyright 2018 by Martin Moene
#
# https://github.com/martinmoene/kalman-estimator
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
from __future__ import print_function
import argparse
import os
import re
import sys
# Configuration:
# atmega328: avr5 - "Enhanced" devices with 16 KiB up to 64 KiB of program memory.
mcu = 'atmega328p'
# Derived configuration:
cmd_upl = '{avrdude} -v -p{mcu} -cusbtiny -Uflash:w:{filename}:i'
# End configuration
# AVR-GCC programs:
avr_gcc_root = os.environ['AVR_GCC_ROOT']
if len( avr_gcc_root ) == 0:
print("Expected environment variable 'AVR_GCC_ROOT' to be set to root of AVR-GCC.")
sys.exit()
#print("avr_gcc_root :{avr_gcc_root}".format(avr_gcc_root=avr_gcc_root) )
#cpp = os.path.join( os.path.normpath(avr_gcc_root), os.path.normpath('/bin/avr-g++' ) )
cxx = avr_gcc_root + os.path.normpath('/bin/avr-g++')
objcopy = avr_gcc_root + os.path.normpath('/bin/avr-objcopy')
avrsize = avr_gcc_root + os.path.normpath('/bin/avr-size')
avrdude = avr_gcc_root + os.path.normpath('/bin/avrdude')
def run( cmd ):
print( cmd )
os.system( cmd )
def upload_hex( filename, mcu ):
#print( "Upload '{filename}'".format(filename=filename) )
cmd = cmd_upl.format( filename=filename, mcu=mcu, avrdude=avrdude, )
run( cmd )
if __name__ == '__main__':
if len( sys.argv ) > 1:
upload_hex( sys.argv[1], mcu )
else:
print( 'Usage: {} file.hex'.format( sys.argv[0] ) )
# end of file