Skip to content

Commit ba2e022

Browse files
tommie-liejpakkane
authored andcommitted
Read arguments to avrdude from cross file and use an option to change default serial port.
1 parent 7e80db9 commit ba2e022

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

arduino_uno_cross.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ strip = '/usr/bin/avr-strip'
66

77
[properties]
88
variant = 'standard'
9+
avrdude_speed = '115200'
10+
avrdude_programmer = 'arduino'
911

1012
c_args = [
1113
'-ffunction-sections',

meson.build

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ project('arduino blink', 'c', 'cpp',
1212
assert(meson.is_cross_build(), 'Arduino projects can only be built in a cross build environment.')
1313

1414
cross_variant = meson.get_cross_property('variant')
15+
avrdude_speed = meson.get_cross_property('avrdude_speed')
16+
avrdude_programmer = meson.get_cross_property('avrdude_programmer')
1517

1618
dependencies = [['arduinocore', 'arduinocore-avr'],
1719
['arduinocore-main', 'arduinocore-avr']]
@@ -36,9 +38,8 @@ stripped = custom_target('stripped',
3638
avrdude = find_program('avrdude')
3739
run_target('upload',
3840
command : [avrdude,
39-
'-C/usr/share/arduino/hardware/tools/avrdude.conf',
40-
'-v', '-v', '-v', '-v',
41-
'-patmega328p', '-carduino', '-P/dev/ttyACM0', '-b115200',
41+
'-v',
42+
'-p' + target_machine.cpu(), '-P' + get_option('port'), '-c' + avrdude_programmer, '-b' + avrdude_speed,
4243
'-D', '-Uflash:w:@0@:e'.format(stripped.full_path())],
4344
depends : stripped
4445
)

meson_options.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
option('port', type : 'string', value : '/dev/ttyACM0', description : 'The serial port that the Arduino is connected to.')

readme.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ The result can be uploaded with the following command:
1515
This command will rebuild the binary before uploading if it is out of
1616
date.
1717

18+
By default, 'ninja upload' will assume that your Arduino is connected
19+
as '/dev/ttyACM0'. If your Arduino shows up as a different device,
20+
you can override the default by setting the meson option 'port', i.e.
21+
22+
meson --cross-file arduino_uno_cross.txt -Dport=/dev/arduino build
23+
1824
# Porting to other Arduino models
1925

2026
This project hardcodes Arduino Uno. If you have a different model,
2127
change the compiler specifications and flags in the cross file. There
2228
does not seem to be a way to easily get these programmatically so you
2329
have to copy them by hand from Arduino IDE invocations.
24-
25-
The code also assumes a Linux environment and that your Arduino is in
26-
the serial port `/dev/ttyACM0`. If your setup is different, change the
27-
program invocations to match.

0 commit comments

Comments
 (0)