You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
13 KiB
HTML
186 lines
13 KiB
HTML
<!-- HTML header for doxygen 1.8.7-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.6.3"/>
|
|
<!--BEGIN PROJECT_NAME--><title>avr-libc: avr-libc: <avr/fuse.h>: Fuse Support</title><!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME--><title>avr-libc: <avr/fuse.h>: Fuse Support</title><!--END !PROJECT_NAME-->
|
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
|
$treeview
|
|
$search
|
|
$mathjax
|
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
|
$extrastylesheet
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
|
|
<!--BEGIN TITLEAREA-->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<!--BEGIN PROJECT_LOGO-->
|
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
|
<!--END PROJECT_LOGO-->
|
|
<!--BEGIN PROJECT_NAME-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">avr-libc
|
|
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">2.0.0</span><!--END PROJECT_NUMBER-->
|
|
</div>
|
|
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
|
</td>
|
|
<!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME-->
|
|
<!--BEGIN PROJECT_BRIEF-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectbrief">$projectbrief</div>
|
|
</td>
|
|
<!--END PROJECT_BRIEF-->
|
|
<!--END !PROJECT_NAME-->
|
|
<!--BEGIN DISABLE_INDEX-->
|
|
<!--BEGIN SEARCHENGINE-->
|
|
<td>$searchbox</td>
|
|
<!--END SEARCHENGINE-->
|
|
<!--END DISABLE_INDEX-->
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table>
|
|
<tr>
|
|
<td align="left"><a href="http://www.nongnu.org/avr-libc/"><h2>AVR Libc Home Page</h2></a></td>
|
|
<td align="center" colspan=4><img src="avrs.png" alt="AVRs" align="middle" border="0"></td>
|
|
<td align="right"><a href="https://savannah.nongnu.org/projects/avr-libc/"><h2>AVR Libc Development Pages</h2></a></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" width="20%"><a href="index.html"><h2>Main Page</h2></a></td>
|
|
<td align="center" width="20%"><a href="pages.html"><h2>User Manual</h2></a></td>
|
|
<td align="center" width="20%"><a href="modules.html"><h2>Library Reference</h2></a></td>
|
|
<td align="center" width="20%"><a href="FAQ.html"><h2>FAQ</h2></a></td>
|
|
<td align="center" width="20%"><a href="group__demos.html"><h2>Example Projects</h2></a></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<!--END TITLEAREA-->
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.6.3 -->
|
|
<script type="text/javascript"><!--
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
--></script>
|
|
<div class="contents">
|
|
<h1><avr/fuse.h>: Fuse Support</h1><table border="0" cellpadding="0" cellspacing="0">
|
|
</table>
|
|
<dl class="user"><dt><b>Introduction</b></dt><dd></dd></dl>
|
|
<p>The Fuse API allows a user to specify the fuse settings for the specific AVR device they are compiling for. These fuse settings will be placed in a special section in the ELF output file, after linking.</p>
|
|
<p>Programming tools can take advantage of the fuse information embedded in the ELF file, by extracting this information and determining if the fuses need to be programmed before programming the Flash and EEPROM memories. This also allows a single ELF file to contain all the information needed to program an AVR.</p>
|
|
<p>To use the Fuse API, include the <<a class="el" href="io_8h.html">avr/io.h</a>> header file, which in turn automatically includes the individual I/O header file and the <<a class="el" href="fuse_8h.html">avr/fuse.h</a>> file. These other two files provides everything necessary to set the AVR fuses.</p>
|
|
<dl class="user"><dt><b>Fuse API</b></dt><dd></dd></dl>
|
|
<p>Each I/O header file must define the FUSE_MEMORY_SIZE macro which is defined to the number of fuse bytes that exist in the AVR device.</p>
|
|
<p>A new type, __fuse_t, is defined as a structure. The number of fields in this structure are determined by the number of fuse bytes in the FUSE_MEMORY_SIZE macro.</p>
|
|
<p>If FUSE_MEMORY_SIZE == 1, there is only a single field: byte, of type unsigned char.</p>
|
|
<p>If FUSE_MEMORY_SIZE == 2, there are two fields: low, and high, of type unsigned char.</p>
|
|
<p>If FUSE_MEMORY_SIZE == 3, there are three fields: low, high, and extended, of type unsigned char.</p>
|
|
<p>If FUSE_MEMORY_SIZE > 3, there is a single field: byte, which is an array of unsigned char with the size of the array being FUSE_MEMORY_SIZE.</p>
|
|
<p>A convenience macro, FUSEMEM, is defined as a GCC attribute for a custom-named section of ".fuse".</p>
|
|
<p>A convenience macro, FUSES, is defined that declares a variable, __fuse, of type __fuse_t with the attribute defined by FUSEMEM. This variable allows the end user to easily set the fuse data.</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd>If a device-specific I/O header file has previously defined FUSEMEM, then FUSEMEM is not redefined. If a device-specific I/O header file has previously defined FUSES, then FUSES is not redefined.</dd></dl>
|
|
<p>Each AVR device I/O header file has a set of defined macros which specify the actual fuse bits available on that device. The AVR fuses have inverted values, logical 1 for an unprogrammed (disabled) bit and logical 0 for a programmed (enabled) bit. The defined macros for each individual fuse bit represent this in their definition by a bit-wise inversion of a mask. For example, the FUSE_EESAVE fuse in the ATmega128 is defined as: </p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #define FUSE_EESAVE ~_BV(3)</span>
|
|
</pre></div> <dl class="note"><dt><b>Note:</b></dt><dd>The _BV macro creates a bit mask from a bit number. It is then inverted to represent logical values for a fuse memory byte.</dd></dl>
|
|
<p>To combine the fuse bits macros together to represent a whole fuse byte, use the bitwise AND operator, like so: </p>
|
|
<div class="fragment"><pre class="fragment"> (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN)
|
|
</pre></div><p>Each device I/O header file also defines macros that provide default values for each fuse byte that is available. LFUSE_DEFAULT is defined for a Low Fuse byte. HFUSE_DEFAULT is defined for a High Fuse byte. EFUSE_DEFAULT is defined for an Extended Fuse byte.</p>
|
|
<p>If FUSE_MEMORY_SIZE > 3, then the I/O header file defines macros that provide default values for each fuse byte like so: FUSE0_DEFAULT FUSE1_DEFAULT FUSE2_DEFAULT FUSE3_DEFAULT FUSE4_DEFAULT ....</p>
|
|
<dl class="user"><dt><b>API Usage Example</b></dt><dd></dd></dl>
|
|
<p>Putting all of this together is easy. Using C99's designated initializers:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
|
|
FUSES =
|
|
{
|
|
.low = LFUSE_DEFAULT,
|
|
.high = (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
|
|
.extended = EFUSE_DEFAULT,
|
|
};
|
|
|
|
<span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)
|
|
{
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div><p>Or, using the variable directly instead of the FUSES macro,</p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
|
|
__fuse_t __fuse <a class="code" href="group__avr__watchdog.html#gadaa6dd28b5d08df35e49b1248d7e5fb0">__attribute__</a>((section (<span class="stringliteral">".fuse"</span>))) =
|
|
{
|
|
.low = LFUSE_DEFAULT,
|
|
.high = (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
|
|
.extended = EFUSE_DEFAULT,
|
|
};
|
|
|
|
<span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)
|
|
{
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div><p>If you are compiling in C++, you cannot use the designated intializers so you must do:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
|
|
FUSES =
|
|
{
|
|
LFUSE_DEFAULT, <span class="comment">// .low</span>
|
|
(FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN), <span class="comment">// .high</span>
|
|
EFUSE_DEFAULT, <span class="comment">// .extended</span>
|
|
};
|
|
|
|
<span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)
|
|
{
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div><p>However there are a number of caveats that you need to be aware of to use this API properly.</p>
|
|
<p>Be sure to include <<a class="el" href="io_8h.html">avr/io.h</a>> to get all of the definitions for the API. The FUSES macro defines a global variable to store the fuse data. This variable is assigned to its own linker section. Assign the desired fuse values immediately in the variable initialization.</p>
|
|
<p>The .fuse section in the ELF file will get its values from the initial variable assignment ONLY. This means that you can NOT assign values to this variable in functions and the new values will not be put into the ELF .fuse section.</p>
|
|
<p>The global variable is declared in the FUSES macro has two leading underscores, which means that it is reserved for the "implementation", meaning the library, so it will not conflict with a user-named variable.</p>
|
|
<p>You must initialize ALL fields in the __fuse_t structure. This is because the fuse bits in all bytes default to a logical 1, meaning unprogrammed. Normal uninitialized data defaults to all locgial zeros. So it is vital that all fuse bytes are initialized, even with default data. If they are not, then the fuse bits may not programmed to the desired settings.</p>
|
|
<p>Be sure to have the -mmcu=<em>device</em> flag in your compile command line and your linker command line to have the correct device selected and to have the correct I/O header file included when you include <<a class="el" href="io_8h.html">avr/io.h</a>>.</p>
|
|
<p>You can print out the contents of the .fuse section in the ELF file by using this command line: </p>
|
|
<div class="fragment"><pre class="fragment"> avr-objdump -s -j .fuse <ELF file>
|
|
</pre></div><p> The section contents shows the address on the left, then the data going from lower address to a higher address, left to right. </p>
|
|
</div>
|
|
<!--- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Defines</a></div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<!-- HTML footer for doxygen 1.8.7-->
|
|
<!-- start footer part -->
|
|
<!--BEGIN GENERATE_TREEVIEW-->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
$navpath
|
|
<li class="footer">$generatedby
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/></a> 1.6.3 </li>
|
|
</ul>
|
|
</div>
|
|
<!--END GENERATE_TREEVIEW-->
|
|
<!--BEGIN !GENERATE_TREEVIEW-->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
$generatedby  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/>
|
|
</a> 1.6.3
|
|
</small></address>
|
|
<!--END !GENERATE_TREEVIEW-->
|
|
</body>
|
|
</html>
|