Skip to content

Commit b118fb6

Browse files
committed
improved DFP setup and support:
- `./make dfp` downloads and installs Atmel DFPs for each supported MCU - build.sh detects and uses attiny or avrdd, and others are simple to add - updated setup info in /README.md ... also some other small documentation updates.
1 parent f9938f6 commit b118fb6

File tree

6 files changed

+118
-30
lines changed

6 files changed

+118
-30
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
arch/dfp/
12
env/
23
hex/
34
ignore/
@@ -11,5 +12,6 @@ old/
1112
*.html
1213
*.o
1314
*.old
15+
*.otl
1416
.*.swo
1517
.*.swp

README.md

+46-15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ for full details.
2121

2222
If you want to know what changed recently, check the [ChangeLog](ChangeLog.md).
2323

24+
For info about hardware-specific features, like what the channel modes are on
25+
multi-channel lights, browse into the [hw/](hw/) directories to find the
26+
hardware model and any hardware-specific documentation.
27+
2428
## Flashing Firmware
2529

2630
Get the latest updates by flashing new firmware!
@@ -50,6 +54,9 @@ A few things are needed to flash firmware:
5054

5155
One particularly useful guide is at https://anduril.click/ .
5256

57+
More info about installing flashing programs is below, in
58+
[Flashing Programs](#flashing-programs).
59+
5360
## Compiling
5461

5562
The firmware can be deeply customized by modifying it and compiling your own
@@ -63,30 +70,54 @@ convenient.
6370

6471
### Prerequisites:
6572

66-
- AVR toolchain packages:
67-
`sudo apt install gcc-avr avr-libc binutils-avr avrdude`
68-
69-
- One or more Atmel DFPs (Device Family Pack) may be needed, to add support
70-
for recent AVR MCUs.
71-
72-
- Download the Atmel ATtiny Series Device Support pack:
73-
http://packs.download.atmel.com/
73+
- AVR toolchain packages:
74+
`sudo apt install gcc-avr avr-libc binutils-avr`
7475

75-
- Unzip the pack somewhere on your build computer
76+
- Other misc packages:
77+
`sudo apt install git wget unzip bash`
7678

77-
- Set ATTINY_DFP=/path/to/where/you/unzipped/the/pack
78-
(either in your shell, or in this repo's bin/build.sh script)
79-
80-
`export ATTINY_DFP=$HOME/src/torches/atmel/attiny-dfp`
79+
- Atmel DFPs (Device Family Packs). A small script is included to
80+
download and install these for you:
81+
`./make dfp`
8182

8283
### Building
8384

8485
Use the `make` script included in this repo. Run `./make --help` for details
8586
about how to use it. In most cases though, you should be able to just run
8687
`./make` by itself to compile all available build targets. Or give it a search
87-
term to limit builds to only a few, like `./make d4v2` to build all Emisar D4v2
88-
firmwares.
88+
term to limit builds to only a few, like `./make hank boost` to build all
89+
firmwares for Hanklights with optional boost drivers.
8990

9091
The compiled firmware goes into the `hex/` directory, ready to be used by any
9192
firmware flashing program.
9293

94+
## Customizing Settings Per User
95+
96+
The build can be [customized per user](docs/per-user-config.md) by placing
97+
overrides into the `users/myname/` directory and letting the build script know
98+
your username. That way, your favorite settings can be applied automatically
99+
without having to modify the original source files.
100+
101+
## Flashing Programs
102+
103+
### AVRdude
104+
105+
Usually avrdude installs in a single command:
106+
107+
`sudo apt install avrdude`
108+
109+
### PyMCUprog
110+
111+
If you use `pymcuprog` to flash firmware, a few extras are needed:
112+
113+
```sh
114+
sudo apt install python3 python3-pip python3-venv
115+
python3 -m venv env
116+
source env/bin/activate
117+
pip install pymcuprog
118+
```
119+
120+
You'll need to `source env/bin/activate` every time you start a fresh shell,
121+
if you want to use pymcuprog. The activation lasts until the shell is
122+
closed or until you run `deactivate`.
123+

bin/build.sh

+18-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ if [ -z "$1" ]; then
1313
exit
1414
fi
1515

16+
# repo root dir
17+
BASEDIR=$(dirname $(dirname "$0"))
18+
1619
TARGET=$1 ; shift
1720
UI=$(basename $TARGET .h)
1821
MODEL=$(dirname $TARGET)
@@ -24,24 +27,26 @@ MODEL_NUMBER=$(head -1 $MODEL/model)
2427
# figure out the MCU type and set some vars
2528
eval $( bin/detect-mcu.sh "$TARGET" )
2629

27-
# TODO: add support for AVR DD
28-
# give a more useful error message when AVR DFP is needed but not installed
29-
# (Atmel ATtiny device family pack, for attiny1616 support)
30-
# http://packs.download.atmel.com/
31-
#if [ -z "$ATTINY_DFP" ]; then export ATTINY_DFP=~/avr/attiny_dfp ; fi
32-
SERIES1=' 416 417 816 817 1616 1617 3216 3217 '
33-
if [[ $SERIES1 =~ " $ATTINY " ]]; then
34-
if [ -z "$ATTINY_DFP" ]; then
35-
echo "ATtiny$ATTINY support requires Atmel attiny device family pack."
36-
echo "More info is in /README under tiny1616 support."
37-
exit 1
38-
fi
30+
# detect and enable a relevant Atmel DFP
31+
if [[ $MCUNAME =~ "attiny" ]]; then
32+
DFPPATH=$BASEDIR/arch/dfp/attiny
33+
elif [[ $MCUNAME =~ "avr" && $MCUNAME =~ "dd" ]]; then
34+
DFPPATH=$BASEDIR/arch/dfp/avrdd
35+
else
36+
echo "Unrecognized MCU type: '$MCUNAME'"
37+
exit 1
38+
fi
39+
# ensure the DFP files exist
40+
if [ ! -d "$DFPPATH" ]; then
41+
echo "Atmel DFP files not found: '$DFPPATH'"
42+
echo "Install DFP files with './make dfp'"
43+
exit 1
3944
fi
4045

4146
export CC=avr-gcc
4247
export CPP=avr-cpp
4348
export OBJCOPY=avr-objcopy
44-
export DFPFLAGS="-B $ATTINY_DFP/gcc/dev/$MCUNAME/ -I $ATTINY_DFP/include/"
49+
export DFPFLAGS="-B $DFPPATH/gcc/dev/$MCUNAME/ -I $DFPPATH/include/"
4550
# TODO: include $user/ first so it can override other stuff
4651
INCLUDES="-I ui -I hw -I. -I.. -I../.. -I../../.."
4752
export CFLAGS=" -Wall -g -Os -mmcu=$MCUNAME -c -std=gnu99 -fgnu89-inline -fwhole-program $MCUFLAGS $INCLUDES -fshort-enums $DFPFLAGS"

bin/dfp-install.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
# Atmel DFP download/install/setup script
3+
# Copyright (C) 2023 Selene ToyKeeper
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
6+
set -e
7+
8+
V_ATTINY='2.0.368'
9+
V_AVRDD='2.2.253'
10+
F_ATTINY="Atmel.ATtiny_DFP.${V_ATTINY}.atpack"
11+
F_AVRDD="Atmel.AVR-Dx_DFP.${V_AVRDD}.atpack"
12+
13+
cd arch
14+
15+
# make the base DFP dir
16+
mkdir -p dfp
17+
cd dfp
18+
19+
# download the zipped pack files if they don't exist yet
20+
mkdir -p zip
21+
cd zip
22+
[ ! -f "${F_ATTINY}" ] && wget "http://packs.download.atmel.com/${F_ATTINY}"
23+
[ ! -f "${F_AVRDD}" ] && wget "http://packs.download.atmel.com/${F_AVRDD}"
24+
25+
# extract the packs
26+
# attiny
27+
cd ..
28+
mkdir -p attiny
29+
cd attiny
30+
unzip "../zip/${F_ATTINY}"
31+
# avrdd
32+
cd ..
33+
mkdir -p avrdd
34+
cd avrdd
35+
unzip "../zip/${F_AVRDD}"
36+

docs/per-user-config.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Per-User Configuration
2+
3+
(write me)
4+

make

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ Usage: ./make TASK
2323
(nothing) Compile all build targets
2424
flash FILE Flash firmare FILE to a hardware device
2525
clean Delete generated files
26-
todo Show tasks noted in source code files
26+
dfp Download and install Atmel DFPs
27+
docs Convert all .md files to .html
2728
models Generate the MODELS file
2829
release Zip up all .hex files to prep for publishing a release
29-
docs Convert all .md files to .html
30+
todo Show tasks noted in source code files
3031
3132
... or TASK can be the partial name of a build target.
3233
@@ -56,6 +57,10 @@ function main() {
5657
echo 'rm -vf **/*.hex **/*~ **/*.elf **/*.o **/*.cpp'
5758
rm -vf **/*.hex **/*~ **/*.elf **/*.o **/*.cpp
5859
;;
60+
dfp)
61+
shift
62+
./bin/dfp-install.sh "$@"
63+
;;
5964
docs)
6065
make-docs
6166
;;
@@ -87,5 +92,10 @@ function make-docs () {
8792
done
8893
}
8994

95+
# go to the repo root
96+
BASEDIR=$(dirname $0)
97+
cd "$BASEDIR"
98+
99+
# do whatever the user requested
90100
main "$@"
91101

0 commit comments

Comments
 (0)