-
Notifications
You must be signed in to change notification settings - Fork 30
/
fuses.mu4
100 lines (87 loc) · 3.36 KB
/
fuses.mu4
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
| This file is part of muforth: https://muforth.dev/
|
| Copyright 2002-2024 David Frech. (Read the LICENSE for details.)
loading AVR fuse byte generator
| comment %%
| You can define any or all of the following values. Leaving any of them
| undefined will result in the default value from the datasheet for those
| fuse bits. ckdiv8 is an exception: I'm changing the default to *off*.
|
| For on/off booleans, fuse bits are 1 if *undefined* (false) and 0 if
| *defined* (true).
|
| For fields that define several possibilities, the default binary bit
| pattern is given.
|
| Symbol Default Comment
| ~~~~~~ ~~~~~~~ ~~~~~~~
| eesave 1 don't erase the EEPROM contents when chip is erased;
| default value means *do* erase the EEPROM
| wdton 1 watchdog always on; default means *off*
| bootrst 1 reset vector is in boot region; default is at 0000
| bootsz 00 size of boot region; 0 to 3; 0 largest, 3 smallest;
| default to *largest*
| ckdiv8 1 divide clock by 8; default to false (differs from datasheet!)
| ckout 1 generate a clock on the CLKO pin; default: don't generate
| cksel 0010 clock select; 0 to 15; default is 8M internal RC
| sut 10 start up timer (see datasheet)
| bodlevel 111 brownout detect level; default to no brownout detect
| %%
| Clock settings
| ~~~~~~~~~~~~~~
|
| For a breadboarded chip with no external crystal, resonator, or
| oscillator, use the default clock settings.
|
| For an Arduino or any other setup using an external *crystal* or *ceramic
| resonator*, you have two options. The "official" Arduino fuse settings
| specify the low-power oscillator; however, the full-swing oscillator is
| better in electrically noisy environments. Both use the longest startup
| time (sut = %11).
|
| External crystal/resonator, low-power oscillator:
| %1111 constant cksel
| %11 constant sut
|
| External crystal/resonator, full-swing oscillator:
| %0111 constant cksel
| %11 constant sut
|
| If using an external *oscillator*, use the following:
| %0000 constant cksel
| Unfortunately, the AVR devices do not specify the fuse bytes in the same
| way! So we have to know which device we are generating for.
hex
( low fuse)
.ifdef ckdiv8 0 .else 80 .then
.ifdef ckout 0 .else 40 .then or
.ifdef sut sut .else %10 .then 4 << or
.ifdef cksel cksel .else %0010 .then or
( high fuse)
0c0 ( base bits)
.ifdef wdton 0 .else 10 .then or
.ifdef eesave 0 .else 08 .then or
.def megax4 .def mega328 .or .if
.ifdef bootsz bootsz .else %00 .then 2* or
.ifdef bootrst 0 .else 1 .then or
.else ( 48/88/168)
.ifdef bodlevel bodlevel .else %111 .then or
.then
( extended fuse)
0f8 ( base bits)
.def megax4 .def mega328 .or .if
.ifdef bodlevel bodlevel .else %111 .then or
.else ( 48/88/168)
.ifdef bootsz bootsz .else %00 .then 2* or
.ifdef bootrst 0 .else 1 .then or
.then
( Combine the bytes, and store in fuses.)
lohi> lohi> dup fuses !
( Print the result.)
." Fuse bytes: "
<# # # bl hold # # bl hold # # #> type space
( Calculate lock bits and save in locks.)
0cf ( base bits)
.ifdef bootrst %10 .else %11 .then 4 << or dup locks !
( Print the result.)
." Lock byte: " <# # # #> type space